diff --git a/src/IdentityServer/ResponseHandling/Default/TokenResponseGenerator.cs b/src/IdentityServer/ResponseHandling/Default/TokenResponseGenerator.cs index 5571b5a06..f27a8232b 100644 --- a/src/IdentityServer/ResponseHandling/Default/TokenResponseGenerator.cs +++ b/src/IdentityServer/ResponseHandling/Default/TokenResponseGenerator.cs @@ -143,30 +143,8 @@ protected virtual async Task ProcessAuthorizationCodeRequestAsync { Logger.LogTrace("Creating response for authorization code request"); - ////////////////////////// - // access token - ///////////////////////// - var (accessToken, refreshToken) = await CreateAccessTokenAsync(request.ValidatedRequest); - var response = new TokenResponse - { - AccessToken = accessToken, - AccessTokenType = request.ValidatedRequest.ProofType == ProofType.DPoP ? OidcConstants.TokenResponse.DPoPTokenType : OidcConstants.TokenResponse.BearerTokenType, - AccessTokenLifetime = request.ValidatedRequest.AccessTokenLifetime, - Custom = request.CustomResponse, - Scope = request.ValidatedRequest.ValidatedResources.RawScopeValues.ToSpaceSeparatedString() - }; - - ////////////////////////// - // refresh token - ///////////////////////// - if (refreshToken.IsPresent()) - { - response.RefreshToken = refreshToken; - } + var response = await ProcessTokenRequestAsync(request); - ////////////////////////// - // id token - ///////////////////////// if (request.ValidatedRequest.AuthorizationCode.IsOpenId) { // load the client that belongs to the authorization code @@ -267,30 +245,8 @@ protected virtual async Task ProcessDeviceCodeRequestAsync(TokenR { Logger.LogTrace("Creating response for device code request"); - ////////////////////////// - // access token - ///////////////////////// - var (accessToken, refreshToken) = await CreateAccessTokenAsync(request.ValidatedRequest); - var response = new TokenResponse - { - AccessToken = accessToken, - AccessTokenType = request.ValidatedRequest.ProofType == ProofType.DPoP ? OidcConstants.TokenResponse.DPoPTokenType : OidcConstants.TokenResponse.BearerTokenType, - AccessTokenLifetime = request.ValidatedRequest.AccessTokenLifetime, - Custom = request.CustomResponse, - Scope = request.ValidatedRequest.ValidatedResources.RawScopeValues.ToSpaceSeparatedString() - }; + var response = await ProcessTokenRequestAsync(request); - ////////////////////////// - // refresh token - ///////////////////////// - if (refreshToken.IsPresent()) - { - response.RefreshToken = refreshToken; - } - - ////////////////////////// - // id token - ///////////////////////// if (request.ValidatedRequest.DeviceCode.IsOpenId) { // load the client that belongs to the device code @@ -330,31 +286,8 @@ protected virtual async Task ProcessCibaRequestAsync(TokenRequest { Logger.LogTrace("Creating response for CIBA request"); - ////////////////////////// - // access token - ///////////////////////// - var (accessToken, refreshToken) = await CreateAccessTokenAsync(request.ValidatedRequest); - var response = new TokenResponse - { - AccessToken = accessToken, - AccessTokenType = request.ValidatedRequest.ProofType == ProofType.DPoP ? OidcConstants.TokenResponse.DPoPTokenType : OidcConstants.TokenResponse.BearerTokenType, - AccessTokenLifetime = request.ValidatedRequest.AccessTokenLifetime, - Custom = request.CustomResponse, - Scope = request.ValidatedRequest.ValidatedResources.RawScopeValues.ToSpaceSeparatedString() - }; + var response = await ProcessTokenRequestAsync(request); - ////////////////////////// - // refresh token - ///////////////////////// - if (refreshToken.IsPresent()) - { - response.RefreshToken = refreshToken; - } - - ////////////////////////// - // id token - ///////////////////////// - // load the client that belongs to the device code Client client = null; if (request.ValidatedRequest.BackChannelAuthenticationRequest.ClientId != null) @@ -395,10 +328,9 @@ protected virtual Task ProcessExtensionGrantRequestAsync(TokenReq } /// - /// Creates the response for a token request. + /// Creates a response for a token request containing an access token and a + /// refresh token if requested. /// - /// The validation result. - /// protected virtual async Task ProcessTokenRequestAsync(TokenRequestValidationResult validationResult) { (var accessToken, var refreshToken) = await CreateAccessTokenAsync(validationResult.ValidatedRequest); @@ -419,6 +351,7 @@ protected virtual async Task ProcessTokenRequestAsync(TokenReques return response; } + /// /// Creates the access/refresh token. ///