LowCodeStacks™
Sign in

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

Checked against Microsoft Learn · 7 sourcesPosted by the Maker DeskHow we write guides

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.

What happens on each call
  1. App or flow
  2. Custom connector
  3. Entra ID issues a token
  4. Function app checks the token
  5. 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

  1. In the Azure portal, open the Function app and select Settings > Authentication.
  2. Select Add identity provider, choose Microsoft, and let it create a new app registration. This is the API app.
  3. Set Restrict access to Require authentication, and Unauthenticated requests to HTTP 401 Unauthorized, the choice for APIs.
  4. 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.
  5. 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

  1. 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.
  2. Under Certificates & secrets, create a client secret. Copy the Value straight away, and note when it expires.
  3. Under API permissions, select Add a permission > My APIs, choose the Function's app, and tick its scope as a Delegated permission.
  4. If your tenant requires it, select Grant admin consent. Otherwise each person sees a consent prompt the first time they connect.

Create the connector

  1. In Power Apps or Power Automate, open Custom connectors and create one from blank, or import an OpenAPI file if your Function publishes one.
  2. On General, set Host to the Function app's host name (<your-app>.azurewebsites.net) and Base URL to /api.
  3. 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:

FieldValue
Authentication typeOAuth 2.0
Identity providerMicrosoft Entra ID
Client IDThe connector app's Application (client) ID
Client secretThe secret's Value from the connector app
Authorization URLhttps://login.microsoftonline.com (the default)
Tenant IDYour tenant ID (or common for a multi-tenant connector app)
Resource URLThe 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 seeWhat it meansFix
AADSTS50011 when signing inThe connector's redirect URL isn't on the connector appAdd the exact Redirect URL from the Security tab under Authentication > Web, and save
AADSTS700016: application not foundThe client ID is wrong, or the sign-in went to another tenantCopy the client ID again and check Tenant ID
AADSTS65001, or a consent prompt nobody can approveNobody has consented to the connector app's permission, and your tenant needs an admin toAn admin selects Grant admin consent on the connector app
Sign-in works, the call returns 401The token's audience isn't one the Function acceptsMake 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 keySend the key from the connector, or set the trigger to Anonymous with authentication required
An older connector stopped making new connectionsIt used the shared redirect URL from before 2024On 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

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.