Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TokenResponseGenerator.CreateResponseAsync #1178

Merged
merged 5 commits into from
Apr 1, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -143,30 +143,8 @@ protected virtual async Task<TokenResponse> 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
Expand Down Expand Up @@ -267,30 +245,8 @@ protected virtual async Task<TokenResponse> 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
Expand Down Expand Up @@ -330,31 +286,8 @@ protected virtual async Task<TokenResponse> 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)
Expand Down Expand Up @@ -395,10 +328,9 @@ protected virtual Task<TokenResponse> ProcessExtensionGrantRequestAsync(TokenReq
}

/// <summary>
/// Creates the response for a token request.
/// Creates a response for a token request containing an access token and a
/// refresh token if requested.
/// </summary>
/// <param name="validationResult">The validation result.</param>
/// <returns></returns>
protected virtual async Task<TokenResponse> ProcessTokenRequestAsync(TokenRequestValidationResult validationResult)
{
(var accessToken, var refreshToken) = await CreateAccessTokenAsync(validationResult.ValidatedRequest);
Expand All @@ -419,6 +351,7 @@ protected virtual async Task<TokenResponse> ProcessTokenRequestAsync(TokenReques
return response;
}


/// <summary>
/// Creates the access/refresh token.
/// </summary>
Expand Down