Don't check for attributes if no attributes set.

If no attributes are set, the attributes property is nil. This
causes a panic if keycloak has no custom attributes.
This patch checks for nil before accessing the attributes.
This commit is contained in:
Daniël Franke
2023-04-12 12:11:22 +02:00
committed by jkoberg
parent c9d0e876f7
commit 3ec5c0f6ed

View File

@@ -164,17 +164,20 @@ func (c *ConcreteClient) getToken(ctx context.Context) (*gocloak.JWT, error) {
}
func (c *ConcreteClient) keycloakUserToLibregraph(u *gocloak.User) *libregraph.User {
attrs := *u.Attributes
ldapID := ""
ldapIDs, ok := attrs[_idAttr]
if ok {
ldapID = ldapIDs[0]
}
var ldapID string
var userType *string
userTypes, ok := attrs[_userTypeAttr]
if ok {
userType = &userTypes[0]
if u.Attributes != nil {
attrs := *u.Attributes
ldapIDs, ok := attrs[_idAttr]
if ok {
ldapID = ldapIDs[0]
}
userTypes, ok := attrs[_userTypeAttr]
if ok {
userType = &userTypes[0]
}
}
return &libregraph.User{