Skip to content

Commit

Permalink
Fix Okta IDP device authorization (#1023)
Browse files Browse the repository at this point in the history
* hide okta netbird attributes fields

* fix: update full user profile
  • Loading branch information
bcmmbaga authored Jul 21, 2023
1 parent 9e540cd commit a4d830e
Showing 1 changed file with 37 additions and 22 deletions.
59 changes: 37 additions & 22 deletions management/server/idp/okta.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,21 +270,32 @@ func (om *OktaManager) GetAllAccounts() (map[string][]*UserData, error) {

// UpdateUserAppMetadata updates user app metadata based on userID and metadata map.
func (om *OktaManager) UpdateUserAppMetadata(userID string, appMetadata AppMetadata) error {
var pendingInvite bool
user, resp, err := om.client.User.GetUser(context.Background(), userID)
if err != nil {
return err
}

if resp.StatusCode != http.StatusOK {
if om.appMetrics != nil {
om.appMetrics.IDPMetrics().CountRequestStatusError()
}
return fmt.Errorf("unable to update user, statusCode %d", resp.StatusCode)
}

profile := *user.Profile

if appMetadata.WTPendingInvite != nil {
pendingInvite = *appMetadata.WTPendingInvite
profile[wtPendingInvite] = *appMetadata.WTPendingInvite
}

_, resp, err := om.client.User.UpdateUser(context.Background(), userID,
okta.User{
Profile: &okta.UserProfile{
wtAccountID: appMetadata.WTAccountID,
wtPendingInvite: pendingInvite,
},
},
nil,
)
if appMetadata.WTAccountID != "" {
profile[wtAccountID] = appMetadata.WTAccountID
}

user.Profile = &profile
_, resp, err = om.client.User.UpdateUser(context.Background(), userID, *user, nil)
if err != nil {
fmt.Println(err.Error())
return err
}

Expand All @@ -311,7 +322,9 @@ func (om *OktaManager) InviteUserByID(_ string) error {
// updateUserProfileSchema updates the Okta user schema to include custom fields,
// wt_account_id and wt_pending_invite.
func updateUserProfileSchema(client *okta.Client) error {
required := true
// Ensure Okta doesn't enforce user input for these fields, as they are solely used by Netbird
userPermissions := []*okta.UserSchemaAttributePermission{{Action: "HIDE", Principal: "SELF"}}

_, resp, err := client.UserSchema.UpdateUserProfile(
context.Background(),
"default",
Expand All @@ -322,18 +335,20 @@ func updateUserProfileSchema(client *okta.Client) error {
Type: "object",
Properties: map[string]*okta.UserSchemaAttribute{
wtAccountID: {
MaxLength: 100,
MinLength: 1,
Required: &required,
Scope: "NONE",
Title: "Wt Account Id",
Type: "string",
MaxLength: 100,
MinLength: 1,
Required: new(bool),
Scope: "NONE",
Title: "Wt Account Id",
Type: "string",
Permissions: userPermissions,
},
wtPendingInvite: {
Required: new(bool),
Scope: "NONE",
Title: "Wt Pending Invite",
Type: "boolean",
Required: new(bool),
Scope: "NONE",
Title: "Wt Pending Invite",
Type: "boolean",
Permissions: userPermissions,
},
},
},
Expand Down

0 comments on commit a4d830e

Please sign in to comment.