Skip to content

Commit

Permalink
Add OverwriteAuthorizationHeader flag (#12)
Browse files Browse the repository at this point in the history
* Add OverwriteAuthorizationHeader flag so consumers can choose to always overwrite any existing Authorization header

Co-authored-by: Bjørn Dybvik Langfors <[email protected]>
  • Loading branch information
DanRJ and elsand authored Mar 22, 2023
1 parent 60f00bd commit 99dd0c2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,10 @@ public class MaskinportenSettings
/// Optional. Enabels verbose logging that should only be enabled when troubleshooting. Will cause logging (with severity "Information") of assertions.
/// </summary>
public bool? EnableDebugLogging { get; set; }

/// <summary>
/// Optional. Overwrites existing Authorization-header if set. Default: ignore existing Authorization-header.
/// </summary>
public bool? OverwriteAuthorizationHeader { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ public MaskinportenTokenHandler(IMaskinportenService maskinporten, IClientDefini

protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
if (request.Headers.Authorization == null)
if (request.Headers.Authorization == null ||
(_clientDefinition.ClientSettings.OverwriteAuthorizationHeader .HasValue &&
_clientDefinition.ClientSettings.OverwriteAuthorizationHeader .Value))
{
TokenResponse tokenResponse = await GetTokenResponse(cancellationToken);
if (tokenResponse != null)
Expand Down

0 comments on commit 99dd0c2

Please sign in to comment.