How to handle Mutliple Authtoken in RestSharp

23 Views Asked by At

I have a System endpoint which requires ClientID, SecretKey, Scope and grantType. I set the client-wide authenticator by assigning the Authenticator property of RestClientOptions.

Now I also have a Business enpoint which requires Username, Password, ClientID, SecretKey, Scope and grantType and it requires a new AuthToken. I want to replace the Authenticator token This statement is not allowing me to retrieve a new token. It is not calling the GetToken method because there is already Token assigned.

  Token = string.IsNullOrEmpty(Token) ? await GetToken() : Token;

How do I reset the Authenticator Token, when I run the business endpoints and generate a new Token.

1

There are 1 best solutions below

0
Bill Tutt On

You can set the Authenticator property on each RestSharp request, and it will override the RestClient Options Authenticator property and be used instead.

Alternatively, you can write a custom Authenticator that examines the supplied request and returns an appropriate token depending on the Uri in the request.

You can see some additional details at RestSharp GitHub