Skip to content

Instantly share code, notes, and snippets.

@msukmanowsky
Created January 28, 2018 19:26
Show Gist options
  • Save msukmanowsky/d737896a9c6ab45ed5075d19122181a9 to your computer and use it in GitHub Desktop.
Save msukmanowsky/d737896a9c6ab45ed5075d19122181a9 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>AuthTest</title>
</head>
<body>
<button id="sign_in_button">Sign in</button>
<script>
window.onGAPILoaded = function() {
const { gapi } = window
const GOOGLE_AUTH_SCOPES = [
'profile',
'email',
'https://www.googleapis.com/auth/analytics.readonly',
'https://www.googleapis.com/auth/webmasters.readonly',
].join(' ')
console.log('GOOGLE_AUTH_SCOPES', GOOGLE_AUTH_SCOPES)
const auth2 = gapi.auth2.init({
scope: GOOGLE_AUTH_SCOPES,
client_id: '...',
cookiepolicy: 'single_host_origin',
})
auth2.attachClickHandler(
document.querySelector('#sign_in_button'),
{
ux_mode: 'redirect',
redirect_uri: '...',
prompt: 'select_account',
},
(user) => {
console.log(user)
},
(error) => { console.error(error) }
)
}
</script>
<script src="https://apis.google.com/js/api:client.js?onload=onGAPILoaded"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment