%3CLINGO-SUB%20id%3D%22lingo-sub-1163098%22%20slang%3D%22en-US%22%3EGenerating%20Azure%20AD%20%22Look-Alike%22%20Tokens%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1163098%22%20slang%3D%22en-US%22%3E%3CP%3EJSON%20Web%20Tokens%20(JWTs)%2C%20colloquially%20known%20as%20%22jots%22%2C%20are%20the%20best%20thing%20since%20sliced%20bread%20in%20the%20identity%20developer%20space.%20Well%2C%20maybe%20that's%20stretching%20it%20a%20bit%20far%2C%20but%20they%20are%20fairly%20simple%20to%20work%20with%20when%20it%20comes%20to%20deserializing%2C%20passing%20around%2C%20and%20general%20dev%20friendliness%20compared%20to%20legacy%20formats.%20For%20cloud%20developers%20it's%20extra%20useful%20because%20it%20does%20not%20rely%20on%20things%20like%20being%20on%20the%20same%20corporate%20network%20as%20classic%20Active%20Directory%20Kerberos%20tickets%20prefer.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20you%20run%20code%20on%20Azure%20there's%20really%20no%20way%20avoiding%20them.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20first%20part%20of%20working%20with%20JWTs%20is%20acquiring%20the%20token.%20This%20usually%20involves%20an%20authentication%20%22dance%22%20where%20you%20need%20to%20interact%20with%20an%20identity%20provider%20either%20interactively%20or%20programmatically.%20This%20blog%20being%20themed%20around%20Microsoft%20means%20that%20provider%20will%20frequently%20be%20Azure%20AD%2C%20Azure%20AD%20B2C%2C%20or%20ADFS%20for%20that%20matter.%20It's%20all%20standards%20though%2C%20so%20if%20you%20rely%20on%20Google%20or%20Facebook%20instead%20it%20will%20be%20similar.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhen%20developing%20code%20relying%20on%20identities%20it%20can%20be%20a%20hassle%20setting%20up%20demo%20accounts%20and%20all%2C%20and%20even%20if%20we%20assume%20there%20are%20no%20problems%20in%20doing%20so%20it%20can%20be%20annoying%20typing%20in%20passwords%20and%20stepping%20through%20debuggers%20to%20retrieve%20the%20token%20when%20all%20you%20want%20is%20a%20%22simple%20test%20token%22.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWouldn't%20it%20be%20easier%20just%20generating%20your%20own%20tokens%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EA%20quick%20search%20might%20lead%20you%20to%20%3CA%20href%3D%22http%3A%2F%2Fjwtbuilder.jamiekurtz.com%2F%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3Ehttp%3A%2F%2Fjwtbuilder.jamiekurtz.com%2F%3C%2FA%3E%2C%20and%20that%20is%20a%20good%20site%20for%20that%20purpose.%20The%20code%20is%20on%20GitHub%20as%20well%20so%20no%20complaints%20on%20my%20part%20there.%20Well%2C%20apart%20from%20the%20fact%20that%20it's%20done%20with%20NodeJS%20and%20things%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESince%20I%20wanted%20to%20play%20around%20with%20Blazor%20(for%20reasons%20not%20pertaining%20to%20identity%20at%20all)%20I%20wanted%20to%20do%20a%20C%23-based%20version.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhile%20researching%20some%20B2C%20features%20I%20found%20some%20inspiration%20in%20the%20B2C%20samples%20repo%20as%20well%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fazure-ad-b2c%2Fsamples%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3Ehttps%3A%2F%2Fgithub.com%2Fazure-ad-b2c%2Fsamples%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20UI%20should%20be%20fairly%20self-explanatory%3A%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBehind%20the%20scenes%20a%20certificate%20is%20used%20for%20signing%20the%20token%2C%20so%20in%20case%20you%20want%20to%20mock%20the%20validation%20in%20an%20API%20(which%20is%20part%20of%20the%20purpose%20for%20this%20tool)%20the%20necessary%20OpenID%20Connect%20metadata%20endpoints%20are%20exposed%20as%20well%3A%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ffqdn%2F.well-known%2Fopenid-configuration%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3Ehttps%3A%2F%2Ffqdn%2F.well-known%2Fopenid-configuration%3C%2FA%3E%20and%20a%20corresponding%20JWKS%20endpoint%20at%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ffqdn%2F.well-known%2Fkeys%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3Ehttps%3A%2F%2Ffqdn%2F.well-known%2Fkeys%3C%2FA%3E.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECode%20can%20be%20found%20at%3A%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fahelland%2FIdentity-CodeSamples-v2%2Ftree%2Fmaster%2Fblazor-jwt_generator-dotnet-core%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3Ehttps%3A%2F%2Fgithub.com%2Fahelland%2FIdentity-CodeSamples-v2%2Ftree%2Fmaster%2Fblazor-jwt_generator-dotnet-core%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMost%20of%20the%20code%20is%20%22fluff%22%20in%20the%20sense%20that%20it's%20mostly%20about%20setting%20up%20the%20UI%2C%20and%20related%20tasks.%20The%20piece%20you%20should%20be%20most%20interested%20in%20is%20the%20following%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3Epublic%20static%20string%20BuildIdToken(string%20Subject)%20%7B%20string%20issuer%20%3D%20jwt.Issuer%3B%20string%20audience%20%3D%20jwt.Audience%3B%20IList%3CSYSTEM.SECURITY.CLAIMS.CLAIM%3E%20claims%20%3D%20new%20List%3CSYSTEM.SECURITY.CLAIMS.CLAIM%3E()%3B%20claims.Add(new%20System.Security.Claims.Claim(%22ver%22%2C%20jwt.Version%2C%20System.Security.Claims.ClaimValueTypes.String%2C%20issuer))%3B%20claims.Add(new%20System.Security.Claims.Claim(%22sub%22%2C%20Subject%2C%20System.Security.Claims.ClaimValueTypes.String%2C%20issuer))%3B%20claims.Add(new%20System.Security.Claims.Claim(%22iat%22%2C%20jwt.iat%2C%20System.Security.Claims.ClaimValueTypes.String%2C%20issuer))%3B%20claims.Add(new%20System.Security.Claims.Claim(%22name%22%2C%20jwt.name%2C%20System.Security.Claims.ClaimValueTypes.String%2C%20issuer))%3B%20claims.Add(new%20System.Security.Claims.Claim(%22preferred_username%22%2C%20jwt.preferred_username%2C%20System.Security.Claims.ClaimValueTypes.String%2C%20issuer))%3B%20claims.Add(new%20System.Security.Claims.Claim(%22oid%22%2C%20jwt.oid%2C%20System.Security.Claims.ClaimValueTypes.String%2C%20issuer))%3B%20claims.Add(new%20System.Security.Claims.Claim(%22tid%22%2C%20jwt.tid%2C%20System.Security.Claims.ClaimValueTypes.String%2C%20issuer))%3B%20claims.Add(new%20System.Security.Claims.Claim(%22nonce%22%2C%20jwt.nonce%2C%20System.Security.Claims.ClaimValueTypes.String%2C%20issuer))%3B%20claims.Add(new%20System.Security.Claims.Claim(%22aio%22%2C%20jwt.aio%2C%20System.Security.Claims.ClaimValueTypes.String%2C%20issuer))%3B%20%2F%2F%20Create%20the%20token%20JwtSecurityToken%20token%20%3D%20new%20JwtSecurityToken(%20issuer%2C%20audience%2C%20claims%2C%20DateTime.Parse(jwt.IssuedAt)%2C%20DateTime.Parse(jwt.Expiration)%2C%20SigningCredentials.Value)%3B%20%2F%2FAAD%20v2%20tokens%20doesn't%20use%20the%20x5t%20claim%20token.Header.Remove(%22x5t%22)%3B%20%2F%2FAAD%20doesn't%20use%20kid%2Fthumbprint%2C%20but%20the%20hash%20so%20a%20%22hack%22%20is%20required%20token.Header.Remove(%22kid%22)%3B%20token.Header.Add(%22kid%22%2C%20SigningCertHash)%3B%20%2F%2F%20Get%20the%20representation%20of%20the%20signed%20token%20JwtSecurityTokenHandler%20jwtHandler%20%3D%20new%20JwtSecurityTokenHandler()%3B%20return%20jwtHandler.WriteToken(token)%3B%20%7D%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAnd%20there's%20a%20Docker-image%20(Linux)%20at%3A%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fhub.docker.com%2Fr%2Fahelland%2Fblazor-jwt_generator-dotnet-core-linux%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3Ehttps%3A%2F%2Fhub.docker.com%2Fr%2Fahelland%2Fblazor-jwt_generator-dotnet-core-linux%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI've%20tested%20running%20it%20as%20a%20container%20on%20Azure%20App%20Service%20-%20more%20info%20on%20how%20to%20do%20that%20here%3A%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fcontos.io%2Fplaying-with-container-in-azure-app-service-bd397be2bb4c%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3Ehttps%3A%2F%2Fcontos.io%2Fplaying-with-container-in-azure-app-service-bd397be2bb4c%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20app%20runs%20on%20both%20Windows%20and%20Linux%20(and%20Docker-based%20variants%20of%20these)%2C%20but%20since%20certificate%20handling%20is%20different%20between%20the%20two%20platforms%20the%20code%20branches%20based%20on%20setting%20the%20HostEnvironment%26nbsp%3Bvariable%20to%20%22Windows%22%20or%20%22Linux%22.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWindows%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20Windows%20it%20is%20assumed%20that%20the%20certificate%20is%20stored%20in%20the%20current%20user's%20certificate%20store.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETo%20generate%20(and%20store)%20a%20certificate%20use%20the%20following%20PowerShell%20commands%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%24cert%20%3D%20New-SelfSignedCertificate%20-Type%20Custom%20-Subject%20%22CN%3DMySelfSignedCertificate%22%20-TextExtension%20%40(%222.5.29.37%3D%7Btext%7D1.3.6.1.5.5.7.3.3%22)%20-KeyUsage%20DigitalSignature%20-KeyAlgorithm%20RSA%20-KeyLength%202048%20-NotAfter%20(Get-Date).AddYears(2)%20-CertStoreLocation%20%22Cert%3A%5CCurrentUser%5CMy%22%20%24cert.Thumbprint%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ELinux%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20Linux%20it%20is%20assumed%20that%20the%20certificate%20is%20stored%20in%20%2Fvar%2Fssl%2Fprivate%2F%7BSigningCertThumbprint%7D.p12%26nbsp%3B%3C%2FP%3E%3CP%3ETechnically%20it%20can%20be%20stored%20in%20any%20path%20you%20like%2C%20but%20this%20ensures%20compatibility%20with%20deploying%20to%20Azure%20App%20Service%20and%20having%20the%20certificate%20stored%20in%20Azure%20Key%20Vault.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETo%20generate%20a%20compatible%20certificate%20and%20retrieve%20the%20thumbprint%20run%20the%20following%20(tested%20on%20Ubuntu%2018.04%20on%20WSL)%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3Eopenssl%20req%20-x509%20-newkey%20rsa%3A4096%20-keyout%20myKey.pem%20-out%20cert.pem%20-days%20365%20-nodes%20openssl%20pkcs12%20-export%20-out%20keyStore.p12%20-inkey%20myKey.pem%20-in%20cert.pem%20openssl%20x509%20-in%20cert.pem%20-noout%20-fingerprint%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20both%20operating%20systems%20set%20the%20thumbprint%20in%20the%20SigningCertThumbprint%26nbsp%3Bsetting%20in%20appsettings.json.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESure%2C%20not%20the%20most%20impressive%20code%20you've%20ever%20seen%2C%20but%20it%20serves%20its%20purpose%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20app%20has%20templates%20for%20Azure%20AD%20and%20Azure%20AD%20B2C%20tokens%20in%20addition%20to%20a%20generic%20token%20not%20specific%20to%20any%20identity%20provider.%20If%20you%20test%20the%20tokens%20at%20%3CA%20href%3D%22https%3A%2F%2Fjwt.ms%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3Ehttps%3A%2F%2Fjwt.ms%3C%2FA%3E%20they%20will%20be%20interpreted%20as%20intended%20-%20the%20AAD-templates%20will%20generate%20tokens%20identified%20as%20being%20sourced%20from%20Azure%20AD.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20clearly%20demonstrates%20why%20you%20should%20validate%20tokens%20issued%20by%20Azure%20properly%2C%20but%20token%20validation%20would%20be%20a%20topic%20for%20a%20different%20post%20at%20another%20time%3C%2FP%3E%3C%2FSYSTEM.SECURITY.CLAIMS.CLAIM%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-1163098%22%20slang%3D%22en-US%22%3E%3CP%3EDon't%20you%20find%20it%20annoying%20having%20to%20actually%20sign%20in%20to%20Azure%20AD%20and%20capture%20the%20token%20when%20you%20are%20debugging%20your%20code%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThere's%20a%20utility%20for%20that%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1163098%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3C%2FSYSTEM.SECURITY.CLAIMS.CLAIM%3E%3C%2FLINGO-BODY%3E
Senior Member

