public void SuccessfulResourceOwnerRefresh() { TokenClient client = null !; GrantedTokenResponse result = null !; "and a properly token client".x( () => client = new TokenClient( TokenCredentials.FromBasicAuthentication("clientCredentials", "clientCredentials"), _fixture.Client, new Uri(WellKnownOpenidConfiguration))); "when requesting auth token".x( async() => { var response = await client.GetToken(TokenRequest.FromScopes("api1", "offline")).ConfigureAwait(false) as Option <GrantedTokenResponse> .Result; Assert.NotNull(response); result = response.Item; }); "then can get new token from refresh token".x( async() => { var response = await client.GetToken(TokenRequest.FromRefreshToken(result.RefreshToken)) .ConfigureAwait(false) as Option <GrantedTokenResponse> .Result; Assert.NotNull(response); }); }
public void CanUpdateOwnClaimsAndRefresh() { HttpResponseMessage response = null !; "When updating user claims".x( async() => { var updateRequest = new UpdateResourceOwnerClaimsRequest { Subject = "administrator", Claims = new[] { new ClaimData { Type = "added_claim_test", Value = "something" } } }; var json = JsonConvert.SerializeObject(updateRequest); var request = new HttpRequestMessage { Content = new StringContent(json, Encoding.UTF8, "application/json"), Method = HttpMethod.Post, RequestUri = new Uri(_fixture.Server.BaseAddress + "resource_owners/claims") }; request.Headers.Authorization = new AuthenticationHeaderValue( "Bearer", _administratorToken.AccessToken); response = await _fixture.Client().SendAsync(request).ConfigureAwait(false); }); "Then is ok request".x(() => { Assert.Equal(HttpStatusCode.OK, response.StatusCode); }); "and has new token".x( async() => { var updatedToken = await response.Content.ReadAsStringAsync().ConfigureAwait(false); Assert.NotNull(updatedToken); }); "When refreshing token, then has updated claims".x( async() => { var result = await _tokenClient .GetToken(TokenRequest.FromRefreshToken(_administratorToken.RefreshToken)) .ConfigureAwait(false) as Option <GrantedTokenResponse> .Result; Assert.NotNull(result.Item); var handler = new JwtSecurityTokenHandler(); var token = handler.ReadToken(result.Item.AccessToken) as JwtSecurityToken; Assert.Contains(token.Claims, c => c.Type == "added_claim_test" && c.Value == "something"); }); }
public void SuccessfulResourceOwnerRefresh() { TokenClient client = null !; GrantedTokenResponse result = null !; GrantedTokenResponse refreshed = null !; "and a properly token client".x( () => client = new TokenClient( TokenCredentials.FromBasicAuthentication("client", "client"), _fixture.Client, new Uri(WellKnownOpenidConfiguration))); "when requesting auth token".x( async() => { var response = await client .GetToken(TokenRequest.FromPassword("user", "password", new[] { "openid", "offline" })) .ConfigureAwait(false) as Option <GrantedTokenResponse> .Result; result = response.Item; }); "then can get new token from refresh token".x( async() => { var response = await client.GetToken(TokenRequest.FromRefreshToken(result.RefreshToken)) .ConfigureAwait(false) as Option <GrantedTokenResponse> .Result; Assert.NotNull(response); refreshed = response.Item; }); "and token has custom custom claims".x( () => { var handler = new JwtSecurityTokenHandler(); var refreshedClaims = handler.ReadJwtToken(refreshed.AccessToken).Claims; Assert.Contains(refreshedClaims, c => c.Type == "acceptance_test"); }); }