mirror of
https://github.com/casdoor/casdoor.git
synced 2025-05-23 02:35:49 +08:00
Show error in AccessToken.
This commit is contained in:
parent
2e7ef69f07
commit
58c7a60220
@ -195,7 +195,7 @@ func GetOAuthToken(grantType string, clientId string, clientSecret string, code
|
||||
application := getApplicationByClientId(clientId)
|
||||
if application == nil {
|
||||
return &TokenWrapper{
|
||||
AccessToken: "Invalid client_id",
|
||||
AccessToken: "error: invalid client_id",
|
||||
TokenType: "",
|
||||
ExpiresIn: 0,
|
||||
Scope: "",
|
||||
@ -204,7 +204,16 @@ func GetOAuthToken(grantType string, clientId string, clientSecret string, code
|
||||
|
||||
if grantType != "authorization_code" {
|
||||
return &TokenWrapper{
|
||||
AccessToken: "grant_type should be \"authorization_code\"",
|
||||
AccessToken: "error: grant_type should be \"authorization_code\"",
|
||||
TokenType: "",
|
||||
ExpiresIn: 0,
|
||||
Scope: "",
|
||||
}
|
||||
}
|
||||
|
||||
if code == "" {
|
||||
return &TokenWrapper{
|
||||
AccessToken: "error: code should not be empty",
|
||||
TokenType: "",
|
||||
ExpiresIn: 0,
|
||||
Scope: "",
|
||||
@ -214,7 +223,7 @@ func GetOAuthToken(grantType string, clientId string, clientSecret string, code
|
||||
token := getTokenByCode(code)
|
||||
if token == nil {
|
||||
return &TokenWrapper{
|
||||
AccessToken: "Invalid code",
|
||||
AccessToken: "error: invalid code",
|
||||
TokenType: "",
|
||||
ExpiresIn: 0,
|
||||
Scope: "",
|
||||
@ -223,7 +232,7 @@ func GetOAuthToken(grantType string, clientId string, clientSecret string, code
|
||||
|
||||
if application.Name != token.Application {
|
||||
return &TokenWrapper{
|
||||
AccessToken: "The token is for wrong application (client_id)",
|
||||
AccessToken: "error: the token is for wrong application (client_id)",
|
||||
TokenType: "",
|
||||
ExpiresIn: 0,
|
||||
Scope: "",
|
||||
@ -232,7 +241,7 @@ func GetOAuthToken(grantType string, clientId string, clientSecret string, code
|
||||
|
||||
if application.ClientSecret != clientSecret {
|
||||
return &TokenWrapper{
|
||||
AccessToken: "Invalid client_secret",
|
||||
AccessToken: "error: invalid client_secret",
|
||||
TokenType: "",
|
||||
ExpiresIn: 0,
|
||||
Scope: "",
|
||||
|
@ -32,6 +32,8 @@ type Claims struct {
|
||||
Phone string `json:"phone"`
|
||||
Affiliation string `json:"affiliation"`
|
||||
Tag string `json:"tag"`
|
||||
Language string `json:"language"`
|
||||
Score int `json:"score"`
|
||||
IsAdmin bool `json:"isAdmin"`
|
||||
jwt.StandardClaims
|
||||
}
|
||||
@ -50,6 +52,8 @@ func generateJwtToken(application *Application, user *User) (string, error) {
|
||||
Phone: user.Phone,
|
||||
Affiliation: user.Affiliation,
|
||||
Tag: user.Tag,
|
||||
Language: user.Language,
|
||||
Score: user.Score,
|
||||
IsAdmin: user.IsAdmin,
|
||||
StandardClaims: jwt.StandardClaims{
|
||||
Audience: application.ClientId,
|
||||
|
Loading…
x
Reference in New Issue
Block a user