Skip to content

Commit

Permalink
Bugfix: skipping default logic should only happen when authenticate f…
Browse files Browse the repository at this point in the history
…ails (#505)

* only skip default logic on authenticateFailure

* move error to body

* cleanup

---------

Co-authored-by: Hammerbeck <andreas.hammerbeck@digdir.no>
  • Loading branch information
Andreass2 and Hammerbeck authored Aug 1, 2024
1 parent cf4fa79 commit 5f05912
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Altinn.Broker.API/Helpers/JWTBearerEventsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ public static Task OnAuthenticationFailed(AuthenticationFailedContext context)
{
context.Response.StatusCode = StatusCodes.Status401Unauthorized;
context.Response.ContentType = "application/json";
context.Response.Headers.Append("WWW-Authenticate", context.Options.Challenge + " error=\"invalid_token\", error_description=\"" + context.Exception.Message + "\"");
string err = "";
context.Response.Headers.Append("WWW-Authenticate", context.Options.Challenge + " error=\"invalid_token\"");
string err = context.Exception.Message;
if (context.Exception is SecurityTokenInvalidIssuerException)
{
context.Response.StatusCode = StatusCodes.Status403Forbidden;
Expand Down
5 changes: 4 additions & 1 deletion src/Altinn.Broker.API/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,10 @@ static void ConfigureServices(IServiceCollection services, IConfiguration config
OnAuthenticationFailed = context => JWTBearerEventsHelper.OnAuthenticationFailed(context),
OnChallenge = c =>
{
c.HandleResponse();
if (c.AuthenticateFailure != null)
{
c.HandleResponse();
}
return Task.CompletedTask;
}
};
Expand Down

0 comments on commit 5f05912

Please sign in to comment.