![]() |
VOOZH | about |
dotnet add package Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents --version 1.1.0
NuGet\Install-Package Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents -Version 1.1.0
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents" Version="1.1.0" />
<PackageVersion Include="Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents" Version="1.1.0" />Directory.Packages.props
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents" />Project file
paket add Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents --version 1.1.0
#r "nuget: Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents, 1.1.0"
#:package Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents@1.1.0
#addin nuget:?package=Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents&version=1.1.0Install as a Cake Addin
#tool nuget:?package=Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents&version=1.1.0Install as a Cake Tool
The authentication events trigger for Azure Functions allows you to implement a custom extension to handle Microsoft Entra authentication events. The authentication events trigger handles all the backend processing for incoming HTTP requests for Microsoft Entra authentication events and provides the developer with:
You can follow this article to start creating your function: Create a REST API for a token issuance start event in Azure Functions
Install the Authentication Event extension with NuGet:
dotnet add package Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents
There are three ways to set up authentication for your Azure Function:
WebJobsAuthenticationEventsTriggerAttributeBy default, the code has been set up for authentication in the Azure portal using environment variables. Use the tabs below to select your preferred method of implementing environment variables, or alternatively, refer to the built-in Azure App service authentication and authorization. For setting up environment variables, use the following values:
| Name | Value |
|---|---|
| AuthenticationEvents__AudienceAppId | Custom authentication extension app ID which is set up in Configure a custom claim provider for a token issuance event |
| AuthenticationEvents__AuthorityUrl | • Workforce tenant https://login.microsoftonline.com/<tenantID> <br> • External tenant https://<mydomain>.ciamlogin.com/<tenantID> |
| AuthenticationEvents__AuthorizedPartyAppId | 99045fe1-7639-4a75-9d4a-577b6ca3810f or another authorized party |
WebJobsAuthenticationEventsTriggerAttributeWebJobsAuthenticationEventsTriggerAttribute include the AuthorityUrl, AudienceAppId and AuthorizedPartyAppId properties, as shown in the below snippet.[FunctionName("onTokenIssuanceStart")]
public static WebJobsAuthenticationEventResponse Run(
[WebJobsAuthenticationEventsTriggerAttribute(
AudienceAppId = "<custom_authentication_extension_app_id>",
AuthorityUrl = "<authority_uri>",
AuthorizedPartyAppId = "<authorized_party_app_id>")] WebJobsTokenIssuanceStartRequest request, ILogger log)
Key concepts of the Azure .NET SDK can be found here.
Custom extensions allow you to handle Microsoft Entra authentication events, integrate with external systems, and customize what happens in your application authentication experience. For example, a custom claims provider is a custom extension that allows you to enrich or customize application tokens with information from external systems that can't be stored as part of the Microsoft Entra directory.
The authentication events trigger allows a function to be executed when an authentication event is sent from the Microsoft Entra event service.
The authentication events trigger output binding allows a function to send authentication event actions to the Microsoft Entra event service.
The first step is to create an HTTP trigger function API using your IDE, install the required NuGet packages and copy in the sample code (found below). You can build the project and run the function to extract the local function URL.
The function API is the source of extra claims for your token. For the purposes of this article, we're hardcoding the values for the sample app. In production, you can fetch information about the user from external data store.
In your trigger class (i.e: AuthEventsTrigger.cs), add the contents of the following snippet in your main function body:
[FunctionName("onTokenIssuanceStart")]
public static WebJobsAuthenticationEventResponse Run(
[WebJobsAuthenticationEventsTriggerAttribute(
AudienceAppId = "<custom_authentication_extension_app_id>",
AuthorityUrl = "<authority_uri>",
AuthorizedPartyAppId = "<authorized_party_app_id>")] WebJobsTokenIssuanceStartRequest request, ILogger log)
{
try
{
// Checks if the request is successful and did the token validation pass
if (request.RequestStatus == WebJobsAuthenticationEventsRequestStatusType.Successful)
{
// Fetches information about the user from external data store
// Add new claims to the token's response
request.Response.Actions.Add(
new WebJobsProvideClaimsForToken(
new WebJobsAuthenticationEventsTokenClaim("dateOfBirth", "01/01/2000"),
new WebJobsAuthenticationEventsTokenClaim("customRoles", "Writer", "Editor"),
new WebJobsAuthenticationEventsTokenClaim("apiVersion", "1.0.0"),
new WebJobsAuthenticationEventsTokenClaim(
"correlationId",
request.Data.AuthenticationContext.CorrelationId.ToString())));
}
else
{
// If the request fails, such as in token validation, output the failed request status,
// such as in token validation or response validation.
log.LogInformation(request.StatusMessage);
}
return request.Completed();
}
catch (Exception ex)
{
return request.Failed(ex);
}
}
It's a good idea to test the function locally before deploying it to Azure. We can use a dummy JSON body that imitates the request that Microsoft Entra ID sends to your REST API. Use your preferred API testing tool to call the function directly.
"AuthenticationEvents__BypassTokenValidation" to true for local testing purposes.{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "",
"AzureWebJobsSecretStorageType": "files",
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"AuthenticationEvents__BypassTokenValidation" : true
}
}
POST.{
"type": "microsoft.graph.authenticationEvent.tokenIssuanceStart",
"source": "/tenants/30000000-0000-0000-0000-000000000003/applications/40000000-0000-0000-0000-000000000002",
"data": {
"@odata.type": "microsoft.graph.onTokenIssuanceStartCalloutData",
"tenantId": "30000000-0000-0000-0000-000000000003",
"authenticationEventListenerId": "10000000-0000-0000-0000-000000000001",
"customAuthenticationExtensionId": "10000000-0000-0000-0000-000000000002",
"authenticationContext": {
"correlationId": "20000000-0000-0000-0000-000000000002",
"client": {
"ip": "127.0.0.1",
"locale": "en-us",
"market": "en-us"
},
"protocol": "OAUTH2.0",
"clientServicePrincipal": {
"id": "40000000-0000-0000-0000-000000000001",
"appId": "40000000-0000-0000-0000-000000000002",
"appDisplayName": "My Test application",
"displayName": "My Test application"
},
"resourceServicePrincipal": {
"id": "40000000-0000-0000-0000-000000000003",
"appId": "40000000-0000-0000-0000-000000000004",
"appDisplayName": "My Test application",
"displayName": "My Test application"
},
"user": {
"companyName": "Casey Jensen",
"createdDateTime": "2023-08-16T00:00:00Z",
"displayName": "Casey Jensen",
"givenName": "Casey",
"id": "60000000-0000-0000-0000-000000000006",
"mail": "casey@contoso.com",
"onPremisesSamAccountName": "Casey Jensen",
"onPremisesSecurityIdentifier": "<Enter Security Identifier>",
"onPremisesUserPrincipalName": "Casey Jensen",
"preferredLanguage": "en-us",
"surname": "Jensen",
"userPrincipalName": "casey@contoso.com",
"userType": "Member"
}
}
}
}
{
"data": {
"@odata.type": "microsoft.graph.onTokenIssuanceStartResponseData",
"actions": [
{
"@odata.type": "microsoft.graph.tokenIssuanceStart.provideClaimsForToken",
"claims": {
"customClaim1": "customClaimValue1",
"customClaim2": [
"customClaimString1",
"customClaimString2"
]
}
}
]
}
}
Once it has been tested and working, deploy the function to Azure.
Follow Configure a custom claim provider for a token issuance event to create a custom extension that will call your function.
For more information on Azure SDK, please refer to this website
Information about logging and metrics for the deployed function can be found here
For details on contributing to this repository, see the contributing guide.
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repositories using our CLA.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact with any additional questions or comments.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.1.0 | 5,249 | 7/30/2025 |
| 1.0.1 | 24,762 | 7/15/2024 |
| 1.0.0 | 2,539 | 5/22/2024 |
| 1.0.0-beta.8 | 1,788 | 5/2/2024 |
| 1.0.0-beta.7 | 234 | 4/22/2024 |
| 1.0.0-beta.6 | 445 | 3/27/2024 |
| 1.0.0-beta.5 | 478 | 12/8/2023 |
| 1.0.0-beta.4 | 244 | 11/14/2023 |
| 1.0.0-beta.3 | 645 | 2/17/2023 |
| 1.0.0-beta.2 | 390 | 11/8/2022 |
| 1.0.0-beta.1 | 429 | 9/14/2022 |