MCPcopy Index your code
hub / github.com/coder/coder / ParseClaims

Method ParseClaims

coderd/idpsync/organization.go:249–285  ·  view source on GitHub ↗

ParseClaims will parse the claims and return the list of organizations the user should sync to.

(ctx context.Context, db database.Store, mergedClaims jwt.MapClaims)

Source from the content-addressed store, hash-verified

247// ParseClaims will parse the claims and return the list of organizations the user
248// should sync to.
249func (s *OrganizationSyncSettings) ParseClaims(ctx context.Context, db database.Store, mergedClaims jwt.MapClaims) ([]uuid.UUID, error) {
250 userOrganizations := make([]uuid.UUID, 0)
251
252 if s.AssignDefault {
253 // This is a bit hacky, but if AssignDefault is included, then always
254 // make sure to include the default org in the list of expected.
255 defaultOrg, err := db.GetDefaultOrganization(ctx)
256 if err != nil {
257 return nil, xerrors.Errorf("failed to get default organization: %w", err)
258 }
259
260 // Always include default org.
261 userOrganizations = append(userOrganizations, defaultOrg.ID)
262 }
263
264 organizationRaw, ok := mergedClaims[s.Field]
265 if !ok {
266 return userOrganizations, nil
267 }
268
269 parsedOrganizations, err := ParseStringSliceClaim(organizationRaw)
270 if err != nil {
271 return userOrganizations, xerrors.Errorf("failed to parese organizations OIDC claims: %w", err)
272 }
273
274 // add any mapped organizations
275 for _, parsedOrg := range parsedOrganizations {
276 if mappedOrganization, ok := s.Mapping[parsedOrg]; ok {
277 // parsedOrg is in the mapping, so add the mapped organizations to the
278 // user's organizations.
279 userOrganizations = append(userOrganizations, mappedOrganization...)
280 }
281 }
282
283 // Deduplicate the organizations
284 return slice.Unique(userOrganizations), nil
285}

Callers 1

SyncOrganizationsMethod · 0.45

Calls 4

UniqueFunction · 0.92
ParseStringSliceClaimFunction · 0.85
ErrorfMethod · 0.45

Tested by

no test coverage detected