-2

really need some help to understand what I'm doing wrong with my reauthorization policy.

My policy looks like this:

var policy = Policy
            .HandleResult<HttpResponseMessage>(message => message.StatusCode == HttpStatusCode.Unauthorized)
            .RetryAsync(1, async (result, retryCount) =>
            {
                await _authorizeService.RefreshAccessToken();
                RestEaseClient.Token = _authorizeService.AccessToken;
            });

And IRestEaseClient looks like this:

public interface IRestEaseClient
{        
    [Header("X-Token")]
    string Token { get; set; }

    ["root")]
    Task SomeMethod();
    .................
}

When the token expires the breakpoint inside the policy retry function gets hit, I successfully receive the new token, set its value to IRestEaseClient.Token header, but for some reason, the retry request goes with the old header value and I still get 401. The next request after this will go fine, without 401 or hitting the reauthorize policy code.

Scott
  • 19
  • 6

1 Answers1

0

The answer is HttpRequestMessage has already been constructed by RestEase, and RestEase is now out of the picture. You can change RestEaseClient.Token all you like, that won't have any effect until you call SomeMethod again which constructs a new HttpRequestMessage.

Look into this discussion for details https://github.com/canton7/RestEase/discussions/192

Scott
  • 19
  • 6