mirror of
https://github.com/zoriya/octokit.net.git
synced 2025-12-06 07:16:09 +00:00
Remove reference to Basic Authentication in the docs (#2555)
* Update getting-started.md Edited the section on Authentication to remove Basic Auth, which GitHub no longer supports, with instructions for using a Personal Access Token. * Update getting-started.md Second commit: Removed "/en" from links. * Update docs/getting-started.md Co-authored-by: Tim Rogers <timrogers@github.com> * Update docs/getting-started.md Co-authored-by: Tim Rogers <timrogers@github.com> * Update getting-started.md Removed the two bullet pointed items because the sentence preceding them provided a clearer description of the options. Co-authored-by: Tim Rogers <timrogers@github.com>
This commit is contained in:
@@ -6,25 +6,22 @@ The easiest way to get started with Octokit is to use a plain `GitHubClient`:
|
||||
var client = new GitHubClient(new ProductHeaderValue("my-cool-app"));
|
||||
```
|
||||
|
||||
This will let you access unauthenticated GitHub APIs, but you will be subject to rate limiting (you can read more about this [here](https://docs.github.com/en/rest/overview/resources-in-the-rest-api#rate-limiting)).
|
||||
This will let you access unauthenticated GitHub APIs, but you will be subject to rate limiting (you can read more about this [here](https://docs.github.com/rest/overview/resources-in-the-rest-api#rate-limiting)).
|
||||
|
||||
But why do you need this `ProductHeaderValue` value?
|
||||
|
||||
The API will reject you if you don't provide a `User-Agent` header (more details [here](https://docs.github.com/en/rest/overview/resources-in-the-rest-api#user-agent-required)). This is also to identify applications that are accessing the API and enable GitHub to contact the application author if there are problems. So pick a name that stands out!
|
||||
The API will reject you if you don't provide a `User-Agent` header (more details [here](https://docs.github.com/rest/overview/resources-in-the-rest-api#user-agent-required)). This is also to identify applications that are accessing the API and enable GitHub to contact the application author if there are problems. So pick a name that stands out!
|
||||
|
||||
### Authenticated Access
|
||||
|
||||
If you want to access private repositories or perform actions on behalf of a user, you need to pass credentials to the client.
|
||||
|
||||
There are two options supported by the API - basic and OAuth authentication.
|
||||
You can authenticate by passing an access token, for example a personal access token (PAT), an OAuth access token or an installation token from a GitHub App.
|
||||
|
||||
If you wish to use a PAT follow this [link](https://docs.github.com/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token) to generate one, then replace "token" in the snippet below with the text generated by GitHub.
|
||||
|
||||
```csharp
|
||||
var basicAuth = new Credentials("username", "password"); // NOTE: not real credentials
|
||||
client.Credentials = basicAuth;
|
||||
```
|
||||
|
||||
```csharp
|
||||
var tokenAuth = new Credentials("token"); // NOTE: not real token
|
||||
var tokenAuth = new Credentials("token"); // This can be a PAT or an OAuth token.
|
||||
client.Credentials = tokenAuth;
|
||||
```
|
||||
|
||||
@@ -71,6 +68,7 @@ var user = await client.User.Current();
|
||||
```
|
||||
|
||||
### Too Much of a Good Thing: Dealing with API Rate Limits
|
||||
|
||||
Like any popular API, Github needs to throttle some requests. The OctoKit.NET client allows you to get some insight into how many requests you have left and when you can start making requests again.
|
||||
|
||||
In fact, there are two ways to get the Rate Limits via OctoKit.NET. Calling `GitHubClient.GetLastApiInfo()` returns the Rate Limit status which has been returned with the last api call. So, calling `GitHubClient.GetLastApiInfo()` will not send any extra HTTP requests to GitHub's servers.
|
||||
|
||||
Reference in New Issue
Block a user