/// <inheritdoc /> public SigningKeyValueProvider( HttpRequest request, TokenSigningKeyOptions options, FunctionTokenAttribute attribute) : this(request, options, attribute, new JwtSecurityTokenHandler()) { }
/// <inheritdoc /> public SingingKeyValueProvider( HttpRequest request, TokenSigningKeyOptions options, FunctionTokenAttribute attribute) : base(request, options, attribute) { this.options = options; }
public SigningKeyValueProvider( HttpRequest request, TokenSigningKeyOptions options, FunctionTokenAttribute attribute, ISecurityTokenValidator securityHandler) : base(request, options, attribute, securityHandler) { this.options = options; }
public void GetValueAsyncWorksForScope(string requiredScope, string[] authorizedRoles, List <Claim> claims, TokenStatus tokenStatus) { Mock <HttpRequest> request = new Mock <HttpRequest>(); request .SetupGet(r => r.Headers) .Returns(new HeaderDictionary { { "Authorization", "Bearer abc123" } }); request .SetupGet(r => r.HttpContext) .Returns(Mock.Of <HttpContext>()); TokenSigningKeyOptions options = new TokenSigningKeyOptions { SigningKey = JsonWebKey.Create( @"{ ""alg"": ""RS256"", ""kty"": ""RSA"", ""use"": ""sig"", ""n"": ""fasdklfjahsdfkaljsnddfnlkasudvgiuq3450897uzxcvnlksdfn---aserkfjasbvdkluy3t45r"", ""e"": ""AQAB"", ""kid"": ""NKJLGHLJKHGBVKBLKJAFUYKJHBFADF"", ""x5t"": ""NKJLGHLJKHGBVKBLKJAFUYKJHBFADF"", ""x5c"": [ ""hkjlgrhkljzvkzjhlgvzvdklhvzsilseujrgfoisyehfltw34to--=sdfghzksujfdhgi7tsertukjhask.fhcgfalsiyuegrht.jklw34batgfklyuasgdvkjsdrbg="" ] }" ), Issuer = "http://iamanissuerofauthtokens.com", Audience = "some audience", }; FunctionTokenAttribute attribute = new FunctionTokenAttribute( AuthLevel.Authorized, requiredScope, authorizedRoles ); SecurityToken mockSecurityToken = Mock.Of <SecurityToken>(); Mock <ISecurityTokenValidator> mockSecurityTokenValidator = new Mock <ISecurityTokenValidator>(); mockSecurityTokenValidator .Setup(v => v.ValidateToken( It.IsAny <string>(), It.IsAny <TokenValidationParameters>(), out mockSecurityToken ) ) .Returns( new ClaimsPrincipal( new List <ClaimsIdentity> { new ClaimsIdentity( claims, "Bearer" ) }) ); SigningKeyValueProvider provider = new SigningKeyValueProvider( request.Object, options, attribute, mockSecurityTokenValidator.Object ); ((FunctionTokenResult)(provider .GetValueAsync() .GetAwaiter() .GetResult())) .Status .Should() .Be(tokenStatus); }