mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2024-12-26 05:19:05 +01:00
fix: Move name extract from token in else branch
This commit is contained in:
parent
4b06fa788d
commit
bb1c8cc25d
@ -153,19 +153,6 @@ func (ja *JWTCookieSessionAuthenticator) Login(
|
|||||||
claims := token.Claims.(jwt.MapClaims)
|
claims := token.Claims.(jwt.MapClaims)
|
||||||
sub, _ := claims["sub"].(string)
|
sub, _ := claims["sub"].(string)
|
||||||
|
|
||||||
var name string
|
|
||||||
if wrap, ok := claims["name"].(map[string]interface{}); ok {
|
|
||||||
if vals, ok := wrap["values"].([]interface{}); ok {
|
|
||||||
if len(vals) != 0 {
|
|
||||||
name = fmt.Sprintf("%v", vals[0])
|
|
||||||
|
|
||||||
for i := 1; i < len(vals); i++ {
|
|
||||||
name += fmt.Sprintf(" %v", vals[i])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var roles []string
|
var roles []string
|
||||||
projects := make([]string, 0)
|
projects := make([]string, 0)
|
||||||
|
|
||||||
@ -182,6 +169,19 @@ func (ja *JWTCookieSessionAuthenticator) Login(
|
|||||||
return nil, errors.New("unknown user")
|
return nil, errors.New("unknown user")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
var name string
|
||||||
|
if wrap, ok := claims["name"].(map[string]interface{}); ok {
|
||||||
|
if vals, ok := wrap["values"].([]interface{}); ok {
|
||||||
|
if len(vals) != 0 {
|
||||||
|
name = fmt.Sprintf("%v", vals[0])
|
||||||
|
|
||||||
|
for i := 1; i < len(vals); i++ {
|
||||||
|
name += fmt.Sprintf(" %v", vals[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Extract roles from JWT (if present)
|
// Extract roles from JWT (if present)
|
||||||
if rawroles, ok := claims["roles"].([]interface{}); ok {
|
if rawroles, ok := claims["roles"].([]interface{}); ok {
|
||||||
for _, rr := range rawroles {
|
for _, rr := range rawroles {
|
||||||
|
@ -79,19 +79,6 @@ func (ja *JWTSessionAuthenticator) Login(
|
|||||||
claims := token.Claims.(jwt.MapClaims)
|
claims := token.Claims.(jwt.MapClaims)
|
||||||
sub, _ := claims["sub"].(string)
|
sub, _ := claims["sub"].(string)
|
||||||
|
|
||||||
var name string
|
|
||||||
if wrap, ok := claims["name"].(map[string]interface{}); ok {
|
|
||||||
if vals, ok := wrap["values"].([]interface{}); ok {
|
|
||||||
if len(vals) != 0 {
|
|
||||||
name = fmt.Sprintf("%v", vals[0])
|
|
||||||
|
|
||||||
for i := 1; i < len(vals); i++ {
|
|
||||||
name += fmt.Sprintf(" %v", vals[i])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var roles []string
|
var roles []string
|
||||||
projects := make([]string, 0)
|
projects := make([]string, 0)
|
||||||
|
|
||||||
@ -108,6 +95,19 @@ func (ja *JWTSessionAuthenticator) Login(
|
|||||||
return nil, errors.New("unknown user")
|
return nil, errors.New("unknown user")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
var name string
|
||||||
|
if wrap, ok := claims["name"].(map[string]interface{}); ok {
|
||||||
|
if vals, ok := wrap["values"].([]interface{}); ok {
|
||||||
|
if len(vals) != 0 {
|
||||||
|
name = fmt.Sprintf("%v", vals[0])
|
||||||
|
|
||||||
|
for i := 1; i < len(vals); i++ {
|
||||||
|
name += fmt.Sprintf(" %v", vals[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Extract roles from JWT (if present)
|
// Extract roles from JWT (if present)
|
||||||
if rawroles, ok := claims["roles"].([]interface{}); ok {
|
if rawroles, ok := claims["roles"].([]interface{}); ok {
|
||||||
for _, rr := range rawroles {
|
for _, rr := range rawroles {
|
||||||
|
Loading…
Reference in New Issue
Block a user