JSON Web Tokens (JWTs), colloquially known as "jots", are the best thing since sliced bread in the identity developer space. Well, maybe that's stretching it a bit far, but they are fairly simple to work with when it comes to deserializing, passing around, and general dev friendliness compared to legacy formats. For cloud developers it's extra useful because it does not rely on things like being on the same corporate network as classic Active Directory Kerberos tickets prefer.

 

If you run code on Azure there's really no way avoiding them.

 

The first part of working with JWTs is acquiring the token. This usually involves an authentication "dance" where you need to interact with an identity provider either interactively or programmatically. This blog being themed around Microsoft means that provider will frequently be Azure AD, Azure AD B2C, or ADFS for that matter. It's all standards though, so if you rely on Google or Facebook instead it will be similar.

 

When developing code relying on identities it can be a hassle setting up demo accounts and all, and even if we assume there are no problems in doing so it can be annoying typing in passwords and stepping through debuggers to retrieve the token when all you want is a "simple test token".

 

Wouldn't it be easier just generating your own tokens?

 

A quick search might lead you to http://jwtbuilder.jamiekurtz.com/, and that is a good site for that purpose. The code is on GitHub as well so no complaints on my part there. Well, apart from the fact that it's done with NodeJS and things :)

 

Since I wanted to play around with Blazor (for reasons not pertaining to identity at all) I wanted to do a C#-based version.

 

