Skip to content
This repository has been archived by the owner on Jul 31, 2024. It is now read-only.

Commit

Permalink
closes #781
Browse files Browse the repository at this point in the history
  • Loading branch information
leastprivilege committed Feb 15, 2017
1 parent d8ba99c commit 91cc7ee
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 11 deletions.
26 changes: 16 additions & 10 deletions src/IdentityServer4/ResponseHandling/TokenResponseGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,18 +225,24 @@ private async Task<Tuple<string, string>> CreateAccessTokenAsync(ValidatedTokenR

private async Task<string> CreateIdTokenFromRefreshTokenRequestAsync(ValidatedTokenRequest request, string newAccessToken)
{
var oldAccessToken = request.RefreshToken.AccessToken;
var tokenRequest = new TokenCreationRequest
var resources = await _resources.FindResourcesByScopeAsync(request.RefreshToken.Scopes);
if (resources.IdentityResources.Any())
{
Subject = request.RefreshToken.Subject,
Client = request.Client,
Resources = await _resources.FindEnabledResourcesByScopeAsync(oldAccessToken.Scopes),
ValidatedRequest = request,
AccessTokenToHash = newAccessToken
};
var oldAccessToken = request.RefreshToken.AccessToken;
var tokenRequest = new TokenCreationRequest
{
Subject = request.RefreshToken.Subject,
Client = request.Client,
Resources = await _resources.FindEnabledResourcesByScopeAsync(oldAccessToken.Scopes),
ValidatedRequest = request,
AccessTokenToHash = newAccessToken
};

var idToken = await _tokenService.CreateIdentityTokenAsync(tokenRequest);
return await _tokenService.CreateSecurityTokenAsync(idToken);
}

var idToken = await _tokenService.CreateIdentityTokenAsync(tokenRequest);
return await _tokenService.CreateSecurityTokenAsync(idToken);
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public RefreshTokenClient()
}

[Fact]
public async Task requesting_a_refresh_token_should_return_expected_results()
public async Task requesting_a_refresh_token_without_identity_scopes_should_return_expected_results()
{
var client = new TokenClient(
TokenEndpoint,
Expand All @@ -48,6 +48,32 @@ public async Task requesting_a_refresh_token_should_return_expected_results()

response = await client.RequestRefreshTokenAsync(response.RefreshToken);

response.IsError.Should().BeFalse();
response.ExpiresIn.Should().Be(3600);
response.TokenType.Should().Be("Bearer");
response.IdentityToken.Should().BeNull();
response.RefreshToken.Should().NotBeNull();
}

[Fact]
public async Task requesting_a_refresh_token_with_identity_scopes_should_return_expected_results()
{
var client = new TokenClient(
TokenEndpoint,
"roclient",
"secret",
innerHttpMessageHandler: _handler);

var response = await client.RequestResourceOwnerPasswordAsync("bob", "bob", "openid api1 offline_access");

response.IsError.Should().BeFalse();
response.ExpiresIn.Should().Be(3600);
response.TokenType.Should().Be("Bearer");
response.IdentityToken.Should().BeNull();
response.RefreshToken.Should().NotBeNull();

response = await client.RequestRefreshTokenAsync(response.RefreshToken);

response.IsError.Should().BeFalse();
response.ExpiresIn.Should().Be(3600);
response.TokenType.Should().Be("Bearer");
Expand Down

0 comments on commit 91cc7ee

Please sign in to comment.