From 953f501d49173aa232b0f43199601b7eb806b635 Mon Sep 17 00:00:00 2001 From: Volodymyr Lisovskyi Date: Tue, 16 Jul 2024 11:49:00 +0200 Subject: [PATCH] fix: check for expired token in any header value (#79) * fix: check for expired token in any header value --- src/Sinch/Core/Http.cs | 2 +- tests/Sinch.Tests/Core/HttpTests.cs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Sinch/Core/Http.cs b/src/Sinch/Core/Http.cs index a279ee0..da5a36b 100644 --- a/src/Sinch/Core/Http.cs +++ b/src/Sinch/Core/Http.cs @@ -128,7 +128,7 @@ public async Task Send(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"); } diff --git a/tests/Sinch.Tests/Core/HttpTests.cs b/tests/Sinch.Tests/Core/HttpTests.cs index 2cb1c50..4438bf8 100644 --- a/tests/Sinch.Tests/Core/HttpTests.cs +++ b/tests/Sinch.Tests/Core/HttpTests.cs @@ -116,7 +116,8 @@ public async Task NewTokenFetchedIfWwwExpiredIsPresent() .WithHeaders("Authorization", "Bearer first_token") .Respond(HttpStatusCode.Unauthorized, new KeyValuePair[] { - 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())