Authentication for Azure Functions

后端 未结 3 874
忘掉有多难
忘掉有多难 2020-12-01 12:45

I\'ve spent the past 24 hours reading all about how to create Azure Functions and have successfully converted a MVC WebApi over to a new Function App with multiple functions

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-01 12:56

    I've created a small extension to Azure Functions v2, that might help you when used with Bearer Tokens.

    For instance, to work with Azure B2C, when you want to allow anonymous requests to the app.

    So you can obtain your ClaimsPrincipal right in the Azure Function without any boilerplate used.

    [FunctionName("Example")]
    public async Task Run(
        [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req,
        [FunctionToken] FunctionTokenResult token,
        ILogger log)
    {
        log.LogInformation("C# HTTP trigger function processed a request.");
        return (ActionResult) new OkObjectResult($"Hello, {token}");
    }
    

    Code is posted to Github

提交回复
热议问题