Skip to content
This repository has been archived by the owner on Sep 18, 2021. It is now read-only.

Added "refresh_token" to AuthorizeResponse #230

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions source/Core/Connect/Models/AuthorizeResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class AuthorizeResponse
public string IdentityToken { get; set; }
public string AccessToken { get; set; }
public int AccessTokenLifetime { get; set; }
public string RefreshToken { get; set; }
public string Code { get; set; }
public string State { get; set; }
public string Scope { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ namespace Thinktecture.IdentityServer.Core.Connect
public class AuthorizeResponseGenerator
{
private readonly ITokenService _tokenService;
private readonly IRefreshTokenService _refreshTokenService;
private readonly IAuthorizationCodeStore _authorizationCodes;

public AuthorizeResponseGenerator(ITokenService tokenService, IAuthorizationCodeStore authorizationCodes)
public AuthorizeResponseGenerator(ITokenService tokenService, IRefreshTokenService refreshTokenService, IAuthorizationCodeStore authorizationCodes)
{
_tokenService = tokenService;
_refreshTokenService = refreshTokenService;
_authorizationCodes = authorizationCodes;
}

Expand Down Expand Up @@ -53,13 +55,21 @@ public async Task<AuthorizeResponse> CreateImplicitFlowResponseAsync(ValidatedAu
{
string accessTokenValue = null;
int accessTokenLifetime = 0;
string refreshToken = null;

if (request.IsResourceRequest)
{
var accessToken = await _tokenService.CreateAccessTokenAsync(request.Subject, request.Client, request.ValidatedScopes.GrantedScopes, request.Raw);
accessTokenLifetime = accessToken.Lifetime;

accessTokenValue = await _tokenService.CreateSecurityTokenAsync(accessToken);

var createRefreshToken = request.ValidatedScopes.ContainsOfflineAccessScope;

if (createRefreshToken)
{
refreshToken = await _refreshTokenService.CreateRefreshTokenAsync(accessToken, request.Client);
}
}

string jwt = null;
Expand All @@ -74,6 +84,7 @@ public async Task<AuthorizeResponse> CreateImplicitFlowResponseAsync(ValidatedAu
RedirectUri = request.RedirectUri,
AccessToken = accessTokenValue,
AccessTokenLifetime = accessTokenLifetime,
RefreshToken = refreshToken,
IdentityToken = jwt,
State = request.State,
Scope = request.ValidatedScopes.GrantedScopes.ToSpaceSeparatedString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ private HttpResponseMessage Execute()
sb.AppendFormat(inputFieldFormat, "token", _response.AccessToken);
sb.AppendFormat(inputFieldFormat, "expires_in", _response.AccessTokenLifetime);
}


if (_response.RefreshToken.IsPresent())
{
sb.AppendFormat(inputFieldFormat, "refresh_token", _response.RefreshToken);
}

if (_response.State.IsPresent())
{
sb.AppendFormat(inputFieldFormat, "state", _response.State);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ private HttpResponseMessage Execute()
query.Add("expires_in", _response.AccessTokenLifetime.ToString());
}

if (_response.RefreshToken.IsPresent())
{
query.Add("refresh_token", _response.RefreshToken);
}

if (_response.Scope.IsPresent())
{
query.Add("scope", _response.Scope);
Expand Down