Skip to content

Commit

Permalink
fix: check for expired token in any header value (#79)
Browse files Browse the repository at this point in the history
* fix: check for expired token in any header value
  • Loading branch information
Dovchik authored Jul 16, 2024
1 parent 64edaf6 commit 953f501
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Sinch/Core/Http.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public async Task<TResponse> Send<TRequest, TResponse>(Uri uri, HttpMethod httpM
// will not retry when no "expired" header for a token.
const string wwwAuthenticateHeader = "www-authenticate";
if (_auth.Scheme == AuthSchemes.Bearer && result.Headers.Contains(wwwAuthenticateHeader) &&
!result.Headers.GetValues(wwwAuthenticateHeader).Contains("expired"))
!result.Headers.GetValues(wwwAuthenticateHeader).Any(x => x.Contains("expired")))
{
_logger?.LogDebug("OAuth Unauthorized");
}
Expand Down
3 changes: 2 additions & 1 deletion tests/Sinch.Tests/Core/HttpTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ public async Task NewTokenFetchedIfWwwExpiredIsPresent()
.WithHeaders("Authorization", "Bearer first_token")
.Respond(HttpStatusCode.Unauthorized, new KeyValuePair<string, string>[]
{
new("www-authenticate", "expired")
new("www-authenticate",
"Bearer error=\"invalid_token\", error_description=\"Jwt expired at 2024-07-08T22:12:28Z\", error_uri=\"https://tools.ietf.org/html/rfc6750#section-3.1\"")
}, (HttpContent)null);

_httpMessageHandlerMock.Expect(HttpMethod.Get, uri.ToString())
Expand Down

0 comments on commit 953f501

Please sign in to comment.