Skip to content

Commit 9b06573

Browse files
authored
Document GitHub's new token formats (#18494)
1 parent a2b8a50 commit 9b06573

10 files changed

Lines changed: 59 additions & 18 deletions
53.8 KB
Loading
46.4 KB
Loading
18.8 KB
Loading

content/developers/apps/authorizing-oauth-apps.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,19 @@ Name | Type | Description
8686

8787
By default, the response takes the following form:
8888

89-
access_token=e72e16c7e42f292c6912e7710c838347ae178b4a&token_type=bearer
89+
access_token={% if currentVersion == "free-pro-team@latest" or currentVersion ver_gt "enterprise-server@3.1" or currentVersion == "github-ae@next" %}gho_16C7e42F292c6912E7710c838347Ae178B4a{% else %}e72e16c7e42f292c6912e7710c838347ae178b4a{% endif %}&token_type=bearer
9090

9191
You can also receive the content in different formats depending on the Accept
9292
header:
9393

9494
Accept: application/json
95-
{"access_token":"e72e16c7e42f292c6912e7710c838347ae178b4a", "scope":"repo,gist", "token_type":"bearer"}
95+
{"access_token":"{% if currentVersion == "free-pro-team@latest" or currentVersion ver_gt "enterprise-server@3.1" or currentVersion == "github-ae@next" %}gho_16C7e42F292c6912E7710c838347Ae178B4a{% else %}e72e16c7e42f292c6912e7710c838347ae178b4a{% endif %}", "scope":"repo,gist", "token_type":"bearer"}
9696

9797
Accept: application/xml
9898
<OAuth>
9999
<token_type>bearer</token_type>
100100
<scope>repo,gist</scope>
101-
<access_token>e72e16c7e42f292c6912e7710c838347ae178b4a</access_token>
101+
<access_token>{% if currentVersion == "free-pro-team@latest" or currentVersion ver_gt "enterprise-server@3.1" or currentVersion == "github-ae@next" %}gho_16C7e42F292c6912E7710c838347Ae178B4a{% else %}e72e16c7e42f292c6912e7710c838347ae178b4a{% endif %}</access_token>
102102
</OAuth>
103103

104104
#### 3. Use the access token to access the API
@@ -208,7 +208,7 @@ Name | Type | Description
208208

209209
```json
210210
{
211-
"access_token": "e72e16c7e42f292c6912e7710c838347ae178b4a",
211+
"access_token": "{% if currentVersion == "free-pro-team@latest" or currentVersion ver_gt "enterprise-server@3.1" or currentVersion == "github-ae@next" %}gho_16C7e42F292c6912E7710c838347Ae178B4a{% else %}e72e16c7e42f292c6912e7710c838347ae178b4a{% endif %}",
212212
"token_type": "bearer",
213213
"scope": "user"
214214
}
@@ -311,3 +311,7 @@ To build this link, you'll need your OAuth Apps `client_id` that you received fr
311311
{% if currentVersion == "free-pro-team@latest" or currentVersion ver_gt "enterprise-server@2.21" or currentVersion == "github-ae@latest" %}
312312
* "[Device flow errors](#errors-for-the-device-flow)"
313313
{% endif %}
314+
315+
### Further reading
316+
317+
- "[About authentication to {% data variables.product.prodname_dotcom %}](/github/authenticating-to-github/about-authentication-to-github)"

content/developers/apps/creating-ci-tests-with-the-checks-api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ Here are a few common problems and some suggested solutions. If you run into any
845845
**A:** If you see the following error, you haven't deleted the checkout of the repository in one or both of the `initiate_check_run` or `take_requested_action` methods:
846846

847847
```shell
848-
2018-11-26 16:55:13 - Git::GitExecuteError - git clone '--' 'https://x-access-token:v1.9b2080277016f797074c4debd350745f4257f8dd@github.com/codertocat/octocat-breeds.git' 'Octocat-breeds' 2>&1:fatal: destination path 'Octocat-breeds' already exists and is not an empty directory.:
848+
2018-11-26 16:55:13 - Git::GitExecuteError - git clone '--' 'https://x-access-token:ghs_9b2080277016f797074c4dEbD350745f4257@github.com/codertocat/octocat-breeds.git' 'Octocat-breeds' 2>&1:fatal: destination path 'Octocat-breeds' already exists and is not an empty directory.:
849849
```
850850

851851
Compare your code to the `server.rb` file to ensure you have the same code in your `initiate_check_run` and `take_requested_action` methods.

content/developers/apps/identifying-and-authorizing-users-for-github-apps.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ By default, the response takes the following form. The response parameters `expi
9494

