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) }