11using System ;
2+ using System . IO ;
3+ using Micro . AppRegistration . Api . Auth ;
24using Microsoft . AspNetCore . Authentication . JwtBearer ;
3- using Microsoft . AspNetCore . Identity ;
45using Microsoft . Extensions . Configuration ;
56using Microsoft . Extensions . DependencyInjection ;
67using Microsoft . IdentityModel . Tokens ;
8+ using PemUtils ;
79
810namespace Micro . AppRegistration . Api . StartupExtensions
911{
@@ -36,12 +38,16 @@ private static void ConfigureJwtBearer(IServiceCollection services, JwtBearerOpt
3638 ClockSkew = TimeSpan . Zero ,
3739 IssuerSigningKeyResolver = ( token , secToken , kid , parameters ) =>
3840 {
39- // todo: first get keystore to generate a sdk and publish to nuget automatically
40- // add that package as a dependency
41- // and finally copy logic from micro.auth
42- throw new NotImplementedException ( ) ;
43- }
41+ // todo: I know this .Result is a very bad idea (converting from async to sync)
42+ // however there's no other way to do this, signing key resolver doesn't have a
43+ // async version of this method, they are looking into it though
44+ // https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/issues/468
45+ var key = services . BuildServiceProvider ( ) . GetRequiredService < IKeyResolver > ( )
46+ . ResolveKey ( kid ) . Result ;
47+ var pemReader = new PemReader ( new MemoryStream ( System . Text . Encoding . UTF8 . GetBytes ( key ) ) ) ;
48+ var publicKeyParameters = pemReader . ReadRsaKey ( ) ;
49+ return new [ ] { new RsaSecurityKey ( publicKeyParameters ) } ; }
4450 } ;
4551 }
4652 }
47- }
53+ }
0 commit comments