public async Task TestAccessTokenProvider_TokenIsValid() { using (var httpClient = new HttpClient()) { IAccessTokenProvider provider = TestAccessTokenProviderFactory.Create(httpClient, DEV_AUTH_URL); IAccessToken token = await provider.ProvisionAccessTokenAsync(testClaimSet, testScopes).ConfigureAwait(false); IAccessTokenValidator validator = AccessTokenValidatorFactory.CreateRemoteValidator(httpClient, new Uri(DEV_AUTH_JWKS_URL), new Uri(DEV_AUTH_JWK_URL)); Assert.DoesNotThrowAsync(async() => await validator.ValidateAsync(token.Token).ConfigureAwait(false)); } }
public async void TestAccessTokenProvider_SuppliedRSAParameters_TokenIsValid() { using (var httpClient = new HttpClient()) { IAccessTokenProvider provider = TestAccessTokenProviderFactory.Create(httpClient, DEV_AUTH_URL, TestStaticKeyProvider.TestKeyId, TestStaticKeyProvider.TestRSAParameters); IAccessToken token = await provider.ProvisionAccessTokenAsync(testClaimSet, testScopes).SafeAsync(); IAccessTokenValidator validator = AccessTokenValidatorFactory.CreateRemoteValidator(httpClient, new Uri(DEV_AUTH_URL)); Assert.DoesNotThrow(async() => await validator.ValidateAsync(token.Token).SafeAsync()); } }
/// <summary> /// Convienence method to get an auth token string. /// </summary> /// <param name="tokenProvisioningEndpoint">The auth server.</param> /// <param name="claimSet">The set of claims to be included in the token. Do not include an issuer.</param> /// <param name="scopes">The set of scopes to be included in the token.</param> /// <returns>An auth token string.</returns> public static async Task <string> GetToken(string tokenProvisioningEndpoint, IEnumerable <Claim> claimSet, IEnumerable <Scope> scopes) { IList <Claim> claims = claimSet.ToList(); if (claims.HasClaim(Constants.Claims.ISSUER)) { throw new ArgumentException("The claimSet should not have an issuer"); } claims.Add(new Claim(Constants.Claims.ISSUER, DEFAULT_ISSUER)); using (var httpClient = new HttpClient()) { IAccessTokenProvider provider = TestAccessTokenProviderFactory.Create(httpClient, tokenProvisioningEndpoint); IAccessToken token = await provider.ProvisionAccessTokenAsync(claims, scopes).SafeAsync(); return(token.Token); } }