Skip to content

Commit

Permalink
add response generator for BackchannelAuthenticationResult
Browse files Browse the repository at this point in the history
  • Loading branch information
brockallen committed Jun 26, 2023
1 parent f009a3c commit 4d331ca
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public static IIdentityServerBuilder AddDefaultEndpoints(this IIdentityServerBui
builder.AddEndpointResultGenerator<DiscoveryDocumentResult, DiscoveryDocumentResultGenerator>();
builder.AddEndpointResultGenerator<AuthorizeResult, AuthorizeResultGenerator>();
builder.AddEndpointResultGenerator<AuthorizeInteractionPageResult, AuthorizeInteractionPageResultGenerator>();
builder.AddEndpointResultGenerator<BackchannelAuthenticationResult, BackchannelAuthenticationResultGenerator>();

return builder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,25 @@

namespace Duende.IdentityServer.Endpoints.Results;

internal class BackchannelAuthenticationResult : IEndpointResult
internal class BackchannelAuthenticationResult : EndpointResult<BackchannelAuthenticationResult>
{
public BackchannelAuthenticationResponse Response { get; set; }

public BackchannelAuthenticationResult(BackchannelAuthenticationResponse response)
{
Response = response ?? throw new ArgumentNullException(nameof(response));
}
}

public async Task ExecuteAsync(HttpContext context)
internal class BackchannelAuthenticationResultGenerator : IEndpointResultGenerator<BackchannelAuthenticationResult>
{
public async Task ExecuteAsync(BackchannelAuthenticationResult result, HttpContext context)
{
context.Response.SetNoCache();

if (Response.IsError)
if (result.Response.IsError)
{
switch (Response.Error)
switch (result.Response.Error)
{
case OidcConstants.BackchannelAuthenticationRequestErrors.InvalidClient:
context.Response.StatusCode = 401;
Expand All @@ -40,19 +43,20 @@ public async Task ExecuteAsync(HttpContext context)
break;
}

await context.Response.WriteJsonAsync(new ErrorResultDto {
error = Response.Error,
error_description = Response.ErrorDescription
await context.Response.WriteJsonAsync(new ErrorResultDto
{
error = result.Response.Error,
error_description = result.Response.ErrorDescription
});
}
else
{
context.Response.StatusCode = 200;
await context.Response.WriteJsonAsync(new SuccessResultDto
{
auth_req_id = Response.AuthenticationRequestId,
expires_in = Response.ExpiresIn,
interval = Response.Interval
auth_req_id = result.Response.AuthenticationRequestId,
expires_in = result.Response.ExpiresIn,
interval = result.Response.Interval
});
}
}
Expand Down

0 comments on commit 4d331ca

Please sign in to comment.