While researching some B2C features I found some inspiration in the B2C samples repo as well

https://github.com/azure-ad-b2c/samples

 

The UI should be fairly self-explanatory:

jwt_generator.png

 

Behind the scenes a certificate is used for signing the token, so in case you want to mock the validation in an API (which is part of the purpose for this tool) the necessary OpenID Connect metadata endpoints are exposed as well:

https://fqdn/.well-known/openid-configuration and a corresponding JWKS endpoint at

https://fqdn/.well-known/keys.

 

Code can be found at:

https://github.com/ahelland/Identity-CodeSamples-v2/tree/master/blazor-jwt_generator-dotnet-core

 

Most of the code is "fluff" in the sense that it's mostly about setting up the UI, and related tasks. The piece you should be most interested in is the following:

 

 

 

public static string BuildIdToken(string Subject)
{
    string issuer = jwt.Issuer;
    string audience = jwt.Audience;

    IList<System.Security.Claims.Claim> claims = new List<System.Security.Claims.Claim>();
    claims.Add(new System.Security.Claims.Claim("ver", jwt.Version, System.Security.Claims.ClaimValueTypes.String, issuer));
    claims.Add(new System.Security.Claims.Claim("sub", Subject, System.Security.Claims.ClaimValueTypes.String, issuer));            
    claims.Add(new System.Security.Claims.Claim("iat", jwt.iat, System.Security.Claims.ClaimValueTypes.String, issuer));
    claims.Add(new System.Security.Claims.Claim("name", jwt.name, System.Security.Claims.ClaimValueTypes.String, issuer));
    claims.Add(new System.Security.Claims.Claim("preferred_username", jwt.preferred_username, System.Security.Claims.ClaimValueTypes.String, issuer));            
    claims.Add(new System.Security.Claims.Claim("oid", jwt.oid, System.Security.Claims.ClaimValueTypes.String, issuer));
    claims.Add(new System.Security.Claims.Claim("tid", jwt.tid, System.Security.Claims.ClaimValueTypes.String, issuer));
    claims.Add(new System.Security.Claims.Claim("nonce", jwt.nonce, System.Security.Claims.ClaimValueTypes.String, issuer));
    claims.Add(new System.Security.Claims.Claim("aio", jwt.aio, System.Security.Claims.ClaimValueTypes.String, issuer));

    // Create the token
    JwtSecurityToken token = new JwtSecurityToken(
            issuer,
            audience,
            claims,
            DateTime.Parse(jwt.IssuedAt),                    
            DateTime.Parse(jwt.Expiration),
            SigningCredentials.Value);

    
    //AAD v2 tokens doesn't use the x5t claim
    token.Header.Remove("x5t");

    //AAD doesn't use kid/thumbprint, but the hash so a "hack" is required
    token.Header.Remove("kid");
    token.Header.Add("kid", SigningCertHash);

    // Get the representation of the signed token
    JwtSecurityTokenHandler jwtHandler = new JwtSecurityTokenHandler();

    return jwtHandler.WriteToken(token);
}

 

 

 

 

