-
Notifications
You must be signed in to change notification settings - Fork 1
Add option to use app links API instead of listing app users. #113
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
7c6da5b
3dba989
b8d9a17
35a790a
429b421
3b78d85
38d046e
58b8d9a
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 |
|---|---|---|
|
|
@@ -17,7 +17,8 @@ import ( | |
| "github.com/conductorone/baton-sdk/pkg/crypto" | ||
| "github.com/conductorone/baton-sdk/pkg/pagination" | ||
| "github.com/conductorone/baton-sdk/pkg/ratelimit" | ||
| "github.com/conductorone/baton-sdk/pkg/types/resource" | ||
| sdkGrant "github.com/conductorone/baton-sdk/pkg/types/grant" | ||
| sdkResource "github.com/conductorone/baton-sdk/pkg/types/resource" | ||
| mapset "github.com/deckarep/golang-set/v2" | ||
| "github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap" | ||
| "github.com/okta/okta-sdk-golang/v2/okta" | ||
|
|
@@ -289,7 +290,37 @@ func (o *userResourceType) Grants( | |
| resource *v2.Resource, | ||
| token *pagination.Token, | ||
| ) ([]*v2.Grant, string, annotations.Annotations, error) { | ||
| return nil, "", nil, nil | ||
| // This shouldn't be necessary since we skip grants if useAppLinksForUserGrants is false, but it's good to be safe. | ||
| if !o.connector.useAppLinksForUserGrants { | ||
| return nil, "", nil, nil | ||
| } | ||
|
|
||
| // This API is not paginated. It returns all app links for a user. | ||
| appLinks, resp, err := o.connector.client.User.ListAppLinks(ctx, resource.Id.Resource) | ||
| if err != nil { | ||
| return nil, "", nil, fmt.Errorf("okta-connectorv2: failed to fetch app links from okta: %w", handleOktaResponseError(resp, err)) | ||
| } | ||
| rv := make([]*v2.Grant, 0) | ||
| for _, appLink := range appLinks { | ||
| var appTraitOpts []sdkResource.AppTraitOption | ||
| appResource, err := sdkResource.NewAppResource(appLink.Label, resourceTypeApp, appLink.AppInstanceId, appTraitOpts, | ||
| sdkResource.WithAnnotation(&v2.V1Identifier{Id: fmtResourceIdV1(appLink.AppInstanceId)}), | ||
| sdkResource.WithAnnotation(&v2.RawId{Id: appLink.AppInstanceId}), | ||
| ) | ||
| if err != nil { | ||
| return nil, "", nil, err | ||
| } | ||
|
|
||
| rv = append(rv, sdkGrant.NewGrant(appResource, "access", resource, | ||
| sdkGrant.WithAnnotation( | ||
| &v2.V1Identifier{ | ||
| Id: fmtGrantIdV1(V1MembershipEntitlementID(appResource.Id.Resource), resource.Id.Resource), | ||
| }, | ||
| ), | ||
| )) | ||
| } | ||
|
|
||
| return rv, "", nil, nil | ||
|
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. Bug: Grants Method Fails Pagination and Rate LimitingThe |
||
| } | ||
|
|
||
| func userName(user *okta.User) (string, string) { | ||
|
|
@@ -350,21 +381,28 @@ func listUsers(ctx context.Context, client *okta.Client, token *pagination.Token | |
| return oktaUsers, respCtx, nil | ||
| } | ||
|
|
||
| func getResourceType(useAppLinksForUserGrants bool) *v2.ResourceType { | ||
| if useAppLinksForUserGrants { | ||
| return resourceTypeUserWithGrants | ||
| } | ||
| return resourceTypeUser | ||
| } | ||
|
|
||
| func ciamUserBuilder(connector *Okta) *userResourceType { | ||
| var loweredFilters []string | ||
| for _, ef := range connector.ciamConfig.EmailDomains { | ||
| loweredFilters = append(loweredFilters, strings.ToLower(ef)) | ||
| } | ||
| return &userResourceType{ | ||
| resourceType: resourceTypeUser, | ||
| resourceType: getResourceType(connector.useAppLinksForUserGrants), | ||
| ciamEmailFilters: loweredFilters, | ||
| connector: connector, | ||
| } | ||
| } | ||
|
|
||
| func userBuilder(connector *Okta) *userResourceType { | ||
| return &userResourceType{ | ||
| resourceType: resourceTypeUser, | ||
| resourceType: getResourceType(connector.useAppLinksForUserGrants), | ||
| connector: connector, | ||
| } | ||
| } | ||
|
|
@@ -376,8 +414,8 @@ func userResource(ctx context.Context, user *okta.User, skipSecondaryEmails bool | |
| oktaProfile := *user.Profile | ||
| oktaProfile["c1_okta_raw_user_status"] = user.Status | ||
|
|
||
| options := []resource.UserTraitOption{ | ||
| resource.WithUserProfile(oktaProfile), | ||
| options := []sdkResource.UserTraitOption{ | ||
| sdkResource.WithUserProfile(oktaProfile), | ||
| // TODO?: use the user types API to figure out the account type | ||
| // https://developer.okta.com/docs/reference/api/user-types/ | ||
| // resource.WithAccountType(v2.UserTrait_ACCOUNT_TYPE_UNSPECIFIED), | ||
|
|
@@ -389,17 +427,17 @@ func userResource(ctx context.Context, user *okta.User, skipSecondaryEmails bool | |
| } | ||
|
|
||
| if user.Created != nil { | ||
| options = append(options, resource.WithCreatedAt(*user.Created)) | ||
| options = append(options, sdkResource.WithCreatedAt(*user.Created)) | ||
| } | ||
| if user.LastLogin != nil { | ||
| options = append(options, resource.WithLastLogin(*user.LastLogin)) | ||
| options = append(options, sdkResource.WithLastLogin(*user.LastLogin)) | ||
| } | ||
|
|
||
| if email, ok := oktaProfile["email"].(string); ok && email != "" { | ||
| options = append(options, resource.WithEmail(email, true)) | ||
| options = append(options, sdkResource.WithEmail(email, true)) | ||
| } | ||
| if secondEmail, ok := oktaProfile["secondEmail"].(string); ok && secondEmail != "" && !skipSecondaryEmails { | ||
| options = append(options, resource.WithEmail(secondEmail, false)) | ||
| options = append(options, sdkResource.WithEmail(secondEmail, false)) | ||
| } | ||
|
|
||
| if skipSecondaryEmails { | ||
|
|
@@ -418,36 +456,36 @@ func userResource(ctx context.Context, user *okta.User, skipSecondaryEmails bool | |
| // If possible, calculate shortname alias from login | ||
| splitLogin := strings.Split(login, "@") | ||
| if len(splitLogin) == 2 { | ||
| options = append(options, resource.WithUserLogin(login, splitLogin[0])) | ||
| options = append(options, sdkResource.WithUserLogin(login, splitLogin[0])) | ||
| } else { | ||
| options = append(options, resource.WithUserLogin(login)) | ||
| options = append(options, sdkResource.WithUserLogin(login)) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if employeeIDs.Cardinality() > 0 { | ||
| options = append(options, resource.WithEmployeeID(employeeIDs.ToSlice()...)) | ||
| options = append(options, sdkResource.WithEmployeeID(employeeIDs.ToSlice()...)) | ||
| } | ||
|
|
||
| switch user.Status { | ||
| // TODO: change userStatusDeprovisioned to STATUS_DELETED once we show deleted stuff in baton & the UI | ||
| // case userStatusDeprovisioned: | ||
| // options = append(options, resource.WithDetailedStatus(v2.UserTrait_Status_STATUS_DELETED, user.Status)) | ||
| case userStatusSuspended, userStatusDeprovisioned: | ||
| options = append(options, resource.WithDetailedStatus(v2.UserTrait_Status_STATUS_DISABLED, user.Status)) | ||
| options = append(options, sdkResource.WithDetailedStatus(v2.UserTrait_Status_STATUS_DISABLED, user.Status)) | ||
| case userStatusActive, userStatusProvisioned, userStatusStaged, userStatusPasswordExpired, userStatusRecovery, userStatusLockedOut: | ||
| options = append(options, resource.WithDetailedStatus(v2.UserTrait_Status_STATUS_ENABLED, user.Status)) | ||
| options = append(options, sdkResource.WithDetailedStatus(v2.UserTrait_Status_STATUS_ENABLED, user.Status)) | ||
| default: | ||
| options = append(options, resource.WithDetailedStatus(v2.UserTrait_Status_STATUS_UNSPECIFIED, user.Status)) | ||
| options = append(options, sdkResource.WithDetailedStatus(v2.UserTrait_Status_STATUS_UNSPECIFIED, user.Status)) | ||
| } | ||
|
|
||
| ret, err := resource.NewUserResource( | ||
| ret, err := sdkResource.NewUserResource( | ||
| displayName, | ||
| resourceTypeUser, | ||
| user.Id, | ||
| options, | ||
| resource.WithAnnotation(&v2.RawId{Id: user.Id}), | ||
| sdkResource.WithAnnotation(&v2.RawId{Id: user.Id}), | ||
|
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. Bug: User Resource Creation Ignores Dynamic Type SelectionThe |
||
| ) | ||
| return ret, err | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.