Skip to content

Commit 44381d9

Browse files
Authenticator documentation updates (#1629)
* Add basic auth documentation * Update authenticators.md
1 parent 341b2ed commit 44381d9

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

docs/usage/authenticators.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,53 @@ the values as encoded form values instead.
2626

2727
## Basic Authentication
2828

29+
The `HttpBasicAuthenticator` allows you pass a username and password as a basica auth Authorization header.
30+
31+
```csharp
32+
var client = new RestClient("http://example.com");
33+
client.Authenticator = new HttpBasicAuthenticator("username", "password");
34+
```
35+
2936
## OAuth1
3037

38+
For OAuth1 authentication the `OAuth1Authenticator` class provides static methods to help generate an OAuth authenticator.
39+
40+
### For endpoints requiring a request token
41+
42+
This method requires a `consumerKey` and `consumerSecret` to authenticate.
43+
44+
```csharp
45+
var client = new RestClient("http://example.com");
46+
client.Authenticator = OAuth1Authenticator.ForRequestToken(consumerKey, consumerSecret);
47+
```
48+
49+
### For endpoints requiring an access token
50+
51+
This method retrieves an access token when provided `consumerKey`, `consumerSecret`, `oauthToken`, and `oauthTokenSecret`.
52+
53+
```csharp
54+
client.Authenticator = OAuth1Authenticator.ForAccessToken(
55+
consumerKey, consumerSecret, oauthToken,
56+
oauthTokenSecret
57+
);
58+
```
59+
60+
This method also includes an optional parameter to specity the `OAuthSignatureMethod`.
61+
```csharp
62+
client.Authenticator = OAuth1Authenticator.ForAccessToken(consumerKey,
63+
consumerSecret,
64+
oauthToken,
65+
oauthTokenSecret,
66+
OAuthSignatureMethod.PlainText);
67+
```
68+
69+
### 0-legged OAuth
70+
71+
The same access token authenticator can be used in 0-legged OAuth scenarios by providing `null` for the `consumerSecret`.
72+
```csharp
73+
client.Authenticator = OAuth1Authenticator.ForAccessToken(consumerKey, null, oauthToken, oauthTokenSecret);
74+
```
75+
3176
## JWT
3277

3378
## Custom Authenticator

0 commit comments

Comments
 (0)