How to Generate Access Token value from Azure in Copilot Studio​

How to Get Azure Access Token from Copilot Studio Step by Step

No comments

Loading

In this “Get Azure Access Token” tutorial, we will learn about how to Get Azure Access Token from Copilot Studio Step by Step. In today’s digital landscape, secure API authentication is crucial for seamless integration between Microsoft services. Microsoft Copilot Studio allows us to automate processes and interact with various APIs, but to authenticate and access secured resources, we need an Azure Access Token.

In this article, we will walk you through the step-by-step process to get an Azure Access Token dynamically in Copilot Studio, using Power Automate and Microsoft Graph API authentication. This method ensures secure API authentication in Microsoft Copilot while enabling automation with Azure AD OAuth 2.0 tokens.

Prerequisites

Before proceeding, ensure you have the following:

  • A Microsoft Azure account
  • Azure AD App Registration with API permissions
  • Copilot Studio access
  • Power Automate license

Step 1: Register an App in Azure AD

To generate an access token, you need to register an application in Azure Active Directory (Entra ID).

Steps:

  1. Go to Azure Portal (Microsoft Azure Portal)
  2. Navigate to Azure Active DirectoryApp Registrations
  3. Click on New Registration
  4. Enter a name (e.g., “CopilotAPIAuth”)
  5. Choose Accounts in this organizational directory only
  6. Click Register

Example of App registration in Azure:

App registration in Azure Portal
App registration in Azure Portal

For the detailed step, refer to this article: App Registration in Azure: Quickly How Do I Register an Application Step by Step?

Step 1.1: Configure API Permissions

  1. Open your newly registered app
  2. Go to API PermissionsAdd a permission
  3. Select Microsoft GraphApplication Permissions
  4. Add the required permissions (e.g., User.Read, Files.ReadWrite)
  5. Click Grant admin consent

Example of Graph API Permissions in Azure portal:

Graph API permissions in Azure Portal
Graph API permissions in Azure Portal

Step 1.2: Generate Client Secret

  1. Navigate to Certificates & SecretsNew Client Secret
  2. Enter a name and set the expiration period
  3. Click Add and copy the generated secret (store it securely)

Example Client Secret in Azure Portal:

Generate Client Secret in Azure Portal
Generate Client Secret in Azure Portal

Step 2: Create Power Automate Flow for Token Generation

Since Copilot Studio does not support direct OAuth authentication, we use Power Automate to fetch the Azure AD OAuth 2.0 token.

Steps:

  1. Open Power Automate (Power Automate Maker Portal)
  2. Click on CreateInstant Cloud Flow
  3. Choose Manually trigger a flow → Click Create
  4. Add a new HTTP Action with the following details:
    • Method: POST
    • URL: https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/token
    • Headers:
      Content-Type: application/x-www-form-urlencoded
    • Body:
      client_id={client_id}&client_secret={client_secret}&grant_type=client_credentials&scope=https://graph.microsoft.com/.default
  5. Parse the response to extract the access_token
  6. Add a Respond to Copilot action to return the access token

Step 3: Call Power Automate Flow from Copilot Studio

Now, integrate this flow into Copilot Studio:

Steps:

  1. Open Copilot Studio → Select your bot
  2. Create a new topic (e.g., “Get Azure Access Token”)
  3. Add a Trigger Phrase (e.g., “Generate Access Token”)
  4. Add Call an Action → Select Power Automate Flow
  5. Map the output to store the access token
  6. Use the token to call Microsoft Graph API or other secured endpoints

Or you can skip the Power Automate steps; you can directly generate an Azure Access token from the Copilot Studio topic using the HTTP request action.

Get Azure Access Token using Copilot Studio Directly

Create a custom topic in Copilot Studio.

Add an HTTP Request action from the advanced menu.

HTTP Request in Copilot Studio topic
HTTP Request in Copilot Studio topic

For the URL, pass the below end point:

Syntax: https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/token
Example: https://login.microsoftonline.com/f10e1e03-fffa-47d0-86f4-d0e3c317c65d/oauth2/v2.0/token

Headers and Body Configuration:

Headers:

Content-Type: application/x-www-form-urlencoded

Body (x-www-form-urlencoded):

Syntax: client_id={client_id}&client_secret={client_secret}&grant_type=client_credentials&scope=https://graph.microsoft.com/.default
Example: client_id=11d4ceed-218f-4ab4-8e16-afa3573c369a&client_secret=HN88Q~hbPWNTCOxRDLtb-Ax67iXpYdES.yrkfdkm&grant_type=client_credentials&scope=https://graph.microsoft.com/.default
HTTP Request action setup in Copilot Studio topic
HTTP Request action setup in Copilot Studio topic

✅ Expected JSON Response: You will receive a JSON response with the access token:

{
"token_type": "Bearer",
"expires_in": 3600,
"access_token": "eyJ0eXAiOiJKV1Qi..."
}

You can use the above sample JSON for the API End point. Response data type select as “From sample data”, then click on the “Get schema from sample JSON”. In the box, paste the above JSON.

Get schema from sample JSON in Copilot Studio
Get schema from sample JSON in Copilot Studio

Once you save the schema, automatically record type will be changed to record as shown below.

Record data type in Copilot Studio
Record data type in Copilot Studio

Now, the API output is stored in a record variable, which I created. Now, we can extract the token type and access token value from this record type variable.

See the below example, I have extracted access token value from the API output and displayed in the message node.

Get access token from Azure Portal in Copilot Studio
Get access token from Azure Portal in Copilot Studio

Testing & Validation

  1. Trigger the Copilot topic → The Power Automate flow should execute
  2. Verify the response → Ensure the access token is generated successfully
  3. Use Postman or Graph Explorer to test API calls with the token

I have triggered my topic in Copilot Studio and got the access token along with its type from the Azure portal dynamically.

Get Azure Access Token Dynamically from Copilot Studio
Get Azure Access Token Dynamically from Copilot Studio

How to Debug API Access Token Value?

If you want to debug the above access token value in the human readable format, you can use this tool – jwt.ms

Best Practices for Secure API Authentication

  • Use Managed Identity if available, instead of client secrets
  • Store credentials securely in Azure Key Vault
  • Rotate client secrets regularly
  • Grant minimal required API permissions to the app

Conclusion

By following these steps, you can dynamically generate an Azure Access Token in Copilot Studio using Power Automate authentication. This method ensures secure API authentication while enabling seamless integration with Microsoft Graph API and other services.

🔹 Now it’s your turn! Try implementing this setup and enhance your automation workflows with Copilot Studio and Azure AD OAuth 2.0 tokens.

📢 Did you find this guide helpful? Share your thoughts in the comments and don’t forget to subscribe to our YouTube channel Power Platform Maven for more Microsoft Copilot Studio tutorials! 🚀

YouTube Video Demo

About Post Author

Do you have a better solution or question on this topic? Please leave a comment