-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9259d08
commit c9fb9c0
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# AzureExtensions.FunctionToken | ||
Extension Attribute to Azure Functions v2, that allows to obrain ClaimsPrincipal on every request. Currently supports key load from Azure B2C by jwks_uri and simple JsonWebKey. Pluggable on Azyre Function Startup | ||
|
||
The extension allows you to use custom tokens in Azure Functions v2. | ||
|
||
Step 1. | ||
1. Add the nuget *AzureExtensions.FunctionToken* | ||
2. Add to StartUp file: | ||
|
||
``` | ||
builder.AddAzureFunctionsToken(new TokenSinginingKeyOptions() | ||
{ | ||
SigningKey = new JsonWebKey("your key"), | ||
Audience = "your audience", | ||
Issuer = "your issuer" | ||
}); | ||
``` | ||
|
||
OR | ||
|
||
``` | ||
builder.AddAzureFunctionsToken(new TokenAzureB2COptions() | ||
{ | ||
//AzureB2CSingingKeyUri = new Uri("https://yourapp.b2clogin.com/yourapp.onmicrosoft.com/discovery/v2.0/keys?p=yourapp-policy"), | ||
Audience = "your audience", | ||
Issuer = "your issuer" | ||
}); | ||
``` | ||
|
||
3. Add it to Azure Function: | ||
|
||
``` | ||
public class Example | ||
{ | ||
[FunctionName("Example")] | ||
public async Task<IActionResult> 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}"); | ||
} | ||
} | ||
``` | ||
|
||
4. That's it. See examples for the details. | ||
|