完善认证逻辑,添加用户信息 introspect 接口,更新 .gitignore 忽略 scripts 目录
This commit is contained in:
@@ -268,7 +268,7 @@ type RevokeReq struct {
|
||||
}
|
||||
|
||||
func Revoke(c *fiber.Ctx) error {
|
||||
_, err := auth.Protect(c, []s.PayloadType{s.PayloadUser}, []string{})
|
||||
_, err := auth.Protect(c, []s.PayloadType{s.PayloadClientConfidential}, []string{})
|
||||
if err != nil {
|
||||
// 用户未登录
|
||||
return nil
|
||||
@@ -290,3 +290,30 @@ func Revoke(c *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
// endregion
|
||||
|
||||
// region /profile
|
||||
|
||||
type IntrospectResp struct {
|
||||
m.User
|
||||
}
|
||||
|
||||
func Introspect(c *fiber.Ctx) error {
|
||||
// 验证权限
|
||||
authCtx, err := auth.Protect(c, []s.PayloadType{s.PayloadUser}, []string{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 获取用户信息
|
||||
profile, err := q.User.
|
||||
Where(q.User.ID.Eq(authCtx.Payload.Id)).
|
||||
Omit(q.User.Password, q.User.DeletedAt).
|
||||
Take()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return c.JSON(IntrospectResp{*profile})
|
||||
}
|
||||
|
||||
// endregion
|
||||
|
||||
Reference in New Issue
Block a user