mirror of
https://github.com/casdoor/casdoor.git
synced 2025-05-23 18:54:03 +08:00
feat: make token_type_hint optional (#3397)
This commit is contained in:
parent
2ceb54f058
commit
6175fd6764
@ -322,7 +322,9 @@ func (c *ApiController) IntrospectToken() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tokenTypeHint := c.Input().Get("token_type_hint")
|
tokenTypeHint := c.Input().Get("token_type_hint")
|
||||||
token, err := object.GetTokenByTokenValue(tokenValue, tokenTypeHint)
|
var token *object.Token
|
||||||
|
if tokenTypeHint != "" {
|
||||||
|
token, err = object.GetTokenByTokenValue(tokenValue, tokenTypeHint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.ResponseTokenError(err.Error())
|
c.ResponseTokenError(err.Error())
|
||||||
return
|
return
|
||||||
@ -332,6 +334,9 @@ func (c *ApiController) IntrospectToken() {
|
|||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var introspectionResponse object.IntrospectionResponse
|
||||||
|
|
||||||
if application.TokenFormat == "JWT-Standard" {
|
if application.TokenFormat == "JWT-Standard" {
|
||||||
jwtToken, err := object.ParseStandardJwtTokenByApplication(tokenValue, application)
|
jwtToken, err := object.ParseStandardJwtTokenByApplication(tokenValue, application)
|
||||||
@ -344,12 +349,12 @@ func (c *ApiController) IntrospectToken() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = &object.IntrospectionResponse{
|
introspectionResponse = object.IntrospectionResponse{
|
||||||
Active: true,
|
Active: true,
|
||||||
Scope: jwtToken.Scope,
|
Scope: jwtToken.Scope,
|
||||||
ClientId: clientId,
|
ClientId: clientId,
|
||||||
Username: token.User,
|
Username: jwtToken.Name,
|
||||||
TokenType: token.TokenType,
|
TokenType: jwtToken.TokenType,
|
||||||
Exp: jwtToken.ExpiresAt.Unix(),
|
Exp: jwtToken.ExpiresAt.Unix(),
|
||||||
Iat: jwtToken.IssuedAt.Unix(),
|
Iat: jwtToken.IssuedAt.Unix(),
|
||||||
Nbf: jwtToken.NotBefore.Unix(),
|
Nbf: jwtToken.NotBefore.Unix(),
|
||||||
@ -358,10 +363,7 @@ func (c *ApiController) IntrospectToken() {
|
|||||||
Iss: jwtToken.Issuer,
|
Iss: jwtToken.Issuer,
|
||||||
Jti: jwtToken.ID,
|
Jti: jwtToken.ID,
|
||||||
}
|
}
|
||||||
c.ServeJSON()
|
} else {
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
jwtToken, err := object.ParseJwtTokenByApplication(tokenValue, application)
|
jwtToken, err := object.ParseJwtTokenByApplication(tokenValue, application)
|
||||||
if err != nil || jwtToken.Valid() != nil {
|
if err != nil || jwtToken.Valid() != nil {
|
||||||
// and token revoked case. but we not implement
|
// and token revoked case. but we not implement
|
||||||
@ -372,12 +374,12 @@ func (c *ApiController) IntrospectToken() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = &object.IntrospectionResponse{
|
introspectionResponse = object.IntrospectionResponse{
|
||||||
Active: true,
|
Active: true,
|
||||||
Scope: jwtToken.Scope,
|
Scope: jwtToken.Scope,
|
||||||
ClientId: clientId,
|
ClientId: clientId,
|
||||||
Username: token.User,
|
Username: jwtToken.Name,
|
||||||
TokenType: token.TokenType,
|
TokenType: jwtToken.TokenType,
|
||||||
Exp: jwtToken.ExpiresAt.Unix(),
|
Exp: jwtToken.ExpiresAt.Unix(),
|
||||||
Iat: jwtToken.IssuedAt.Unix(),
|
Iat: jwtToken.IssuedAt.Unix(),
|
||||||
Nbf: jwtToken.NotBefore.Unix(),
|
Nbf: jwtToken.NotBefore.Unix(),
|
||||||
@ -386,5 +388,21 @@ func (c *ApiController) IntrospectToken() {
|
|||||||
Iss: jwtToken.Issuer,
|
Iss: jwtToken.Issuer,
|
||||||
Jti: jwtToken.ID,
|
Jti: jwtToken.ID,
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if tokenTypeHint == "" {
|
||||||
|
token, err = object.GetTokenByTokenValue(tokenValue, introspectionResponse.TokenType)
|
||||||
|
if err != nil {
|
||||||
|
c.ResponseTokenError(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if token == nil {
|
||||||
|
c.Data["json"] = &object.IntrospectionResponse{Active: false}
|
||||||
|
c.ServeJSON()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
c.Data["json"] = introspectionResponse
|
||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
@ -124,6 +124,7 @@ func GetTokenByRefreshToken(refreshToken string) (*Token, error) {
|
|||||||
func GetTokenByTokenValue(tokenValue, tokenTypeHint string) (*Token, error) {
|
func GetTokenByTokenValue(tokenValue, tokenTypeHint string) (*Token, error) {
|
||||||
switch tokenTypeHint {
|
switch tokenTypeHint {
|
||||||
case "access_token":
|
case "access_token":
|
||||||
|
case "access-token":
|
||||||
token, err := GetTokenByAccessToken(tokenValue)
|
token, err := GetTokenByAccessToken(tokenValue)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -132,6 +133,7 @@ func GetTokenByTokenValue(tokenValue, tokenTypeHint string) (*Token, error) {
|
|||||||
return token, nil
|
return token, nil
|
||||||
}
|
}
|
||||||
case "refresh_token":
|
case "refresh_token":
|
||||||
|
case "refresh-token":
|
||||||
token, err := GetTokenByRefreshToken(tokenValue)
|
token, err := GetTokenByRefreshToken(tokenValue)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user