-
Notifications
You must be signed in to change notification settings - Fork 2
feat: staged account creation and profile attribute support #145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -541,6 +541,19 @@ func getCredentialOption(credentialOptions *v2.LocalCredentialOptions) (*okta.Us | |
| }, nil | ||
| } | ||
|
|
||
| // optionalProfileFields maps account creation schema field names to Okta profile attribute names. | ||
| var optionalProfileFields = map[string]string{ | ||
| "department": "department", | ||
| "title": "title", | ||
| "display_name": "displayName", | ||
| "user_type": "userType", | ||
| "organization": "organization", | ||
| "manager_id": "managerId", | ||
| "cost_center": "costCenter", | ||
| "division": "division", | ||
| "employee_number": "employeeNumber", | ||
| } | ||
|
|
||
| func getUserProfile(accountInfo *v2.AccountInfo) (*okta.UserProfile, error) { | ||
| pMap := accountInfo.Profile.AsMap() | ||
| firstName, ok := pMap["first_name"] | ||
|
|
@@ -563,33 +576,65 @@ func getUserProfile(accountInfo *v2.AccountInfo) (*okta.UserProfile, error) { | |
| login = email | ||
| } | ||
|
|
||
| return &okta.UserProfile{ | ||
| profile := &okta.UserProfile{ | ||
| "firstName": firstName, | ||
| "lastName": lastName, | ||
| "email": email, | ||
| "login": login, | ||
| }, nil | ||
| } | ||
| } | ||
|
|
||
| func getAccountCreationQueryParams(accountInfo *v2.AccountInfo, credentialOptions *v2.LocalCredentialOptions) (*query.Params, error) { | ||
| if credentialOptions.GetNoPassword() != nil { | ||
| return nil, nil | ||
| for schemaField, oktaField := range optionalProfileFields { | ||
| if val, ok := pMap[schemaField]; ok { | ||
| if strVal, isStr := val.(string); isStr && strVal != "" { | ||
| (*profile)[oktaField] = strVal | ||
| } | ||
| } | ||
| } | ||
|
|
||
| pMap := accountInfo.Profile.AsMap() | ||
| requirePass := pMap["password_change_on_login_required"] | ||
| requirePasswordChanged := false | ||
| switch v := requirePass.(type) { | ||
| return profile, nil | ||
| } | ||
|
|
||
| func parseBoolField(pMap map[string]interface{}, fieldName string) (bool, error) { | ||
| val := pMap[fieldName] | ||
| switch v := val.(type) { | ||
| case bool: | ||
| requirePasswordChanged = v | ||
| return v, nil | ||
| case string: | ||
| parsed, err := strconv.ParseBool(v) | ||
| if err != nil { | ||
| return nil, err | ||
| return false, err | ||
| } | ||
| requirePasswordChanged = parsed | ||
| return parsed, nil | ||
| case nil: | ||
| // Do nothing | ||
| return false, nil | ||
| default: | ||
| return false, fmt.Errorf("okta-connectorv2: unsupported type for %s: %T", fieldName, val) | ||
| } | ||
| } | ||
|
Comment on lines
+597
to
+613
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Suggestion: The |
||
|
|
||
| func getAccountCreationQueryParams(accountInfo *v2.AccountInfo, credentialOptions *v2.LocalCredentialOptions) (*query.Params, error) { | ||
| pMap := accountInfo.Profile.AsMap() | ||
|
|
||
| createStaged, err := parseBoolField(pMap, "create_in_staged_status") | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| // If creating in staged status, set Activate to false and return early. | ||
| // Staged users are not activated on creation regardless of credential options. | ||
| if createStaged { | ||
| return &query.Params{ | ||
| Activate: ToPtr(false), | ||
| }, nil | ||
| } | ||
|
|
||
| if credentialOptions.GetNoPassword() != nil { | ||
| return nil, nil | ||
| } | ||
|
|
||
| requirePasswordChanged, err := parseBoolField(pMap, "password_change_on_login_required") | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| params := &query.Params{} | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Suggestion:
okta.UserProfileis a map type (map[string]interface{}), so the pointer dereference is unnecessary when indexing. You can simplify this toprofile[oktaField] = strVal.