Show error in AccessToken.

This commit is contained in:
Yang Luo
2021-06-01 21:14:41 +08:00
parent 2e7ef69f07
commit 58c7a60220
2 changed files with 18 additions and 5 deletions

View File

@@ -195,7 +195,7 @@ func GetOAuthToken(grantType string, clientId string, clientSecret string, code
application := getApplicationByClientId(clientId) application := getApplicationByClientId(clientId)
if application == nil { if application == nil {
return &TokenWrapper{ return &TokenWrapper{
AccessToken: "Invalid client_id", AccessToken: "error: invalid client_id",
TokenType: "", TokenType: "",
ExpiresIn: 0, ExpiresIn: 0,
Scope: "", Scope: "",
@@ -204,7 +204,16 @@ func GetOAuthToken(grantType string, clientId string, clientSecret string, code
if grantType != "authorization_code" { if grantType != "authorization_code" {
return &TokenWrapper{ 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: "", TokenType: "",
ExpiresIn: 0, ExpiresIn: 0,
Scope: "", Scope: "",
@@ -214,7 +223,7 @@ func GetOAuthToken(grantType string, clientId string, clientSecret string, code
token := getTokenByCode(code) token := getTokenByCode(code)
if token == nil { if token == nil {
return &TokenWrapper{ return &TokenWrapper{
AccessToken: "Invalid code", AccessToken: "error: invalid code",
TokenType: "", TokenType: "",
ExpiresIn: 0, ExpiresIn: 0,
Scope: "", Scope: "",
@@ -223,7 +232,7 @@ func GetOAuthToken(grantType string, clientId string, clientSecret string, code
if application.Name != token.Application { if application.Name != token.Application {
return &TokenWrapper{ return &TokenWrapper{
AccessToken: "The token is for wrong application (client_id)", AccessToken: "error: the token is for wrong application (client_id)",
TokenType: "", TokenType: "",
ExpiresIn: 0, ExpiresIn: 0,
Scope: "", Scope: "",
@@ -232,7 +241,7 @@ func GetOAuthToken(grantType string, clientId string, clientSecret string, code
if application.ClientSecret != clientSecret { if application.ClientSecret != clientSecret {
return &TokenWrapper{ return &TokenWrapper{
AccessToken: "Invalid client_secret", AccessToken: "error: invalid client_secret",
TokenType: "", TokenType: "",
ExpiresIn: 0, ExpiresIn: 0,
Scope: "", Scope: "",

View File

@@ -32,6 +32,8 @@ type Claims struct {
Phone string `json:"phone"` Phone string `json:"phone"`
Affiliation string `json:"affiliation"` Affiliation string `json:"affiliation"`
Tag string `json:"tag"` Tag string `json:"tag"`
Language string `json:"language"`
Score int `json:"score"`
IsAdmin bool `json:"isAdmin"` IsAdmin bool `json:"isAdmin"`
jwt.StandardClaims jwt.StandardClaims
} }
@@ -50,6 +52,8 @@ func generateJwtToken(application *Application, user *User) (string, error) {
Phone: user.Phone, Phone: user.Phone,
Affiliation: user.Affiliation, Affiliation: user.Affiliation,
Tag: user.Tag, Tag: user.Tag,
Language: user.Language,
Score: user.Score,
IsAdmin: user.IsAdmin, IsAdmin: user.IsAdmin,
StandardClaims: jwt.StandardClaims{ StandardClaims: jwt.StandardClaims{
Audience: application.ClientId, Audience: application.ClientId,