Configure an "on behalf of" authentication flow for AI agents
The "on behalf of" flow allows an AI agent to perform actions on behalf of an end user, which is useful for securing the actions of digital assistants.
Task 1: Configure the OAuth 2.0 provider service
Configure the OAuth 2.0 provider service to support the grant types needed for the "on behalf of" authentication flow:
-
In the Advanced Identity Cloud admin console, go to Native Consoles > Access Management > Services.
-
Click the OAuth2 Provider service, then click the Advanced tab:
-
In the Grant Types field, select the Resource Owner Password Credentials and Token Exchange grant types, if they aren’t already selected.
-
-
Click Save Changes.
Task 2: Create and configure a custom OAuth 2.0 application
Create and configure a custom OAuth 2.0 application with a confidential client type to act as a resource that the AI agent can access on behalf of end users.
Task 2.1: Create a custom OAuth 2.0 application
-
In the Advanced Identity Cloud admin console, go to Applications, then click Custom Application.
-
In the Add a Custom Application modal:
-
Click OIDC - OpenId Connect, then click Next.
-
Click Web, then click Next.
-
-
In the Application Details modal:
-
Enter a name for the application. For example,
Digital Assistant Web App. -
Select one or more application Owners.
-
Click Next.
-
-
In the Web Settings modal:
-
Enter a Client ID for the application using only alphanumeric characters, dashes, or underscores. For example,
digital-assistant-web-app. -
Enter a Client Secret and make a note of it, as you won’t be able to view it again after creating the application.
-
Click Create Application.
-
-
Follow the instructions in Configure a custom OAuth 2.0 application to configure the application you created.
Task 2.2: Configure a custom OAuth 2.0 application
-
In the Advanced Identity Cloud admin console, go to Applications.
-
Review the Applications page to find the application you want to configure.
-
Click the applications’s ellipsis icon (), then click Edit.
-
Click the Sign On tab to configure the application’s OAuth 2.0 client:
-
In the Grant Types field, select Resource Owner Password Credentials to add it to the existing grant types.
-
In the Scopes field, enter the scopes that the application needs to access resources. For example,
openid,read-data,write-data, andadmin-action. -
Click Show Advanced Settings to display a vertical tab menu, then click the Authentication vertical tab.
-
In the Token Endpoint Authentication Method field, select
client_secret_post. -
Click Save.
-
Task 3: Create and configure an AI agent
Create and configure an AI agent that can access the custom OAuth 2.0 application on behalf of end users using the token exchange grant type.
Task 3.1: Create an AI agent
-
Follow the instructions in Create an AI agent. An example name for the AI agent is
Digital Assistant AI Agent, and an example client ID isdigital-assistant-ai-agent. These example values are used for illustrative purposes in the following sections. -
Follow the instructions in Configure an AI agent to configure the AI agent you created.
Task 3.2: Configure an AI agent
-
In the Advanced Identity Cloud admin console, go to AI Agents.
-
Review the AI Agents page to find the AI agent you want to configure.
-
Click the AI agent’s ellipsis icon (), then click Edit.
-
Click the Access tab to configure the agent’s OAuth 2.0 client:
-
Click Show Advanced Settings to display a vertical tab menu, then click the Advanced vertical tab:
-
In the Grant Types field, enter
urn:ietf:params:oauth:grant-type:token-exchange. -
In the Token Endpoint Authentication Method field, select
client_secret_post. -
Click the OAuth Provider Overrides tab.
-
Select the Enable OAuth2 Provider Overrides checkbox.
-
Select the Use Client-Side Access & Refresh Tokens checkbox.
-
Select the Accept Audience Parameters in Token Exchange Requests checkbox.
-
-
Click the Applications tab:
-
Click Add Application.
-
In the Resource field, select the custom OAuth 2.0 application you created in the previous task.
-
Click Save.
-
In the Subjects field, select users that the AI agent will act on behalf of or in the Subject Groups field, select groups of users that the AI agent will act on behalf of.
-
In the Permissions field, choose one of the following approaches:
-
To limit the scopes the AI agent can request, select specific scopes. For example,
read-data. This approach is recommended for "on behalf of" operations where the AI agent only needs access to a limited set of permissions. -
To allow the AI agent to request any or all of the scopes that are assigned to the custom OAuth 2.0 application, select all scopes in this field or leave it empty. This approach might be suitable for "human-in-the-loop" workflows, where end users are required to explicitly approve high-risk or sensitive operations.
You can also enter custom scope values that aren’t in the drop-down list by typing them into the field.
-
-
Click Save.
-
Task 4: Test the authentication flow
Run a series of commands to get an access token for an end user and then exchange it for a new access token that represents an AI agent acting on behalf of the end user.
Task 4.1: Get an end user access token
-
Create a user account for the end user that the AI agent will act on behalf of, if one doesn’t already exist.
-
Get an access token for the end user using the Resource Owner Password Credentials grant type:
$ curl \ --request POST 'https://<tenant-env-fqdn>/am/oauth2/realms/root/realms/alpha/access_token' \(1) --header 'Content-Type: application/x-www-form-urlencoded' \ --data-urlencode 'grant_type=password' \(2) --data-urlencode 'username=<end-user-username>' \(3) --data-urlencode 'password=<end-user-password>' \(4) --data-urlencode 'client_id=<oauth2-app-client-id>' \(5) --data-urlencode 'client_secret=<oauth2-app-client-secret>' \(6) --data-urlencode 'scope=<application-scopes>'(7)Show request guidance
1 Replace <tenant-env-fqdn> with the FQDN of your tenant environment. 2 The grant_typefor this request ispassword, which represents the Resource Owner Password Credentials grant type.3 Replace <end-user-username> with the username of the end user that the AI agent will act on behalf of. For example, barbara.jensen.4 Replace <end-user-password> with the password of the end user. 5 Replace <oauth2-app-client-id> with client ID of the custom OAuth 2.0 application you created in task 2. For example, digital-assistant-web-app.6 Replace <oauth2-app-client-secret> with the client secret of the custom OAuth 2.0 application. 7 Replace <application-scopes> with some or all of the scopes you assigned to the custom OAuth 2.0 application. For example, openid.{ "access_token": "eyJ0eXAiOi...nbCv_gODEw", (1) "refresh_token": "eyJ0eXAiOi...1HXGCc8z0s", "scope": "openid", "token_type": "Bearer", "expires_in": 3599 }Show response guidance
1 The access_tokenvalue in the response is the end user’s access token. -
Introspect the end user’s access token to verify that the
subclaim represents the end user and the token contains the expected scopes:$ curl \ --request POST 'https://<tenant-env-fqdn>/am/oauth2/realms/root/realms/alpha/introspect' \(1) --header 'Content-Type: application/x-www-form-urlencoded' \ --data-urlencode 'token=<end-user-access-token>' \(2) --data-urlencode 'client_id=<oauth2-app-client-id>' \(3) --data-urlencode 'client_secret=<oauth2-app-client-secret>' \(4)Show request guidance
1 Replace <tenant-env-fqdn> with the FQDN of your tenant environment. 2 Replace <end-user-access-token> with the end-user’s access token from the response in step 2. 3 Replace <oauth2-app-client-id> with client ID of the custom OAuth 2.0 application. For example, digital-assistant-ai-agent.4 Replace <oauth2-app-client-secret> with the client secret of the custom OAuth 2.0 application. { "active": true, "scope": "openid", (1) "realm": "/alpha", "client_id": "digital-assistant-web-app", "user_id": "2199ef22-7927-4ecf-8345-ee58df8f6328", "username": "2199ef22-7927-4ecf-8345-ee58df8f6328", "token_type": "Bearer", "exp": 1775741840, "sub": "2199ef22-7927-4ecf-8345-ee58df8f6328", (2) "iss": "https://<tenant-env-fqdn>:443/am/oauth2/realms/root/realms/alpha", "subname": "2199ef22-7927-4ecf-8345-ee58df8f6328", "auth_level": 0, "authGrantId": "zCUFAdfohd5ul06NsTienRQrCrk", "auditTrackingId": "c1665344-1da9-4804-b95a-de0a4013d026-550633", "expires_in": 3578 }Show response guidance
1 The scopeclaim contains the application scopes that the end user can access.2 The subclaim contains the end user’s UUID, which indicates that the token represents the end user.
Task 4.2: Get an AI agent access token
-
Use the Token Exchange grant type to exchange the end user’s access token for a new AI agent access token that the AI agent can use to access the custom OAuth 2.0 application on behalf of the end user:
$ curl \ --request POST 'https://<tenant-env-fqdn>/am/oauth2/realms/root/realms/alpha/access_token' \(1) --header 'Content-Type: application/x-www-form-urlencoded' \ --data-urlencode 'grant_type=urn:ietf:params:oauth:grant-type:token-exchange' \(2) --data-urlencode 'subject_token=<end-user-access-token>' \(3) --data-urlencode 'subject_token_type=urn:ietf:params:oauth:token-type:access_token' \ --data-urlencode 'client_id=<ai-agent-client-id>' \(4) --data-urlencode 'client_secret=<ai-agent-client-secret>' \(5) --data-urlencode 'audience=<oauth2-app-client-id>' \(6) --data-urlencode 'scope=<ai-agent-scopes>'(7)Show request guidance
1 Replace <tenant-env-fqdn> with the FQDN of your tenant environment. 2 The grant_typefor this request isurn:ietf:params:oauth:grant-type:token-exchange, which represents the Token Exchange grant type.3 Replace <end-user-access-token> with the end user’s access token. 4 Replace <ai-agent-client-id> with client ID of the AI agent you created in task 3. For example, digital-assistant-ai-agent.5 Replace <ai-agent-client-secret> with the client secret of the AI agent. 6 Replace <oauth2-app-client-id> with the client ID of the custom OAuth 2.0 application. For example, digital-assistant-web-app. Setting this as theaudienceindicates that the AI agent intends to access the custom OAuth 2.0 application on behalf of the end user.7 Replace <ai-agent-scopes> with some or all of the scopes that you assigned to the AI agent in task 3.2, step 5e. For example, read-data.{ "access_token": "eyJ0eXAiOi...7-SnU_UoYg", (1) "refresh_token": null, "issued_token_type": "urn:ietf:params:oauth:token-type:access_token", "scope": "read-data", "token_type": "Bearer", "expires_in": 3599 }Show response guidance
1 The access_tokenvalue in the response is can be used by the AI agent to access the custom OAuth 2.0 application on behalf of the end user. -
Introspect the AI agent’s access token to verify that the
subclaim represents the end user and theactclaim contains the AI agent’s client ID:$ curl \ --request POST 'https://<tenant-env-fqdn>/am/oauth2/realms/root/realms/alpha/introspect' \(1) --header 'Content-Type: application/x-www-form-urlencoded' \ --data-urlencode 'token=<ai-agent-access-token>' \(2) --data-urlencode 'client_id=<ai-agent-client-id>' \(3) --data-urlencode 'client_secret=<ai-agent-client-secret>' \(4)Show request guidance
1 Replace <tenant-env-fqdn> with the FQDN of your tenant environment. 2 Replace <ai-agent-access-token> with the ai-agent’s access token from the response in step 1. 3 Replace <ai-agent-client-id> with client ID of the AI agent. For example, digital-assistant-ai-agent.4 Replace <ai-agent-client-secret> with the client secret of the AI agent. { "active": true, "scope": "read-data", (1) "realm": "/alpha", "client_id": "digital-assistant-ai-agent", "user_id": "2199ef22-7927-4ecf-8345-ee58df8f6328", "username": "2199ef22-7927-4ecf-8345-ee58df8f6328", "token_type": "Bearer", "exp": 1775741873, "sub": "2199ef22-7927-4ecf-8345-ee58df8f6328", (2) "iss": "https://<tenant-env-fqdn>:443/am/oauth2/realms/root/realms/alpha", "subname": "2199ef22-7927-4ecf-8345-ee58df8f6328", "auth_level": 0, "authGrantId": "e3ktYI6ggph39IdDz59pnIjZjeM", "act": { "sub": "digital-assistant-ai-agent" (3) }, "auditTrackingId": "c1665344-1da9-4804-b95a-de0a4013d026-550848", "expires_in": 3543 }Show response guidance
1 The scopeclaim contains the scopes that the AI agent can access.2 The subclaim contains the end user’s UUID, which indicates that the token represents the end user.3 The actclaim contains asubclaim with the AI agent’s client ID, which indicates that the AI agent is acting on behalf of the end user.