Page cover image

RestSharp Authenticator

To register a specific RestSharp credential, just create that type and assign the appropriate Authenticator.

CredentialStore.RegisterRefresh("ClientAPI", (o) => {

        return new RestSharpCredentialStoreItem(
                new RestSharp.Authenticators.JwtAuthenticator("MyToken"), 
                DateTimeOffset.UtcNow.AddMinutes(58));
        
});

Any time you create a client, simply assign this credential authenticator:

//Create a new client
using var client = new RestClient("https://localhost.com");

//Assign the CredentialAuthenticator with the name tied to the refresh
client.UseAuthenticator(new CredentialAuthenticator("ClientAPI"));

//Anytime you execute any requests, it's automatically maintained. 

Last updated