@@ -9,7 +9,7 @@ title: OAuth | GitHub API
99
1010OAuth2 is a protocol that lets external apps request authorization to
1111private details in a user's GitHub account without getting their
12- password. This is preferred over Basic Authentication because tokens can
12+ password. This is preferred over [ Basic Authentication] ( /v3/auth#basic-authentication ) because tokens can
1313be limited to specific types of data, and can be revoked by users at any
1414time.
1515
@@ -97,10 +97,12 @@ The access token allows you to make requests to the API on a behalf of a user.
9797
9898## Non-Web Application Flow
9999
100- Use basic authentication to create an OAuth2 token using the [ interface
101- below] ( /v3/oauth/#create-a-new-authorization ) . With this technique, a username
102- and password need not be stored permanently, and the user can revoke access at
103- any time.
100+ Use [ Basic Authentication] ( /v3/auth#basic-authentication ) to create an OAuth2
101+ token using the [ interface below] ( /v3/oauth/#create-a-new-authorization ) . With
102+ this technique, a username and password need not be stored permanently, and the
103+ user can revoke access at any time. (Make sure to understand how to [ work with
104+ two-factor authentication] ( /v3/auth/#working-with-two-factor-authentication ) if
105+ you or your users have two-factor authentication enabled.)
104106
105107## Redirect URLs
106108
@@ -185,8 +187,11 @@ can specify multiple scopes by separating them by a comma.
185187
186188## OAuth Authorizations API
187189
188- There is an API for users to manage their own tokens. You can only
189- access your own tokens, and only through Basic Authentication.
190+ There is an API for users to manage their own tokens. You can only access your
191+ own tokens, and only via [ Basic Authentication] ( /v3/auth#basic-authentication ) .
192+ (Make sure to understand how to [ work with two-factor
193+ authentication] ( /v3/auth/#working-with-two-factor-authentication ) if you or your
194+ users have two-factor authentication enabled.)
190195
191196## List your authorizations
192197
@@ -210,7 +215,7 @@ access your own tokens, and only through Basic Authentication.
210215
211216If you need a small number of tokens, implementing the [ web flow] ( #web-application-flow )
212217can be cumbersome. Instead, tokens can be created using the Authorizations API using
213- Basic Authentication. To create tokens for a particular OAuth application, you
218+ [ Basic Authentication] ( /v3/auth#basic-authentication ) . To create tokens for a particular OAuth application, you
214219must provide its client ID and secret, found on the OAuth application settings
215220page, linked from your [ OAuth applications listing on GitHub] [ app-listing ] . OAuth tokens
216221can also be created through the web UI via the [ Application settings page] ( https://github.com/settings/applications ) .
@@ -245,6 +250,45 @@ token.
245250%>
246251<%= json : oauth_access %>
247252
253+ ## Get-or-create an authorization for a specific app
254+
255+ This method will create a new authorization for the specified OAuth application,
256+ only if an authorization for that application doesn't already exist for the
257+ user. (The URL includes the 20 character client ID for the OAuth app that is
258+ requesting the token.) It returns the user's token for the application if one
259+ exists. Otherwise, it creates one.
260+
261+ PUT /authorizations/clients/:client_id
262+
263+ ### Input
264+
265+ client_secret
266+ : ** String** - The 40 character OAuth app client secret associated with the
267+ client ID specified in the URL.
268+
269+ scopes
270+ : _ Optional_ ** array** - A list of scopes that this authorization is in.
271+
272+ note
273+ : _ Optional_ ** string** - A note to remind you what the OAuth token is for.
274+
275+ note_url
276+ : _ Optional_ ** string** - A URL to remind you what app the OAuth token is for.
277+
278+ <%= json : client_secret => "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd", : scopes => [ "public_repo"] , : note => 'admin script' %>
279+
280+ ### Response if returning a new token
281+
282+ <%= headers 201, : Location => "https://api.github.com/authorizations/1 "
283+ %>
284+ <%= json : oauth_access %>
285+
286+ ### Response if returning an existing token
287+
288+ <%= headers 200, : Location => "https://api.github.com/authorizations/1 "
289+ %>
290+ <%= json : oauth_access %>
291+
248292## Update an existing authorization
249293
250294 PATCH /authorizations/:id
@@ -289,7 +333,7 @@ You can only send one of these scope keys at a time.
289333OAuth applications can use a special API method for checking OAuth token
290334validity without running afoul of normal rate limits for failed login attempts.
291335Authentication works differently with this particular endpoint. You must use
292- Basic Authentication when accessing it, where the username is the OAuth
336+ [ Basic Authentication] ( /v3/auth#basic-authentication ) when accessing it, where the username is the OAuth
293337application ` client_id ` and the password is its ` client_secret ` . Invalid tokens
294338will return ` 404 NOT FOUND ` .
295339
@@ -300,7 +344,6 @@ will return `404 NOT FOUND`.
300344<%= headers 200 %>
301345<%= json(: oauth_access_with_user ) %>
302346
303-
304347## More Information
305348
306349
0 commit comments