An organization may have many different identity providers for authenticating users. Some identity providers are internal such as username-password, while others are external federated identity providers. Here, I will explain how to use IdP policy on OCI identity domain to automatically set an identity provider for user authentication based on username attribute. This is an example scenario for this IdP policy:
- If username ending with domain1.com, use identity provider IDP1 to authenticate the user.
- If username ending with domain2.com, use identity provider IDP2 to authenticate the user.
- (Optionally) Anyone else not in domain1.com and domain2.com, use IDP3 to authenticate.
In this example, IDP1, IDP2 and IDP3 can be any identity provider such as username_password, SAML or OpenID Connect. Here’s the steps to implement this on OCI:
- Enable username first flow
- In the OCI Console, under Identity & Security -> Domains
- Click on the Domain. In this example, TestDomain
- On the left navigation link, click on Settings
- Then click on Session settings on the left
- Click on the Enable username first flow check box and click Save changes at the bottom
- For this example, the 3 Identity providers IDP1, IDP2 and IDP3 are already created and configured.
- Create a new IdP policy with 4 IdP rules
- Under Identity > Domains > TestDomain > Security > IdP polies, click Create IdP policy
- Enter the name of the new policy and click Add policy
- Click Add IdP rule
- Create the 1st rule with username-password as the identity provider and empty username as the condition. However, empty username is not a condition that is available in the OCI console UI and this condition can only be set using API call. Leave the condition as empty for now and click Add IdP rule.
- Create the 2nd rule and set the identity provider to IDP1 and set the condition to end with @domain1.com
- Create the 3rd rule and set the identity provider to IDP2 and set the condition to end with @domain2.com
- (Optionally) Create 4th rule and set the identity provider to IDP3 and leave the condition as empty.
- The IdP policy with all 4 IdP rules is now created.
- Go back to the 1st rule and find the condition OCID of this rule. Use the identity domain API call to patch this condition and set the attribute to username is empty.
- Open network trace in the browser and edit the 1st rule.
- Get the condition OCID attached to the rule by click on the network trace that start with “Conditions?filter”. The OCID can be seen in the payload. Copy and save the OCID.
- Use the identity domain API call to patch this condition. This can be done using oci raw-request from cloud shell or Postman or curl. Using oci raw-request from cloud shell is simplest.
- To use oci raw-request, open cloud shell from OCI console.
- In Cloud Shell, use an editor of your choice to create a file request.json with the following condition payload:
- The request.json should look like this:
- Run the oci raw-request command using your identity domain url and the condition ocid saved from network trace in step above.
oci raw-request --http-method PATCH --target-uri <identity domain url>/admin/v1/Conditions/<Condition OCID> --request-body file://request.json
- Make sure the status returned is 200 indicating the request is successful
- This completes the patch operation of the EmptyUsernameRule condition.
- Once the IdP rules are configured, click Next to Add apps to add all the applications that would use this IdP policy for authentication.
Now with this IdP policy, a user attempting to authenticate to this identity domain will be presented with login page with username field only. Once the username is entered, then the user will be directed to the corresponding identity provider based on the username to authenticate into applications assigned to IdP policy.
Postman can also be used for patching the IdP policy rule condition with the identity domain Rest API. If you want to do this in Postman, here’re the steps for Postman
- Configure a Confidential Application in the identity domain if one does not exist.
- Under Identity > Domains > TestDomain, click Integrated applications on the left. Then click Add application and select Confidential Application and Launch workflow.
- Enter a Name and click Next.
- In Configure OAuth screen, Client configuration section, select Configure this application as a client now. Select client credentials
- Scroll to the bottom and select Add app role
- Click Add roles and select Identity Domain Administrator and click Add
- Click Next and Finish
- Then Activate the application
- Copy and save both the Client ID and Client Secret
- Get an oauth token for the identity domain. In this example, postman is used for the identity domain api call.
- In the collections, expand REST_API_for_Oracle_Identity_Cloud_Service > OAuth >Tokens and click on Obtain access_token (client_credentials)
- Edit Environment variable and set the current values of variables for HOST, Client ID and Client Secret of the identity domain
- Click Send to get the access token
- Copy the access token and edit the environment and paste in the access token in current value
- PATCH the condition with payload below
- In postman, navigate to Policy > Conditions > Modify > Patch Update a condition.
- In the URL, paste the saved condition OCID after /admin/v1/Conditions/.
- In the Body, copy the payload and run it. Make sure the Status code is 200
- After completing the patch operation, delete the confidential application created in step 1.
Master Principal Solution Engineer