The Azure AI Bot Service facilitates the development of agents that can access online resources requiring user authentication. Your agent doesn’t need to manage authentication tokens because Azure does it for you. Azure uses OAuth 2.0 to generate a token based on each user’s credentials. Your agent uses the token generated by Azure to access those resources. In this way, the user doesn’t have to provide ID and password to the agent to access a secured resource but only to a trusted identity provider.
[!IMPORTANT] Web Chat and Direct Line considerations: You need to use Direct Line with enhanced authentication enabled to mitigate security risks when connecting to an agent using the Web Chat control. For more information, see Direct Line enhanced authentication.
To setup OAuth on agent, register an Azure Bot if you haven’t done so already.
[!IMPORTANT] Whenever you register an agent in Azure, the agent gets assigned an Microsoft Entra ID application. However, this application secures channel-to-bot access. You need an additional Microsoft Entra ID application for each external secured resource you want the agent to access on behalf of the user.
The Microsoft Entra ID is a cloud identity service that allows you to build applications that securely sign in users using industry standard protocols like OAuth 2.0.
You can use one of these three identity services:
These allow you to build applications that sign in to all Microsoft identity providers and get tokens to call Microsoft APIs, such as Microsoft Graph, or other APIs that developers have built.
This section shows how to create an Microsoft Entra ID identity provider that uses OAuth 2.0 to authenticate the agent for Graph.
[!TIP] You’ll need to create and register the Microsoft Entra ID application in a tenant in which you can consent to delegate permissions requested by an application.
Open the Microsoft Entra ID panel in the Azure portal. If you aren’t in the correct tenant, select Switch directory to switch to the correct tenant. (For information on how to create a tenant, see Access the portal and create a tenant.)
Open the App registrations panel.
In the App registrations panel, select New registration.
Fill in the required fields and create the app registration.
Name your application.
Select the Supported account types for your application. Select Single Tenant.
For the Redirect URI, select Web and set the URL to one of the supported OAuth redirect URLs.
Data residency | Cloud | OAuth URL | OAuth Redirect URL |
---|---|---|---|
None | Public | https://token.botframework.com | https://token.botframework.com/.auth/web/redirect |
Europe | Public | https://europe.token.botframework.com | https://europe.token.botframework.com/.auth/web/redirect |
United States | Public | https://unitedstates.token.botframework.com | https://unitedstates.token.botframework.com/.auth/web/redirect |
India | Public | https://india.token.botframework.com | https://india.token.botframework.com/.auth/web/redirect |
None | Azure Government | https://token.botframework.azure.us | https://token.botframework.azure.us/.auth/web/redirect |
None | Azure operated by 21Vianet | https://token.botframework.azure.cn | https://token.botframework.azure.cn/.auth/web/redirect |
On Add Credentials page, Choose the Federated credential scenario to Other Issuer
https://login.microsoftonline.com/{customer-tenant-ID}/v2.0
Subject Identifier : /eid1/c/pub/t/{base64 encoded customer tenant ID}/a/{base64 encoded 1-P app client ID}/{unique-identifier-for-projected-identity}
The following table contains Base64url encoded byte-array representation of supported First party application IDs. Use this value which represents our First party app.
Encoded Value | Description |
---|---|
9ExAW52n_ky4ZiS_jhpJIQ | Base64url encoded of Bot Service Token Store |
ND1y8_Vv60yhSNmdzSUR_A | Base64url encoded of Bot Framework Dev Portal |
The following table contains Base64url encoded byte-array representation of some supported tenant IDs. Use the value which represents tenant of your app.
Encoded Value | Description |
---|---|
v4j5cvGGr0GRqy180BHbRw | Base64url encoded MSIT tenant ID (aaaabbbb-0000-cccc-1111-dddd2222eeee) |
PwFflyR_6Een06vEdSvzRg | Base64url encoded PME tenant ID (bbbbcccc-1111-dddd-2222-eeee3333ffff) |
6q7FzcUVtk2wefyt0lBdwg | Base64url encoded Torus tenant ID (ccccdddd-2222-eeee-3333-ffff4444aaaa) |
IRngM2RNjE-gVVva_9XjPQ | Base64url encoded AME tenant ID (ddddeeee-3333-ffff-4444-aaaa5555bbbb) |
The Primary Identity service owners calculate it once and provide it to their consumers.
Unique-identifier-for-projected-identity: A Unique Identifier, of your choosing, that is used in the OAuth Connection Setting on the Azure Bot.
Provide information under Credential details.
api://{appid}
is expectedapi://botid-{appid}
Select Add a permission to show the Request API permissions pane.
For this sample, select Microsoft APIs and Microsoft Graph.
Choose Delegated permissions and make sure the permissions you need are selected. This sample requires theses permissions.
Note: Any permission marked as ADMIN CONSENT REQUIRED will require both a user and a tenant admin to login, so for your agent tend to stay away from these.
Select Add permissions. (The first time a user accesses this app through the agent, they need to grant consent.)
You now have a OAuth application configured.
[!NOTE] You’ll assign the Application (client) ID, when you create the connection string and register the identity provider with the agent registration. See next section.
The next step is to register your identity provider with your agent.
[!NOTE] Single Tenant Entra Application is only supported for AAD v2 with Federated Credentials service provider. Support for multi-tenant apps will be added in future.
Open your bot’s Azure Bot resource page in the Azure portal.
Select Settings, then Configuration.
Select the OAuth Connection Settings button near the bottom of the page.
Fill in the form as follows:
Name. Enter a name for your connection. You use it in your agent code.
Service Provider. Select AAD v2 with Federated Credentials to display service provider specific fields.
Client id. Enter the application (client) ID you recorded for your Microsoft Entra ID identity provider(Only Single Tenant Supported).
Unique Identifier. Enter the unique identifier you recorded for your Microsoft Entra ID identity provider while creating federated credentials.
Token Exchange URL. Leave it blank because it’s used for SSO in Microsoft Entra ID only.
Tenant ID. Enter the directory (tenant) ID that you recorded earlier for your Microsoft Entra ID app or common
depending on the supported account types selected when you created the Azure DD app. To decide which value to assign, follow these criteria:
common
instead of a tenant ID. Otherwise, the Microsoft Entra ID app verifies through the tenant whose ID was selected and exclude personal Microsoft accounts.This is the tenant associated with the users who can be authenticated. For more information, see Tenancy in Microsoft Entra ID.
For Scopes, enter the names of the permission you chose from the application registration. For testing purposes, you can just enter: openid profile User.Read User.ReadBasic.All
.
Note: For Microsoft Entra ID, Scopes field takes a case-sensitive, space-separated list of values.
Select Save.
your-connection-succeeded
is your specific connection name.You can now use this connection name in your agent code to retrieve user tokens.