Configure Authentication with Azure Functions on LocalHost

Viewed 1266

I'd like to use Visual Studio 2017 to build Azure Function App with HttpTrigger. However, I can't find the way how I could add Azure Active Directory authentication to secure the end point.

Will it work if I just add jwt token to the http request and then call ClaimsPrincipal.Current.Claims inside the method? Is there any other solution?

2 Answers

You can use the Microsoft OpenID Connect and JWT libraries to validate the token and get claims based on a received access token. Here's an example: https://github.com/azure-samples/ms-identity-dotnet-webapi-azurefunctions/tree/master/

  1. Create an app registration in AD
  2. Issue a browser request to get an access code
  3. Issue an HTTP POST request for an access token using the code and the secret via cURL
  4. Send the access token as an Authorization Bearer header to the local function endpoint

I had issues using newer versions of Microsoft.IdentityModel.Protocols.OpenIdConnect with .NET 6.0 and Azure Functions 4 and had to fall back to version 6.10.2.

Related