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

Removing existing authorization token #674

Merged
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 @@ -30,6 +30,12 @@ public TokenAcquisitionCredentialProvider(ITokenAcquisition tokenAcquisition, IE
/// <returns>A Task (as this is an async method).</returns>
public async Task AuthenticateRequestAsync(HttpRequestMessage request)
{
// In case of a retry there is already an authorization header; replace it with new one to avoid using expired token
if (request.Headers.Contains(Constants.Authorization))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about the following?

request.Headers[Constants.Authorization] = string.Format(
                    CultureInfo.InvariantCulture,
                    "{0} {1}",
                    Constants.Bearer,
                    await _tokenAcquisition.GetAccessTokenForUserAsync(_initialScopes).ConfigureAwait(false)));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the HttpHeaders doesn't have a indexer

image

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Thanks @davesmits

{
request.Headers.Remove(Constants.Authorization);
}

request.Headers.Add(
Constants.Authorization,
string.Format(
Expand Down