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 | |
} |
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
login
parameter, it prompts users with a specific account they can use for signing in and authorizing your app.Parameters
client_id
string
redirect_uri
string
login
string
scope
string
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 withrepo
scope, a third web flow that does not provide ascope
will receive a token withuser
andrepo
scope.state
string
allow_signup
string
true
. Usefalse
in the case that a policy prohibits signups.