Skip to content

Commit

Permalink
chore: document graphFields and add cast checking
Browse files Browse the repository at this point in the history
Added comment and a link to MS documentation.
Added cast checking to user["id"].(string)
  • Loading branch information
moose115 committed Dec 8, 2023
1 parent b605170 commit 874d9c5
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions selfservice/strategy/oidc/provider_microsoft.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ func (m *ProviderMicrosoft) updateSubject(ctx context.Context, claims *Claims, e
}

client := m.reg.HTTPClient(ctx, httpx.ResilientClientWithClient(o.Client(ctx, exchange)))
graphFields := "accountEnabled,assignedLicenses,assignedPlans,city,country,creationType,deletionTimestamp,department,dirSyncEnabled,displayName,employeeId,facsimileTelephoneNumber,givenName,immutableId,jobTitle,lastDirSyncTime,mail,mailNickname,mobile,objectId,objectType,onPremisesSecurityIdentifier,otherMails,passwordPolicies,passwordProfile,physicalDeliveryOfficeName,postalCode,preferredLanguage,provisionedPlans,provisioningErrors,proxyAddresses,refreshTokensValidFromDateTime,showInAddressList,signInNames,sipProxyAddress,state,streetAddress,surname,telephoneNumber,thumbnailPhoto,usageLocation,userIdentities,userPrincipalName,userType"

// params to request all user fields from the graph api (User.Read scope) - https://learn.microsoft.com/en-us/previous-versions/azure/ad/graph/api/entity-and-complex-type-reference#user-entity
graphFields := "id,accountEnabled,assignedLicenses,assignedPlans,city,country,creationType,deletionTimestamp,department,dirSyncEnabled,displayName,employeeId,facsimileTelephoneNumber,givenName,immutableId,jobTitle,lastDirSyncTime,mail,mailNickname,mobile,objectId,objectType,onPremisesSecurityIdentifier,otherMails,passwordPolicies,passwordProfile,physicalDeliveryOfficeName,postalCode,preferredLanguage,provisionedPlans,provisioningErrors,proxyAddresses,refreshTokensValidFromDateTime,showInAddressList,signInNames,sipProxyAddress,state,streetAddress,surname,telephoneNumber,thumbnailPhoto,usageLocation,userIdentities,userPrincipalName,userType"
req, err := retryablehttp.NewRequest("GET", "https://graph.microsoft.com/v1.0/me?$select="+graphFields, nil)
if err != nil {
return nil, errors.WithStack(herodot.ErrInternalServerError.WithReasonf("%s", err))
Expand All @@ -112,7 +114,12 @@ func (m *ProviderMicrosoft) updateSubject(ctx context.Context, claims *Claims, e
return nil, errors.WithStack(herodot.ErrInternalServerError.WithReasonf("Unable to decode JSON from `https://graph.microsoft.com/v1.0/me`: %s", err))
}

claims.Subject = user["id"].(string)
ok := false
claims.Subject, ok = user["id"].(string)
if !ok {
return nil, errors.WithStack(herodot.ErrInternalServerError.WithReason("Unable to retrieve subject from response"))
}

claims.RawClaims["user"] = user
}

Expand Down

0 comments on commit 874d9c5

Please sign in to comment.