Fix Java/Grails issued token parsing

- Tested locally until successfull login
- Initialize empty projects array
This commit is contained in:
Christoph Kluge 2023-08-14 13:52:26 +02:00
parent 9e3ba41746
commit e550e57ac0

View File

@ -79,12 +79,26 @@ func (ja *JWTSessionAuthenticator) Login(
exp, _ := claims["exp"].(float64) exp, _ := claims["exp"].(float64)
var name string var name string
if val, ok := claims["name"]; ok { // Java/Grails Issued Token
if wrap, ok := claims["name"].(map[string]interface{}); ok {
if vals, ok := wrap["values"].([]interface{}); ok {
name = fmt.Sprintf("%v %v", vals[0], vals[1])
}
} else if val, ok := claims["name"]; ok {
name, _ = val.(string) name, _ = val.(string)
} }
var roles []string var roles []string
if rawroles, ok := claims["roles"]; ok { // Java/Grails Issued Token
if rawroles, ok := claims["roles"].([]interface{}); ok {
for _, rr := range rawroles {
if r, ok := rr.(string); ok {
if isValidRole(r) {
roles = append(roles, r)
}
}
}
} else if rawroles, ok := claims["roles"]; ok {
for _, r := range rawroles.([]string) { for _, r := range rawroles.([]string) {
if isValidRole(r) { if isValidRole(r) {
roles = append(roles, r) roles = append(roles, r)
@ -92,11 +106,26 @@ func (ja *JWTSessionAuthenticator) Login(
} }
} }
projects := make([]string, 0)
// Java/Grails Issued Token
// if rawprojs, ok := claims["projects"].([]interface{}); ok {
// for _, pp := range rawprojs {
// if p, ok := pp.(string); ok {
// projects = append(projects, p)
// }
// }
// } else if rawprojs, ok := claims["projects"]; ok {
// for _, p := range rawprojs.([]string) {
// projects = append(projects, p)
// }
// }
if user == nil { if user == nil {
user = &User{ user = &User{
Username: sub, Username: sub,
Name: name, Name: name,
Roles: roles, Roles: roles,
Projects: projects,
AuthType: AuthSession, AuthType: AuthSession,
AuthSource: AuthViaToken, AuthSource: AuthViaToken,
} }