0

I was able to obtain a JWT token successfully using MSAL pattern from Graph API per the following code snippet below in C#:

app = ConfidentialClientApplicationBuilder.Create(_authenticationSettings.ClientId)
                    .WithClientSecret(_authenticationSettings.ClientSecret)
                    .WithAuthority(new Uri(_authenticationSettings.Authority))
                    .Build();
var result = await app.AcquireTokenForClient(scopes).ExecuteAsync();
return result.AccessToken; 

I am also able to include this token in POST or GET requests' headers as a "Bearer" token to submit to an HTTP-triggered function. How can I validate this token in the function side to ensure it's authentic? All examples online are covering asp.net core applications and I could not find anything relevant to functions.

1 Answer 1

2

Here you can find a tutorial how to validate Graph API token in Azure Functions.

JwtSecurityTokenHandler class is used for validating JWT.

Sign up to request clarification or add additional context in comments.

3 Comments

This is the error that I am getting which I could not find a solution for that!! Could not load file or assembly 'Microsoft.IdentityModel.Protocols.OpenIdConnect, Version=6.7.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
@Arash Maybe similar issue: github.com/Azure/azure-functions-vs-build-sdk/issues/397 Accroding the thread the workaround can be adding <_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput> in .csproj
Yes, I got this issue fixed and now got the error message below which I have no idea why! IDX10511: Signature validation failed. Keys tried: 'System.Text.StringBuilder'. kid: 'System.String'. Exceptions caught: 'System.Text.StringBuilder'. token: 'System.IdentityModel.Tokens.Jwt.JwtSecurityToken'.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.