9595
```json
9696
{
97-
"access_token": "e72e16c7e42f292c6912e7710c838347ae178b4a",
97+
"access_token": "{% if currentVersion == "free-pro-team@latest" or currentVersion ver_gt "enterprise-server@3.1" or currentVersion == "github-ae@next" %}ghu_16C7e42F292c6912E7710c838347Ae178B4a"{% else %}e72e16c7e42f292c6912e7710c838347ae178b4a{% endif %}",
9898
"expires_in": 28800,
99-
"refresh_token": "r1.c1b4a2e77838347a7e420ce178f2e7c6912e1692",
99+
"refresh_token": "{% if currentVersion == "free-pro-team@latest" or currentVersion ver_gt "enterprise-server@3.1" or currentVersion == "github-ae@next" %}ghr_1B4a2e77838347a7E420ce178F2E7c6912E169246c34E1ccbF66C46812d16D5B1A9Dc86A1498"{% else %}r1.c1b4a2e77838347a7e420ce178f2e7c6912e1692{% endif %}",
100100
"refresh_token_expires_in": 15811200,
101101
"scope": "",
102102
"token_type": "bearer"
@@ -106,7 +106,7 @@ By default, the response takes the following form. The response parameters `expi
106106

107107
By default, the response takes the following form:
108108

109-
access_token=e72e16c7e42f292c6912e7710c838347ae178b4a&token_type=bearer
109+
access_token={% if currentVersion == "free-pro-team@latest" or currentVersion ver_gt "enterprise-server@3.1" or currentVersion == "github-ae@next" %}ghu_16C7e42F292c6912E7710c838347Ae178B4a"{% else %}e72e16c7e42f292c6912e7710c838347ae178b4a{% endif %}&token_type=bearer
110110

111111
{% endif %}
112112

