Synchronous User Creation

So I think as far as activation goes, that part is actually working out now.
The next issue I seem to be encountering is the fact that our users are taking some time to be assigned to our application.

I’ve tried to work around this by waiting upon user creation for this to happen with:

int isUserCurrentlyAssignedCheck = 0;
int maxAssignUserToApplicationChecks = 3;
int sleepTime = 7000;
while (isUserCurrentlyAssignedCheck < maxAssignUserToApplicationChecks) {
    ApplicationList assignedApps
            = oktaClientWrapper.getOktaClient()
                               .http()
                               .get("/api/v1/apps?filter=user.id+eq+\"" + user.getId() + "\"&expand=user/" + user.getId(),
                                    ApplicationList.class);

    Boolean userContainsAssignedApp
            = assignedApps.stream()
                          .map(Application::getName)
                          .anyMatch(applicationName -> applicationName.equalsIgnoreCase(oktaPropertiesService.getCompanyIdentifier()));

    if (userContainsAssignedApp) {
        break;
    } else {
        try {
            Thread.sleep(sleepTime);
        } catch (InterruptedException interruptedException) {
            throw new AppException("Error trying to wait for Okta to provision user", interruptedException);
        }
    }

    isUserCurrentlyAssignedCheck++;
}

if (isUserCurrentlyAssignedCheck >= maxAssignUserToApplicationChecks) {
    throw new OktaException("Timed out waiting for Okta to assign user to application after "
                                    + sleepTime * isUserCurrentlyAssignedCheck
                                    + " milliseconds");
}

// continue doing user stuff

My hope is that this will work out.

I’m reading through the user provisioning documentation right now and it actually mentions users having an externalId after being completely provisioned? It seems like maybe it would be better to check for this externalId instead of looking through the list of assigned applications, but the SDK doesn’t seem to expose this externalId.

Any advice or recommendations on this front?
Also, thank you so much for all the help so far!

1 Like