Last active
October 7, 2019 17:44
-
-
Save daliborgogic/00e81c0d71ae796dba6558aeeab11ce1 to your computer and use it in GitHub Desktop.
Request a user's GitHub identity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const uuid = require('uuid') | |
| const { | |
| GITHUB_CLIENT_ID = '#####', | |
| GITHUB_REDIRECT_URL = 'https://example.com/callback', | |
| GITHUB_SCOPE = 'user:email' | |
| } = process.env | |
| const authorize = `https://github.com/login/oauth/authorize` | |
| const states = [] | |
| module.exports = login => { | |
| const state = uuid.v4() | |
| states.push(state) | |
| let params = { | |
| client_id: GITHUB_CLIENT_ID, | |
| redirect_uri: GITHUB_REDIRECT_URL, | |
| scope: GITHUB_SCOPE, | |
| state | |
| } | |
| if (login) params.login = login | |
| const authorizeUrl = new URL(authorize) | |
| Object.keys(params).forEach(key => | |
| authorizeUrl.searchParams.append(key, params[key])) | |
| return authorizeUrl | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Request a user's GitHub identity
When your GitHub App specifies a
loginparameter, it prompts users with a specific account they can use for signing in and authorizing your app.Parameters
client_idstringredirect_uristringloginstringscopestringscopedefaults 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 withreposcope, a third web flow that does not provide ascopewill receive a token withuserandreposcope.statestringallow_signupstringtrue. Usefalsein the case that a policy prohibits signups.