89 lines
3.6 KiB
Go
89 lines
3.6 KiB
Go
package v1
|
||
|
||
import (
|
||
"github.com/gogf/gf/v2/util/gmeta"
|
||
)
|
||
|
||
// ============================== 认证授权模块 ==============================
|
||
|
||
// LoginReq 登录请求
|
||
// 参数支持 query/body 混合提交
|
||
type LoginReq struct {
|
||
gmeta.Meta `method:"post" path:"/api/login" summary:"登录" public:"true"`
|
||
Username string `json:"username" v:"required#请输入用户名" dc:"用户名"` // 用户名
|
||
Password string `json:"password" v:"required#请输入密码" dc:"密码"` // 密码
|
||
Code string `json:"code" dc:"图形验证码"` // 图形验证码
|
||
Key string `json:"key" dc:"验证码标识(captcha 接口返回的 key)"` // 验证码标识
|
||
TenantCode string `json:"tenantCode" dc:"租户编码,留空按用户名全局定位"` // 租户编码
|
||
}
|
||
|
||
// LoginRes 登录结果
|
||
// 客户端从 data.access_token 中读取并存储令牌
|
||
type LoginRes struct {
|
||
AccessToken string `json:"access_token"` // 访问令牌
|
||
RefreshToken string `json:"refresh_token"` // 刷新令牌
|
||
ExpiresIn int64 `json:"expires_in"` // access 有效期(秒)
|
||
TokenType string `json:"token_type"` // 令牌类型,固定为 Bearer
|
||
}
|
||
|
||
// LogoutReq 登出请求
|
||
// 拉黑当前 access token,需携带 access token 走 JWT 校验
|
||
type LogoutReq struct {
|
||
gmeta.Meta `method:"get" path:"/api/logout" summary:"登出"`
|
||
}
|
||
|
||
// LogoutRes 登出结果
|
||
type LogoutRes struct{}
|
||
|
||
// CaptchaReq 图形验证码请求
|
||
type CaptchaReq struct {
|
||
gmeta.Meta `method:"get" path:"/api/captcha" summary:"获取图形验证码" public:"true"`
|
||
}
|
||
|
||
// CaptchaRes 图形验证码结果
|
||
type CaptchaRes struct {
|
||
Key string `json:"key" dc:"验证码标识"` // 验证码标识
|
||
Captcha string `json:"captcha" dc:"SVG data URL 图片"` // SVG data URL 图片
|
||
}
|
||
|
||
// RefreshReq 刷新令牌请求
|
||
// 同时兼容 refresh_token 与 password 两种授权模式
|
||
type RefreshReq struct {
|
||
gmeta.Meta `method:"post" path:"/api/oauth2/token" summary:"刷新令牌/密码模式兑换" public:"true"`
|
||
GrantType string `json:"grant_type" dc:"refresh_token | password"` // 授权类型
|
||
RefreshToken string `json:"refresh_token" dc:"刷新令牌(grant_type=refresh_token 时必填)"` // 刷新令牌
|
||
Username string `json:"username" dc:"用户名(grant_type=password 时必填)"` // 用户名
|
||
Password string `json:"password" dc:"密码(grant_type=password 时必填)"` // 密码
|
||
Code string `json:"code" dc:"验证码"` // 验证码
|
||
Key string `json:"key" dc:"验证码标识"` // 验证码标识
|
||
}
|
||
|
||
// RefreshRes 刷新令牌结果
|
||
// 结构与登录结果保持一致
|
||
type RefreshRes struct {
|
||
AccessToken string `json:"access_token"` // 访问令牌
|
||
RefreshToken string `json:"refresh_token"` // 刷新令牌
|
||
ExpiresIn int64 `json:"expires_in"` // access 有效期(秒)
|
||
TokenType string `json:"token_type"` // 令牌类型
|
||
}
|
||
|
||
// CheckTokenReq 校验令牌请求
|
||
type CheckTokenReq struct {
|
||
gmeta.Meta `method:"get" path:"/api/oauth2/check/token" summary:"校验令牌"`
|
||
}
|
||
|
||
// CheckTokenRes 校验令牌结果
|
||
type CheckTokenRes struct {
|
||
Valid bool `json:"valid"` // 是否有效
|
||
UserId int64 `json:"userId"` // 用户ID
|
||
}
|
||
|
||
// RemoveTokenReq 指定令牌拉黑请求
|
||
type RemoveTokenReq struct {
|
||
gmeta.Meta `method:"delete" path:"/api/oauth2/remove/:token" summary:"撤销指定令牌"`
|
||
Token string `json:"token" v:"required#缺少token" dc:"待撤销的令牌"` // 待撤销的令牌
|
||
}
|
||
|
||
// RemoveTokenRes 撤销令牌结果
|
||
type RemoveTokenRes struct{}
|