From 904084b2bb4f1953879e0411815638ee482e7357 Mon Sep 17 00:00:00 2001 From: Patrick Hampson Date: Sat, 4 Sep 2021 01:24:58 -0400 Subject: [PATCH 1/2] Add basic auth documentation --- docs/usage/authenticators.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/usage/authenticators.md b/docs/usage/authenticators.md index 24b79e4d5..3d7cd8d55 100644 --- a/docs/usage/authenticators.md +++ b/docs/usage/authenticators.md @@ -26,6 +26,13 @@ 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 ## JWT From 65c6d3f56a803af05737e110058145d71f66670c Mon Sep 17 00:00:00 2001 From: Patrick Hampson Date: Sat, 4 Sep 2021 01:45:37 -0400 Subject: [PATCH 2/2] Update authenticators.md --- docs/usage/authenticators.md | 38 ++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/docs/usage/authenticators.md b/docs/usage/authenticators.md index 3d7cd8d55..3c465e92a 100644 --- a/docs/usage/authenticators.md +++ b/docs/usage/authenticators.md @@ -35,6 +35,44 @@ 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