更新依赖项,添加单元测试,优化用户信息和令牌管理功能,增强中间件以支持 JWT 验证,新增访问令牌模型并更新数据库迁移。
This commit is contained in:
@@ -174,7 +174,7 @@ func (s *OAuthService) ExchangeToken(req *TokenRequest) (*TokenResponse, error)
|
||||
}
|
||||
|
||||
// 生成访问令牌
|
||||
accessToken, err := s.generateAccessToken(user, client, authCode.Scope)
|
||||
accessToken, err := s.GenerateAccessToken(user, client, authCode.Scope)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -197,17 +197,18 @@ func (s *OAuthService) ExchangeToken(req *TokenRequest) (*TokenResponse, error)
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *OAuthService) generateAccessToken(user *models.User, client *models.Client, scope string) (string, error) {
|
||||
func (s *OAuthService) GenerateAccessToken(user *models.User, client *models.Client, scope string) (string, error) {
|
||||
now := time.Now()
|
||||
claims := jwt.MapClaims{
|
||||
"sub": user.ID,
|
||||
"sub": fmt.Sprintf("%d", user.ID),
|
||||
"iss": client.ClientID,
|
||||
"aud": client.ClientID,
|
||||
"exp": now.Add(s.tokenTTL).Unix(),
|
||||
"iat": now.Unix(),
|
||||
"iss": client.ClientID,
|
||||
"scope": scope,
|
||||
}
|
||||
|
||||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
|
||||
token := jwt.NewWithClaims(jwt.SigningMethodRS256, claims)
|
||||
return token.SignedString(s.keyManager.GetPrivateKey())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user