From 3ec5c0f6ed9b7ba6c33a7e5ee8b5e1ff8cfbdc3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20Franke?= Date: Wed, 12 Apr 2023 12:11:22 +0200 Subject: [PATCH] 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. --- ocis-pkg/keycloak/client.go | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/ocis-pkg/keycloak/client.go b/ocis-pkg/keycloak/client.go index 3b20eafe06..49cd3e9819 100644 --- a/ocis-pkg/keycloak/client.go +++ b/ocis-pkg/keycloak/client.go @@ -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{