Skip to content

Commit 3fecb89

Browse files
authored
feat: clientType option and different results for GitHub Apps and OAuth Apps (#129)
1 parent ac98fc9 commit 3fecb89

File tree

5 files changed

+338
-145
lines changed

5 files changed

+338
-145
lines changed

README.md

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@
77

88
See [GitHub’s Developer Guide for the OAuth App web application flow](https://developer.github.com/apps/building-oauth-apps/authorizing-oauth-apps/#web-application-flow). Note that the [OAuth web application flow for GitHub Apps](https://docs.github.com/en/developers/apps/identifying-and-authorizing-users-for-github-apps#web-application-flow) is slightly different. GitHub Apps do not support scopes for its user access tokens (they are called user-to-server tokens for GitHub Apps), instead they inherit the user permissions from the GitHub App's registration and the repository/organization access and permissions from the respective installation.
99

10+
<!-- toc -->
11+
12+
- [Usage](#usage)
13+
- [For OAuth Apps](#for-oauth-apps)
14+
- [For GitHub Apps](#for-github-apps)
15+
- [Options](#options)
16+
- [Result](#result)
17+
- [License](#license)
18+
19+
<!-- tocstop -->
20+
1021
## Usage
1122

1223
<table>
@@ -43,6 +54,8 @@ const { oauthAuthorizationUrl } = require("@octokit/oauth-authorization-url");
4354
</tbody>
4455
</table>
4556

57+
### For OAuth Apps
58+
4659
```js
4760
const {
4861
url,
@@ -52,6 +65,7 @@ const {
5265
scopes,
5366
state,
5467
} = oauthAuthorizationUrl({
68+
clientType: "oauth-app",
5569
clientId: "1234567890abcdef1234",
5670
redirectUrl: "https://example.com",
5771
login: "octocat",
@@ -60,6 +74,18 @@ const {
6074
});
6175
```
6276

77+
### For GitHub Apps
78+
79+
```js
80+
const { url, clientId, redirectUrl, login, state } = oauthAuthorizationUrl({
81+
clientType: "github-app",
82+
clientId: "lv1.1234567890abcdef",
83+
redirectUrl: "https://example.com",
84+
login: "octocat",
85+
state: "secret123",
86+
});
87+
```
88+
6389
## Options
6490

6591
<table>
@@ -82,6 +108,16 @@ const {
82108
<strong>Required</strong>. The client ID you received from GitHub when you registered.
83109
</td>
84110
</tr>
111+
<tr>
112+
<th>
113+
<code>clientType</code>
114+
</th>
115+
<td>
116+
117+
Must be set to either `"oauth-app"` or `"github-app"`. Defaults to `"oauth-app"`.
118+
119+
</td>
120+
</tr>
85121
<tr>
86122
<th>
87123
<code>redirectUrl</code>
@@ -103,8 +139,14 @@ const {
103139
<code>scopes</code>
104140
</th>
105141
<td>
106-
An array of scope names (or: space-delimited list of scopes). If not provided, scope defaults to an empty list for users that have not authorized any scopes for the application. For users who have authorized scopes for the application, the user won't be shown the OAuth authorization page with the list of scopes. Instead, this step of the flow will automatically complete with the set of scopes the user has authorized for the application. For example, if a user has already performed the web flow twice and has authorized one token with user scope and another token with repo scope, a third web flow that does not provide a scope will receive a token with user and repo scope.
107-
</td>
142+
143+
Only relevant when `clientType` is set to `"oauth-app"`.
144+
145+
An array of scope names (or: space-delimited list of scopes). If not provided, scope defaults to an empty list for users that have not authorized any scopes for the application. For users who have authorized scopes for the application, the user won't be shown the OAuth authorization page with the list of scopes. Instead, this step of the flow will automatically complete with the set of scopes the user has authorized for the application. For example, if a user has already performed the web flow twice and has authorized one token with user scope and another token with repo scope, a third web flow that does not provide a scope will receive a token with user and repo scope.
146+
147+
Defaults to `[]` if `clientType` is set to `"oauth-app"`.
148+
149+
</td>
108150
</tr>
109151
<tr>
110152
<th>
@@ -120,7 +162,7 @@ const {
120162
<code>allowSignup</code>
121163
</th>
122164
<td>
123-
Whether or not unauthenticated users will be offered an option to sign up for GitHub during the OAuth flow. The default is <code>true</code>. Use <code>false</code> in the case that a policy prohibits signups.
165+
Whether or not unauthenticated users will be offered an option to sign up for GitHub during the OAuth flow. Use <code>false</code> in the case that a policy prohibits signups. Defaults to <code>true</code>.
124166
</td>
125167
</tr>
126168
<tr>
@@ -158,6 +200,14 @@ const {
158200
Returns <code>options.allowSignup</code> if it was set. Defaults to <code>true</code>.
159201
</td>
160202
</tr>
203+
<tr>
204+
<th>
205+
<code>clientType</code>
206+
</th>
207+
<td>
208+
Returns <code>options.clientType</code>. Defaults to <code>"oauth-app"</code>.
209+
</td>
210+
</tr>
161211
<tr>
162212
<th>
163213
<code>clientId</code>
@@ -187,8 +237,12 @@ const {
187237
<code>scopes</code>
188238
</th>
189239
<td>
190-
Always returns an array of strings. Returns <code>options.scopes</code> if it was set and turns the string into an array if a string was passed. Defaults to <code>[]</code>.
191-
</td>
240+
241+
Only set if `options.clientType` is set to `"oauth-app"`.
242+
243+
Returns an array of strings. Returns <code>options.scopes</code> if it was set and turns the string into an array if a string was passed, otherwise <code>[]</code>.
244+
245+
</td>
192246
</tr>
193247
<tr>
194248
<th>

0 commit comments

Comments
 (0)