From de26719b0f7f5970a69dd244d7392a52e1a0a399 Mon Sep 17 00:00:00 2001 From: markalansee Date: Fri, 18 Jul 2014 16:16:08 +0100 Subject: [PATCH] Added "refresh_token" to AuthorizeResponse --- source/Core/Connect/Models/AuthorizeResponse.cs | 1 + .../ResponseHandling/AuthorizeResponseGenerator.cs | 13 ++++++++++++- .../Results/AuthorizeImplicitFormPostResult.cs | 7 ++++++- .../Results/AuthorizeImplicitFragmentResult.cs | 5 +++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/source/Core/Connect/Models/AuthorizeResponse.cs b/source/Core/Connect/Models/AuthorizeResponse.cs index b10f0d625..35fc01ae2 100644 --- a/source/Core/Connect/Models/AuthorizeResponse.cs +++ b/source/Core/Connect/Models/AuthorizeResponse.cs @@ -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; } diff --git a/source/Core/Connect/ResponseHandling/AuthorizeResponseGenerator.cs b/source/Core/Connect/ResponseHandling/AuthorizeResponseGenerator.cs index 5377efe56..a95c458ac 100644 --- a/source/Core/Connect/ResponseHandling/AuthorizeResponseGenerator.cs +++ b/source/Core/Connect/ResponseHandling/AuthorizeResponseGenerator.cs @@ -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; } @@ -53,6 +55,7 @@ public async Task CreateImplicitFlowResponseAsync(ValidatedAu { string accessTokenValue = null; int accessTokenLifetime = 0; + string refreshToken = null; if (request.IsResourceRequest) { @@ -60,6 +63,13 @@ public async Task CreateImplicitFlowResponseAsync(ValidatedAu 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; @@ -74,6 +84,7 @@ public async Task CreateImplicitFlowResponseAsync(ValidatedAu RedirectUri = request.RedirectUri, AccessToken = accessTokenValue, AccessTokenLifetime = accessTokenLifetime, + RefreshToken = refreshToken, IdentityToken = jwt, State = request.State, Scope = request.ValidatedScopes.GrantedScopes.ToSpaceSeparatedString() diff --git a/source/Core/Connect/Results/AuthorizeImplicitFormPostResult.cs b/source/Core/Connect/Results/AuthorizeImplicitFormPostResult.cs index cdff70383..f9782e0a9 100644 --- a/source/Core/Connect/Results/AuthorizeImplicitFormPostResult.cs +++ b/source/Core/Connect/Results/AuthorizeImplicitFormPostResult.cs @@ -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); diff --git a/source/Core/Connect/Results/AuthorizeImplicitFragmentResult.cs b/source/Core/Connect/Results/AuthorizeImplicitFragmentResult.cs index d2f72098a..4ec154ded 100644 --- a/source/Core/Connect/Results/AuthorizeImplicitFragmentResult.cs +++ b/source/Core/Connect/Results/AuthorizeImplicitFragmentResult.cs @@ -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);