You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
OneAuth/api/oauth/revoke.go

27 lines
684 B
Go

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

// Copyright (C) 2024 veypi <i@veypi.com>
// 2025-03-04 16:08:06
// Distributed under terms of the MIT license.
package oauth
import (
"github.com/veypi/vbase/cfg"
"github.com/veypi/vbase/models"
"github.com/veypi/vigo"
)
type RevokeRequest struct {
Token string `json:"token" src:"form" desc:"要撤销的令牌"`
}
func revoke(x *vigo.X, req *RevokeRequest) error {
// 查找并撤销令牌
var token models.OAuthToken
if err := cfg.DB().First(&token, "access_token = ? OR refresh_token = ?", req.Token, req.Token).Error; err != nil {
return nil // 按照OAuth规范不存在的令牌也返回成功
}
cfg.DB().Model(&token).Update("revoked", true)
return nil
}