-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Closed
Labels
Description
It is related to changes that happened within the #1963 scope
Use case:
It is a common practice that the Authentication token is not provided during the initialization of the RestClient and has to be fetched later from a specific URI (eg. "/auth").
This was working in v108:
_restClient = new RestClient("https://my-base-uri");
var request = new RestRequest("auth")
.AddJsonBody(new UserCredentials("user", "password123"));
var response = await tempClient.PostAsync<LoginResponse>(request);
_restClient.Authenticator = new JwtAuthenticator(response.Token);
This is a workaround in v109:
//Creating a temporary RestClient only to perform a POST call to get the token
var tempClient = new RestClient("https://my-base-uri");
var request = new RestRequest("auth")
.AddJsonBody(new UserCredentials("user", "password123"));
var response = await tempClient.PostAsync<LoginResponse>(request);
//In v109, the 'RestSharp.ReadOnlyRestClientOptions.Authenticator' has no setter.
//For this case, a new instance of RestClient must be created
_restClient = new RestClient(new RestClientOptions
{
BaseUrl = new Uri("https://my-base-uri"),
Authenticator = new JwtAuthenticator(response.Token)
});
Outcomes:
Instanciating 2 RestClient just to change one (or more) properties in Options is not optimal. My humble opinion is to create an instance of RestClient and to be able to change just the specific properties you may require.
Reactions are currently unavailable