mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-03 12:30:19 +08:00
Improve parseBearerToken().
This commit is contained in:
@ -97,19 +97,17 @@ func setSessionExpire(ctx *context.Context, ExpireTime int64) {
|
||||
ctx.Input.CruSession.SessionRelease(ctx.ResponseWriter)
|
||||
}
|
||||
|
||||
func parseBearer(ctx *context.Context) (*object.Claims, bool) {
|
||||
bearer := ctx.Request.Header.Get("Authorization")
|
||||
bearerList := strings.Split(bearer, " ")
|
||||
if len(bearerList) != 2 {
|
||||
return nil, false
|
||||
func parseBearerToken(ctx *context.Context) string {
|
||||
header := ctx.Request.Header.Get("Authorization")
|
||||
tokens := strings.Split(header, " ")
|
||||
if len(tokens) != 2 {
|
||||
return ""
|
||||
}
|
||||
prefix := bearerList[0]
|
||||
|
||||
prefix := tokens[0]
|
||||
if prefix != "Bearer" {
|
||||
return nil, false
|
||||
return ""
|
||||
}
|
||||
claims, err := object.ParseJwtToken(bearerList[1])
|
||||
if err != nil {
|
||||
return nil, false
|
||||
}
|
||||
return claims, true
|
||||
|
||||
return tokens[1]
|
||||
}
|
||||
|
Reference in New Issue
Block a user