更新依赖项,优化 OAuth2 服务,添加 PKCE 支持,增强 OIDC 处理器,新增客户端注册和令牌管理端点,改进数据库模型以支持新功能。
This commit is contained in:
46
handlers/token.go
Normal file
46
handlers/token.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"oidc-oauth2-server/services"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type TokenHandler struct {
|
||||
tokenService *services.TokenService
|
||||
}
|
||||
|
||||
func NewTokenHandler(tokenService *services.TokenService) *TokenHandler {
|
||||
return &TokenHandler{
|
||||
tokenService: tokenService,
|
||||
}
|
||||
}
|
||||
|
||||
// Revoke 处理令牌撤销请求
|
||||
func (h *TokenHandler) Revoke(c *gin.Context) {
|
||||
token := c.PostForm("token")
|
||||
tokenTypeHint := c.PostForm("token_type_hint")
|
||||
|
||||
if err := h.tokenService.RevokeToken(token, tokenTypeHint); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid_request"})
|
||||
return
|
||||
}
|
||||
|
||||
c.Status(http.StatusOK)
|
||||
}
|
||||
|
||||
// Introspect 处理令牌自省请求
|
||||
func (h *TokenHandler) Introspect(c *gin.Context) {
|
||||
token := c.PostForm("token")
|
||||
tokenTypeHint := c.PostForm("token_type_hint")
|
||||
|
||||
result, err := h.tokenService.IntrospectToken(token, tokenTypeHint)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid_request"})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, result)
|
||||
}
|
||||
Reference in New Issue
Block a user