Reputation: 45
So, I created azure b2c directory, and created inside it application like https://github.com/Azure-Samples/active-directory-b2c-javascript-msal-singlepageapp, and I created azure function in general azure directory that suppose to read blob and return json file. Also I created custom login page for sign in. I ran my program locally, and I can login, and instead of call API that uses in github, I call azure function and it works. But now I want to secure access to function, so I make authLevel 'user' and try to make Authentication via Azure Active Directory. And no mater how I make settings, or I can't connect because I don't have permissions, or I can't use function because I don't have permissions. Also I get this error The client id ’/.auth/login/aad/callback' specified in the request is not registered in tenant ‘’.”
How should I connect function to b2c so only authorised users can have access to function response.
Upvotes: 2
Views: 3138
Reputation: 444
With the new "User flows (policies)" a few small changes must be made to the selected answer:
Perform Step-3 as follows to get the "Metadata Endpoint URL”: a) Go to your B2C tenant and click on User flows (policies). b) Select your login (or sign up sign in) flow and click on “Run user flow”. c) Your "Metadata Endpoint URL” is displayed at the top of the new window – right beneath the ”Run user flow” heading.
Perform Step-4 and 5 as follows to configure “Authentication”: a) Go to your function apps and click on your function app (NOT on one of your functions inside your function app). b) Click on Platform features and then on Authentication / Authorization. c) Turn on “App Service Authentication”. Select “Log in with Azure Active Directory” and then click on “Azure Active Directory – Configured (Advanced)”.
Continue with Step-6.
Upvotes: 1
Reputation: 922
Setting up B2C authentication for your Azure Functions App is actually really easy:
E.g. https://myazurefunctions.azurewebsites.net (make sure to make it a HTTPS URL)
Configure your application in Azure Active Directory B2C:
Get the Metadata Endpoint URL for your Sign-in policy
In your Functions App, on the bottom left select "Function app settings" and go to "Configure authentication":
Turn on authentication and select Azure Active Directory:
Select the advanced settings and enter the following values:
Client ID: The Application ID which you copied in step 2. a. Issuer Url: The Metadata Endpoint URL from step 3.
Save your settings and you're done!
Upvotes: 6