Azure Function custom connector with Entra ID sign-in, step by step
Call your Azure Function from Power Apps and Power Automate through a custom connector with Entra ID sign-in: two app registrations, the connector's security settings, and the fixes for AADSTS50011 and 401.
Azure + Power PlatformFix a problem6 min read
A custom connector lets Power Apps, Power Automate and Copilot Studio call your own Azure Function like any other connector. With Entra ID sign-in instead of a function key, there's no shared secret in the app, each call carries the signed-in person's identity, and Azure turns away anyone who isn't signed in before your code runs. The set-up joins three places (the Function app, two Entra app registrations and the connector), and most failures come from one value that doesn't match between them.
- App or flow
- Custom connector
- Entra ID issues a token
- Function app checks the token
- Your code runs
Why two app registrations
- The API app represents your Function. App Service authentication checks every incoming token against it: who issued it, and whether it was issued for this API (its audience).
- The connector app represents the custom connector. It signs people in, holds the client secret, and asks Entra ID for a token for the API app on their behalf.
Keeping them separate means the connector can be granted exactly one permission on your API, and you can rotate the connector's secret without touching the Function. Both must be in the same Entra tenant as your environment.
Work through it
Protect the Function with Entra ID
- In the Azure portal, open the Function app and select Settings > Authentication.
- Select Add identity provider, choose Microsoft, and let it create a new app registration. This is the API app.
- Set Restrict access to Require authentication, and Unauthenticated requests to HTTP 401 Unauthorized, the choice for APIs.
- Open the new app registration and select Expose an API. Check that it has an Application ID URI, normally
api://followed by its client ID, and at least one scope. Add them if they're missing. Copy the URI. - Back on the Function app's Authentication page, edit the Microsoft provider and check that Allowed token audiences includes that Application ID URI. A token for any other audience is rejected.
About the function key: with Require authentication on, App Service refuses calls without a valid token before they reach your code. If your HTTP trigger also uses the Function authorization level, the connector must send the key as well. Either add the key to the connector as a second check, or set the trigger to Anonymous and rely on the sign-in; never do the second while authentication is optional.
Register the connector app
- In the Microsoft Entra admin center, open App registrations > New registration. Name it after the connector and keep it single-tenant unless people from other tenants will use it.
- Under Certificates & secrets, create a client secret. Copy the Value straight away, and note when it expires.
- Under API permissions, select Add a permission > My APIs, choose the Function's app, and tick its scope as a Delegated permission.
- If your tenant requires it, select Grant admin consent. Otherwise each person sees a consent prompt the first time they connect.
Create the connector
- In Power Apps or Power Automate, open Custom connectors and create one from blank, or import an OpenAPI file if your Function publishes one.
- On General, set Host to the Function app's host name (
<your-app>.azurewebsites.net) and Base URL to/api. - On Definition, add an action for each function you'll call, with its method, path and parameters. A sample request and response make the action's inputs and outputs readable in the designer.
Set the connector's security
On the Security tab:
| Field | Value |
|---|---|
| Authentication type | OAuth 2.0 |
| Identity provider | Microsoft Entra ID |
| Client ID | The connector app's Application (client) ID |
| Client secret | The secret's Value from the connector app |
| Authorization URL | https://login.microsoftonline.com (the default) |
| Tenant ID | Your tenant ID (or common for a multi-tenant connector app) |
| Resource URL | The Function's Application ID URI, exactly as on Expose an API |
Select Create connector. A Redirect URL then appears on this tab. Every connector has its own, of the form https://global.consent.azure-apim.net/redirect/<connector-id>. Copy it, and in the connector app open Authentication > Add a platform > Web, paste it, and save.
Test it
On the connector's Test tab, create a new connection, sign in, and run an action. A 200 with your function's response means every part matches. In the function, App Service passes the caller's identity in request headers such as X-MS-CLIENT-PRINCIPAL-NAME, so you can log or check who called without validating the token yourself.
When sign-in or the call fails
| What you see | What it means | Fix |
|---|---|---|
AADSTS50011 when signing in | The connector's redirect URL isn't on the connector app | Add the exact Redirect URL from the Security tab under Authentication > Web, and save |
AADSTS700016: application not found | The client ID is wrong, or the sign-in went to another tenant | Copy the client ID again and check Tenant ID |
AADSTS65001, or a consent prompt nobody can approve | Nobody has consented to the connector app's permission, and your tenant needs an admin to | An admin selects Grant admin consent on the connector app |
Sign-in works, the call returns 401 | The token's audience isn't one the Function accepts | Make Resource URL and Allowed token audiences the same Application ID URI |
401 mentioning a key, or the call works only with ?code= | The trigger still expects a function key | Send the key from the connector, or set the trigger to Anonymous with authentication required |
| An older connector stopped making new connections | It used the shared redirect URL from before 2024 | On Security, tick Update to unique redirect URL, save, and put the new URL on the connector app in place of the old one |
Keep it running
- Renew the client secret before it expires. When it lapses, every connection stops working. Create the new secret, update the connector's Security tab, then delete the old secret.
- Share the connector with the people who build apps and flows on it; each person signs in with their own account when they create a connection.
- Move it between environments in a solution, and keep the client secret out of source control.
Sources
- Authenticate your API and connector with Microsoft Entra ID, Microsoft Learn
- Create a custom connector for a web API, Microsoft Learn
- Custom connectors overview, Microsoft Learn (per-connector redirect URLs)
- Configure your App Service or Azure Functions app to use Microsoft Entra sign-in, Microsoft Learn
- Work with user identities in Azure App Service authentication, Microsoft Learn
- Error AADSTS50011: the redirect URI doesn't match, Microsoft Learn
- Microsoft Entra authentication and authorization error codes, Microsoft Learn
Did this fix it?
Comments
No comments yet. Share what worked for you.
Sign in to comment. Comments show under a display name you choose, never your email.