Add /api/oauth/token API.

This commit is contained in:
Yang Luo
2021-03-14 00:08:59 +08:00
parent 85523fa9d4
commit 202a94a8e5
5 changed files with 45 additions and 6 deletions

View File

@ -93,3 +93,29 @@ func DeleteToken(token *Token) bool {
return affected != 0
}
func GetOAuthToken(applicationId string, grantType string, clientId string, clientSecret string, scope string) *Token {
application := GetApplication(applicationId)
if grantType != "client_credentials" {
return nil
}
if application.ClientId != clientId || application.ClientSecret != clientSecret {
return nil
}
token := &Token{
Owner: application.Owner,
Name: util.GenerateId(),
CreatedTime: util.GetCurrentTime(),
Application: application.Name,
AccessToken: "",
ExpiresIn: 7200,
Scope: scope,
TokenType: "Bearer",
}
AddToken(token)
return token
}