Created
February 28, 2019 09:48
-
-
Save kohendrix/926ef7ec536b78a053a6567b01808dd9 to your computer and use it in GitHub Desktop.
Google sign-in url getter
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
| import { OAuth2Client } from 'google-auth-library'; | |
| const p = console.log; | |
| /** APIs Explorer for OAuth2 v1: https://developers.google.com/apis-explorer/#p/oauth2/v1/ **/ | |
| const infoUrl = 'https://www.googleapis.com/oauth2/v1/userinfo?alt=JSON'; | |
| /** | |
| * information scope needed | |
| * reference: https://developers.google.com/identity/protocols/googlescopes | |
| * check: Google OAuth2 API, v2 | |
| */ | |
| const scope = ['https://www.googleapis.com/auth/userinfo.email']; | |
| /** | |
| * this establishes the connection | |
| * @return { OAuth2Client } | |
| */ | |
| function getOAuth2Client() { | |
| return new OAuth2Client('YOUR_CLIENT_ID', 'YOUR_CLIENT_SECRET', 'REDIRECT_URL'); | |
| } | |
| /** | |
| * get the url for sign-in link | |
| * @param { OAuth2Client } client | |
| * @return { string } | |
| */ | |
| function getConnectionUrl(client) { | |
| return client.generateAuthUrl({ | |
| access_type: 'offline', | |
| prompt: 'consent', | |
| scope: scope | |
| }); | |
| } | |
| /** PUBLIC **/ | |
| /** | |
| * sso url | |
| * @return { string } | |
| */ | |
| function googleUrl() { | |
| return getConnectionUrl(getOAuth2Client()); | |
| } | |
| export { googleUrl }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment