Skip to content

Commit

Permalink
chore(webapi): Fix JWTBearerAuth scheme name casing (#1578)
Browse files Browse the repository at this point in the history
<!--- Provide a general summary of your changes in the Title above -->

## Description

<!--- Describe your changes in detail -->

## Related Issue(s)

- #1577 

## Verification

- [x] **Your** code builds clean without any errors or warnings
- [x] Manual testing done (required)
- [ ] Relevant automated test added (if you find this hard, leave it and
we'll help out)

## Documentation

- [ ] Documentation is updated (either in `docs`-directory, Altinnpedia
or a separate linked PR in
[altinn-studio-docs.](https://github.com/Altinn/altinn-studio-docs), if
applicable)

Co-authored-by: Knut Haug <[email protected]>
  • Loading branch information
oskogstad and knuhau authored Dec 10, 2024
1 parent 7bed6c1 commit c5f3bfb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/schema/V1/swagger.verified.json
Original file line number Diff line number Diff line change
Expand Up @@ -4683,7 +4683,7 @@
"JWTBearerAuth": {
"bearerFormat": "JWT",
"description": "Enter a JWT token to authorize the requests...",
"scheme": "Bearer",
"scheme": "bearer",
"type": "http"
}
}
Expand Down
18 changes: 18 additions & 0 deletions src/Digdir.Domain.Dialogporten.WebApi/OpenApiDocumentExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@ namespace Digdir.Domain.Dialogporten.WebApi;

public static class OpenApiDocumentExtensions
{
/// <summary>
/// To have this be validated in BlackDuck, we need to lower case the bearer scheme name.
/// From editor.swagger.io:
/// Structural error at components.securitySchemes.JWTBearerAuth
/// should NOT have a `bearerFormat` property without `scheme: bearer` being set
/// </summary>
/// <param name="openApiDocument"></param>
public static void FixJwtBearerCasing(this OpenApiDocument openApiDocument)
{
foreach (var securityScheme in openApiDocument.Components.SecuritySchemes.Values)
{
if (securityScheme.Scheme.Equals("Bearer", StringComparison.Ordinal))
{
securityScheme.Scheme = "bearer";
}
}
}

/// <summary>
/// When generating ProblemDetails and ProblemDetails_Error, there is a bug/weird behavior in NSwag or FastEndpoints
/// which results in certain 'Description' properties being generated when running on f.ex. MacOS,
Expand Down
1 change: 1 addition & 0 deletions src/Digdir.Domain.Dialogporten.WebApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ static void BuildAndRun(string[] args, TelemetryConfiguration telemetryConfigura
document.Generator = null;
document.ReplaceProblemDetailsDescriptions();
document.MakeCollectionsNullable();
document.FixJwtBearerCasing();
};
}, uiConfig =>
{
Expand Down

0 comments on commit c5f3bfb

Please sign in to comment.