@@ -934,3 +934,11 @@ While most of your API interaction should occur using your server-to-server inst
934934
* [Get a workflow](/rest/reference/actions#get-a-workflow)
935935
* [Get workflow usage](/rest/reference/actions#get-workflow-usage)
936936
{% endif %}
937+
938+
{% if currentVersion == "free-pro-team@latest" or currentVersion ver_gt "enterprise-server@3.1" or currentVersion == "github-ae@next" %}
939+
940+
### Further reading
941+
942+
- "[About authentication to {% data variables.product.prodname_dotcom %}](/github/authenticating-to-github/about-authentication-to-github#githubs-token-formats)"
943+
944+
{% endif %}

content/developers/apps/refreshing-user-to-server-access-tokens.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ Name | Type | Description
4242

4343
```json
4444
{
45-
"access_token": "e72e16c7e42f292c6912e7710c838347ae178b4a",
45+
"access_token": "{% if currentVersion == "free-pro-team@latest" or currentVersion ver_gt "enterprise-server@3.1" or currentVersion == "github-ae@next" %}ghu_16C7e42F292c6912E7710c838347Ae178B4a"{% else %}e72e16c7e42f292c6912e7710c838347ae178b4a{% endif %}",
4646
"expires_in": "28800",
47-
"refresh_token": "r1.c1b4a2e77838347a7e420ce178f2e7c6912e169246c34e1ccbf66c46812d16d5b1a9dc86a149873c",
47+
"refresh_token": "{% if currentVersion == "free-pro-team@latest" or currentVersion ver_gt "enterprise-server@3.1" or currentVersion == "github-ae@next" %}ghr_1B4a2e77838347a7E420ce178F2E7c6912E169246c34E1ccbF66C46812d16D5B1A9Dc86A1498"{% else %}r1.c1b4a2e77838347a7e420ce178f2e7c6912e169246c34e1ccbf66c46812d16d5b1a9dc86a149873c{% endif %}",
4848
"refresh_token_expires_in": "15811200",
4949
"scope": "",
5050
"token_type": "bearer"
@@ -74,3 +74,11 @@ If you want your app to use non-expiring user-to-server access tokens, you can d
7474
Existing {% data variables.product.prodname_github_app %}s using user-to-server authorization tokens are only affected by this new flow when the app owner enables expiring user tokens for their app.
7575

7676
Enabling expiring user tokens for existing {% data variables.product.prodname_github_app %}s requires sending users through the OAuth flow to re-issue new user tokens that will expire in 8 hours and making a request with the refresh token to get a new access token and refresh token. For more information, see "[Identifying and authorizing users for GitHub Apps](/apps/building-github-apps/identifying-and-authorizing-users-for-github-apps/)."
77+
78+
{% if currentVersion == "free-pro-team@latest" or currentVersion ver_gt "enterprise-server@3.1" or currentVersion == "github-ae@next" %}
79+
80+
### Further reading
81+
82+
- "[About authentication to {% data variables.product.prodname_dotcom %}](/github/authenticating-to-github/about-authentication-to-github#githubs-token-formats)"
83+
84+
{% endif %}

content/github/authenticating-to-github/about-authentication-to-github.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,19 @@ You can access repositories on {% data variables.product.product_name %} from th
5555
* You can work with all repositories on {% data variables.product.product_name %} over SSH, although firewalls and proxys might refuse to allow SSH connections. Using SSH requires you to generate an SSH public/private keypair on your local machine and add the public key to your {% data variables.product.product_name %} account. Every time you use Git to authenticate with {% data variables.product.product_name %}, you'll be prompted to enter your SSH key passphrase, unless you've [stored the key](/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent#adding-your-ssh-key-to-the-ssh-agent). For more information, see "[Generating a new SSH key and adding it to the ssh-agent](/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent)."
5656

5757
{% if currentVersion == "free-pro-team@latest" %}To use a personal access token or SSH key to access resources owned by an organization that uses SAML single sign-on, you must also authorize the personal token or SSH key. For more information, see "[Authorizing a personal access token for use with SAML single sign-on](/github/authenticating-to-github/authorizing-a-personal-access-token-for-use-with-saml-single-sign-on)" or "[Authorizing an SSH key for use with SAML single sign-on](/github/authenticating-to-github/authorizing-an-ssh-key-for-use-with-saml-single-sign-on)."{% endif %}
58+
59+
{% if currentVersion == "free-pro-team@latest" or currentVersion ver_gt "enterprise-server@3.1" or currentVersion == "github-ae@next" %}
60+
61+
### {% data variables.product.company_short %}'s token formats
62+
63+
{% data variables.product.company_short %} issues tokens that begin with a prefix to indicate the token's type.
64+
65+
| Token type | Prefix | More information |
66+
| :- | :- | :- |
67+
| Personal access token | `ghp_` | "[Creating a personal access token](/github/authenticating-to-github/creating-a-personal-access-token)" |
68+
| OAuth access token | `gho_` | "[Authorizing {% data variables.product.prodname_oauth_apps %}](/developers/apps/authorizing-oauth-apps)" |
69+
| User-to-server token for a {% data variables.product.prodname_github_app %} | `ghu_` | "[Identifying and authorizing users for {% data variables.product.prodname_github_apps %}](/developers/apps/identifying-and-authorizing-users-for-github-apps)" |
70+
| Server-to-server token for a {% data variables.product.prodname_github_app %} | `ghs_` | "[Authenticating with {% data variables.product.prodname_github_apps %}](/developers/apps/authenticating-with-github-apps#authenticating-as-an-installation)" |
71+
| Refresh token for a {% data variables.product.prodname_github_app %} | `ghr_` | "[Refreshing user-to-server access tokens](/developers/apps/refreshing-user-to-server-access-tokens)" |
72+
73+
{% endif %}

content/github/authenticating-to-github/creating-a-personal-access-token.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,14 @@ Personal access tokens (PATs) are an alternative to using passwords for authenti
3939
{% endif %}
4040
7. Click **Generate token**.
4141
![Generate token button](/assets/images/help/settings/generate_token.png)
42-
8. Click {% octicon "clippy" aria-label="The copy to clipboard icon" %} to copy the token to your clipboard. For security reasons, after you navigate off the page, you will not be able to see the token again.{% if currentVersion == "free-pro-team@latest" %}
43-
![Newly created token](/assets/images/help/settings/personal_access_tokens.png){% else %}
44-
![Newly created token](/assets/images/help/settings/personal_access_tokens_ghe.png){% endif %}
42+
8. Click {% octicon "clippy" aria-label="The copy to clipboard icon" %} to copy the token to your clipboard. For security reasons, after you navigate off the page, you will not be able to see the token again.
43+
{% if currentVersion == "free-pro-team@latest" %}
44+
![Newly created token](/assets/images/help/settings/personal_access_tokens.png)
45+
{% elsif currentVersion ver_gt "enterprise-server@3.1" or currentVersion == "github-ae@next" %}
46+
![Newly created token](/assets/images/help/settings/personal_access_tokens_ghe.png)
47+
{% else %}
48+
![Newly created token](/assets/images/help/settings/personal_access_tokens_ghe_legacy.png)
49+
{% endif %}
4550

4651
{% warning %}
4752

content/rest/guides/getting-started-with-the-rest-api.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ $ curl -i {% data variables.product.api_url_pre %}/repos/twbs/bootstrap
197197
In the same way, we can [view repositories for the authenticated user][user repos api]:
198198
199199
```shell
200-
$ curl -i -H "Authorization: token 5199831f4dd3b79e7c5b7e0ebe75d67aa66e79d4" \
200+
$ curl -i -H "Authorization: token {% if currentVersion == "free-pro-team@latest" or currentVersion ver_gt "enterprise-server@3.1" or currentVersion == "github-ae@next" %}ghp_16C7e42F292c6912E7710c838347Ae178B4a"{% else %}5199831f4dd3b79e7c5b7e0ebe75d67aa66e79d4{% endif %}" \
201201
{% data variables.product.api_url_pre %}/user/repos
202202
```
203203
@@ -240,7 +240,7 @@ Fetching information for existing repositories is a common use case, but the
240240
we need to `POST` some JSON containing the details and configuration options.
241241
242242
```shell
243-
$ curl -i -H "Authorization: token 5199831f4dd3b79e7c5b7e0ebe75d67aa66e79d4" \
243+
$ curl -i -H "Authorization: token {% if currentVersion == "free-pro-team@latest" or currentVersion ver_gt "enterprise-server@3.1" or currentVersion == "github-ae@next" %}ghp_16C7e42F292c6912E7710c838347Ae178B4a"{% else %}5199831f4dd3b79e7c5b7e0ebe75d67aa66e79d4{% endif %}" \
244244
-d '{ \
245245
"name": "blog", \
246246
"auto_init": true, \
@@ -286,15 +286,15 @@ Just like github.com, the API provides a few methods to view issues for the
286286
authenticated user. To [see all your issues][get issues api], call `GET /issues`:
287287
288288
```shell
289-
$ curl -i -H "Authorization: token 5199831f4dd3b79e7c5b7e0ebe75d67aa66e79d4" \
289+
$ curl -i -H "Authorization: token {% if currentVersion == "free-pro-team@latest" or currentVersion ver_gt "enterprise-server@3.1" or currentVersion == "github-ae@next" %}ghp_16C7e42F292c6912E7710c838347Ae178B4a"{% else %}5199831f4dd3b79e7c5b7e0ebe75d67aa66e79d4{% endif %}" \
290290
{% data variables.product.api_url_pre %}/issues
291291
```
292292
293293
To get only the [issues under one of your {% data variables.product.product_name %} organizations][get issues api], call `GET
294294
/orgs/<org>/issues`:
295295
296296
```shell
297-
$ curl -i -H "Authorization: token 5199831f4dd3b79e7c5b7e0ebe75d67aa66e79d4" \
297+
$ curl -i -H "Authorization: token {% if currentVersion == "free-pro-team@latest" or currentVersion ver_gt "enterprise-server@3.1" or currentVersion == "github-ae@next" %}ghp_16C7e42F292c6912E7710c838347Ae178B4a"{% else %}5199831f4dd3b79e7c5b7e0ebe75d67aa66e79d4{% endif %}" \
298298
{% data variables.product.api_url_pre %}/orgs/rails/issues
299299
```
300300
@@ -336,7 +336,7 @@ body to the `/issues` path underneath the repository in which we want to create
336336
the issue:
337337
338338
```shell
339-
$ curl -i -H 'Authorization: token 5199831f4dd3b79e7c5b7e0ebe75d67aa66e79d4' \
339+
$ curl -i -H 'Authorization: token {% if currentVersion == "free-pro-team@latest" or currentVersion ver_gt "enterprise-server@3.1" or currentVersion == "github-ae@next" %}ghp_16C7e42F292c6912E7710c838347Ae178B4a"{% else %}5199831f4dd3b79e7c5b7e0ebe75d67aa66e79d4{% endif %}' \
340340
$ -d '{ \
341341
$ "title": "New logo", \
342342
$ "body": "We should have one", \

0 commit comments

Comments
 (0)