ParseClaims will take the merged claims from the IDP and return the groups the user is expected to be a member of. The expected group can either be a name or an ID. It is unfortunate we cannot use exclusively names or exclusively IDs. When configuring though, if a group is mapped from "A" -> "UUID 1
(orgID uuid.UUID, mergedClaims jwt.MapClaims)
| 364 | // We have to keep names because group sync supports syncing groups by name if |
| 365 | // the external IDP group name matches the Coder one. |
| 366 | func (s GroupSyncSettings) ParseClaims(orgID uuid.UUID, mergedClaims jwt.MapClaims) ([]ExpectedGroup, error) { |
| 367 | groupsRaw, ok := mergedClaims[s.Field] |
| 368 | if !ok { |
| 369 | return []ExpectedGroup{}, nil |
| 370 | } |
| 371 | |
| 372 | parsedGroups, err := ParseStringSliceClaim(groupsRaw) |
| 373 | if err != nil { |
| 374 | return nil, xerrors.Errorf("parse groups field, unexpected type %T: %w", groupsRaw, err) |
| 375 | } |
| 376 | |
| 377 | groups := make([]ExpectedGroup, 0) |
| 378 | for _, group := range parsedGroups { |
| 379 | // Legacy group mappings happen before the regex filter. |
| 380 | mappedGroupName, ok := s.LegacyNameMapping[group] |
| 381 | if ok { |
| 382 | group = mappedGroupName |
| 383 | } |
| 384 | |
| 385 | // Only allow through groups that pass the regex |
| 386 | if s.RegexFilter != nil { |
| 387 | if !s.RegexFilter.MatchString(group) { |
| 388 | continue |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | mappedGroupIDs, ok := s.Mapping[group] |
| 393 | if ok { |
| 394 | for _, gid := range mappedGroupIDs { |
| 395 | groups = append(groups, ExpectedGroup{OrganizationID: orgID, GroupID: &gid}) |
| 396 | } |
| 397 | continue |
| 398 | } |
| 399 | |
| 400 | groups = append(groups, ExpectedGroup{OrganizationID: orgID, GroupName: &group}) |
| 401 | } |
| 402 | |
| 403 | return groups, nil |
| 404 | } |
| 405 | |
| 406 | // HandleMissingGroups ensures all ExpectedGroups convert to uuids. |
| 407 | // Groups can be referenced by name via legacy params or IDP group names. |
no test coverage detected