mirror of
https://github.com/casdoor/casdoor.git
synced 2025-05-24 08:20:31 +08:00
Improve error handling in IntrospectToken()
This commit is contained in:
parent
4e145f71b5
commit
79f81f1356
@ -271,6 +271,14 @@ func (c *ApiController) RefreshToken() {
|
|||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *ApiController) ResponseTokenError(errorMsg string) {
|
||||||
|
c.Data["json"] = &object.TokenError{
|
||||||
|
Error: errorMsg,
|
||||||
|
}
|
||||||
|
c.SetTokenErrorHttpStatus()
|
||||||
|
c.ServeJSON()
|
||||||
|
}
|
||||||
|
|
||||||
// IntrospectToken
|
// IntrospectToken
|
||||||
// @Title IntrospectToken
|
// @Title IntrospectToken
|
||||||
// @Tag Login API
|
// @Tag Login API
|
||||||
@ -293,40 +301,33 @@ func (c *ApiController) IntrospectToken() {
|
|||||||
clientId = c.Input().Get("client_id")
|
clientId = c.Input().Get("client_id")
|
||||||
clientSecret = c.Input().Get("client_secret")
|
clientSecret = c.Input().Get("client_secret")
|
||||||
if clientId == "" || clientSecret == "" {
|
if clientId == "" || clientSecret == "" {
|
||||||
c.ResponseError(c.T("token:Empty clientId or clientSecret"))
|
c.ResponseTokenError(object.InvalidRequest)
|
||||||
c.Data["json"] = &object.TokenError{
|
|
||||||
Error: object.InvalidRequest,
|
|
||||||
}
|
|
||||||
c.SetTokenErrorHttpStatus()
|
|
||||||
c.ServeJSON()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
application, err := object.GetApplicationByClientId(clientId)
|
application, err := object.GetApplicationByClientId(clientId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.ResponseError(err.Error())
|
c.ResponseTokenError(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if application == nil || application.ClientSecret != clientSecret {
|
if application == nil || application.ClientSecret != clientSecret {
|
||||||
c.ResponseError(c.T("token:Invalid application or wrong clientSecret"))
|
c.ResponseTokenError(c.T("token:Invalid application or wrong clientSecret"))
|
||||||
c.Data["json"] = &object.TokenError{
|
|
||||||
Error: object.InvalidClient,
|
|
||||||
}
|
|
||||||
c.SetTokenErrorHttpStatus()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
token, err := object.GetTokenByTokenAndApplication(tokenValue, application.Name)
|
|
||||||
if err != nil {
|
|
||||||
c.ResponseError(err.Error())
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
token, err := object.GetTokenByTokenAndApplication(tokenValue, application.Name)
|
||||||
|
if err != nil {
|
||||||
|
c.ResponseTokenError(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
if token == nil {
|
if token == nil {
|
||||||
c.Data["json"] = &object.IntrospectionResponse{Active: false}
|
c.Data["json"] = &object.IntrospectionResponse{Active: false}
|
||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
return
|
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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user