Configuring End-User Authentication with PKCE
The OAuth 2.0 (Authorization Code PKCE) credential type lets an AI Agent action call an external service on behalf of the individual end user. When the AI Agent runs an action that uses a PKCE credential, it asks the user to sign in to the external service in a pop-up window. The action then runs with that user's own access, so the AI Agent returns only the data that belongs to that user, such as their orders, tickets, bookings, or account details.
Use a PKCE credential when an action needs the user's own identity. Use the other credential types, such as API Key or OAuth 2.0 (Client Credentials), when one shared login is enough for all users.
How It Works
-
Setup: A partition administrator creates a PKCE credential in External Credentials and registers the eGain redirect URI with the identity provider. The administrator then selects the credential in the Authentication section of a custom API.
-
Sign-in: When a user asks a question that needs the action, the AI Agent pauses the action and shows a sign-in card in the chat. The user signs in to the external service in a pop-up window. eGain never sees the user's password.
-
Response: After the user signs in, the pop-up closes and the AI Agent continues automatically. It runs the action with the user's access and answers the original question. The user does not need to ask the question again.
Prerequisites
-
You must be a partition administrator to create and manage external credentials.
-
The external service must support the OAuth 2.0 authorization code flow with PKCE.
-
You need the authorization URL, token URL, and client ID of the application registered with the identity provider. A client secret is not required.
-
You need access to the identity provider's application settings to register the eGain redirect URI.
Creating a PKCE Credential
To create a PKCE credential:
-
In Agentic Studio, select the External Credentials tab.
-
Click the + Add New Credential button. The New Credential panel opens.
-
Enter a name for the credential.
-
From the Authentication Type dropdown, select OAuth 2.0 (Authorization Code PKCE).
-
In the OAuth 2.0 (Authorization Code PKCE) Configuration section, complete the fields described in the table below.
-
Copy the Redirect URI and register it with your identity provider as an allowed callback URL.
-
Optionally, select the Expiry Date & Time. This date and time is for internal notification purposes only and does not change the credential's actual expiry.
-
Click the Save Credential button.
The credential appears in the credential list with the type OAuth 2.0 (Authorization Code PKCE), and you can select it in the Authentication section of a custom API.
|
Field |
Required |
Description |
|
Authorization URL |
Yes |
The authorization endpoint of the identity provider. The user signs in at this URL. For example, |
|
Token URL |
Yes |
The token endpoint of the identity provider. eGain exchanges the authorization code for an access token at this URL. For example, |
|
Client ID |
Yes |
The client identifier that the identity provider issued for your application. |
|
Redirect URI |
Not applicable (read-only) |
The callback URL provided by eGain. You cannot edit this value. Click the Copy icon to copy it, and then register it with your identity provider. If the URI registered with the identity provider does not match this value exactly, sign-in fails. |
|
Scopes |
No |
The permissions that the action needs, separated by spaces. For example, |
Using the PKCE Credential in a Custom API
To use the PKCE credential in a custom API:
-
From the AI Agents tab, open the AI Agent.
-
Select Enable Actions, and then select the Custom APIs tab.
-
Click the Create Custom API button, or click the Edit icon on an existing custom API.
-
Complete the action details, such as the name, description, sample questions, protocol, method, and URL endpoint. For more information, see Configuring Custom APIs.
-
In the Authentication section, from the Select credential or create new dropdown, select the PKCE credential. Credentials of this type show the label OAuth 2.0 (Authorization Code PKCE).
-
Click the Save button.
Note: The Test Request button is not available for actions that use a PKCE credential, because the credential signs in as the end user. Test the action from the Test AI Agent page instead.
Testing the Sign-In Flow
To test the sign-in flow:
-
From the AI Agent's menu, select Test AI Agent.
-
In the Test your AI Agent panel, select the Standalone tab.
-
Enter a question that matches one of the action's sample questions. The AI Agent shows the sign-in card.
-
Click the Sign in button, and then sign in to the external service in the pop-up window.
After you sign in, the chat shows Connected to followed by the service name, and the AI Agent answers the question with the data returned by the action.
What End Users See
When an action needs the user's account and the user has not signed in, the AI Agent shows a Connect to card in the chat. The card includes the following options:
-
Sign in: Opens the identity provider's sign-in page in a pop-up window. The chat page does not reload or redirect. While the pop-up is open, the button changes to Waiting for sign-in, and a Cancel button appears. If the pop-up does not appear, the card prompts the user to check for a blocked pop-up.
-
Not now: Skips sign-in. The AI Agent continues without the action's data.
After the sign-in attempt, the chat shows one of the following notices:
-
Connected to followed by the service name: The user signed in. The AI Agent runs the action and answers the original question.
-
Couldn't connect to followed by the service name: The user declined, closed the pop-up, or did not sign in before the wait time ended. The action returns no data, and the AI Agent tells the user that it was unable to retrieve the information. The user can ask again to see the sign-in card again.
Sign-In Behavior
-
Same conversation: After the user signs in, later calls to the action in the same conversation run without asking the user to sign in again.
-
New conversation in the same browser: If the user's saved access is still valid, the sign-in step runs automatically. The pop-up opens and closes on its own, and the user is not asked to sign in.
-
Expired access: If the user's access has expired, eGain renews it in the background. The user sees the sign-in card again only if renewal is not possible.
-
Different browser or device: Saved access is stored per browser. On a different browser or device, the user sees the sign-in card again.
-
Disconnecting: Clearing the browser's saved data signs the user out. The next time the action runs, the user sees the sign-in card again.
-
Insufficient permissions: If the signed-in account does not have the required permissions, the action fails and the AI Agent tells the user that it was unable to complete the step.
-
Deleted credential: If the credential is deleted but an action still refers to it, the AI Agent skips the action and does not show a sign-in card.
-
Expiry date: The Expiry Date & Time of the credential is a reminder in Agentic Studio only. It does not block the action at runtime.
Security and Privacy
-
The user signs in directly with the identity provider. eGain never sees the user's password.
-
The user's access is saved in the user's own browser, not on eGain servers.
-
Access tokens are never written to the conversation transcript, conversation history, or analytics.
-
PKCE credentials do not use a client secret.
For more information about managing credentials, see Configuring External Credentials.