And there's a Docker-image (Linux) at:

https://hub.docker.com/r/ahelland/blazor-jwt_generator-dotnet-core-linux

 

I've tested running it as a container on Azure App Service - more info on how to do that here:

https://contos.io/playing-with-container-in-azure-app-service-bd397be2bb4c

 

The app runs on both Windows and Linux (and Docker-based variants of these), but since certificate handling is different between the two platforms the code branches based on setting the HostEnvironment variable to "Windows" or "Linux".

 

Windows 

For Windows it is assumed that the certificate is stored in the current user's certificate store.

 

To generate (and store) a certificate use the following PowerShell commands:

 

 

 

$cert = New-SelfSignedCertificate -Type Custom -Subject "CN=MySelfSignedCertificate" -TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.3") -KeyUsage DigitalSignature -KeyAlgorithm RSA -KeyLength 2048 -NotAfter (Get-Date).AddYears(2) -CertStoreLocation "Cert:\CurrentUser\My" 

$cert.Thumbprint

 

 

 

 

Linux 

For Linux it is assumed that the certificate is stored in /var/ssl/private/{SigningCertThumbprint}.p12 

Technically it can be stored in any path you like, but this ensures compatibility with deploying to Azure App Service and having the certificate stored in Azure Key Vault.

 

To generate a compatible certificate and retrieve the thumbprint run the following (tested on Ubuntu 18.04 on WSL):

 

 

 

openssl req -x509 -newkey rsa:4096 -keyout myKey.pem -out cert.pem -days 365 -nodes

openssl pkcs12 -export -out keyStore.p12 -inkey myKey.pem -in cert.pem

openssl x509 -in cert.pem -noout -fingerprint

 

 

 

 

For both operating systems set the thumbprint in the SigningCertThumbprint setting in appsettings.json.

 

Sure, not the most impressive code you've ever seen, but it serves its purpose :)

 

The app has templates for Azure AD and Azure AD B2C tokens in addition to a generic token not specific to any identity provider. If you test the tokens at https://jwt.ms they will be interpreted as intended - the AAD-templates will generate tokens identified as being sourced from Azure AD.

 

This clearly demonstrates why you should validate tokens issued by Azure properly, but token validation would be a topic for a different post at another time :)