diff --git a/docs/usage/authenticators.md b/docs/usage/authenticators.md index 24b79e4d5..3c465e92a 100644 --- a/docs/usage/authenticators.md +++ b/docs/usage/authenticators.md @@ -26,8 +26,53 @@ the values as encoded form values instead. ## Basic Authentication +The `HttpBasicAuthenticator` allows you pass a username and password as a basica auth Authorization header. + +```csharp +var client = new RestClient("http://example.com"); +client.Authenticator = new HttpBasicAuthenticator("username", "password"); +``` + ## OAuth1 +For OAuth1 authentication the `OAuth1Authenticator` class provides static methods to help generate an OAuth authenticator. + +### For endpoints requiring a request token + +This method requires a `consumerKey` and `consumerSecret` to authenticate. + +```csharp +var client = new RestClient("http://example.com"); +client.Authenticator = OAuth1Authenticator.ForRequestToken(consumerKey, consumerSecret); +``` + +### For endpoints requiring an access token + +This method retrieves an access token when provided `consumerKey`, `consumerSecret`, `oauthToken`, and `oauthTokenSecret`. + +```csharp +client.Authenticator = OAuth1Authenticator.ForAccessToken( + consumerKey, consumerSecret, oauthToken, + oauthTokenSecret + ); +``` + +This method also includes an optional parameter to specity the `OAuthSignatureMethod`. +```csharp +client.Authenticator = OAuth1Authenticator.ForAccessToken(consumerKey, + consumerSecret, + oauthToken, + oauthTokenSecret, + OAuthSignatureMethod.PlainText); +``` + +### 0-legged OAuth + +The same access token authenticator can be used in 0-legged OAuth scenarios by providing `null` for the `consumerSecret`. +```csharp +client.Authenticator = OAuth1Authenticator.ForAccessToken(consumerKey, null, oauthToken, oauthTokenSecret); +``` + ## JWT ## Custom Authenticator