No longer in use. Archived for reference only.
Interactions for Google's web-based OAuth flow.
const html = require('bel')
const GOOGLE_CLIENT_ID = 'your client id!'
const google = require('@scriptollc/google-platform')(GOOGLE_CLIENT_ID)
function main (state, emit) {
return html`<div>
<p><button onclick=${logout}>log out</button></p>
<p>
<b>User logged in?</b><br>
<pre><code>${JSON.stringify(state.user, null, 2)}</pre></code>
</p>
${google.render(google.renderLogin(onLogin))}
</div>`
function onLogin (err, user) {
if (err) return console.log(err)
state.user = user
emit('render')
}
function logout (evt) {
google.renderLogout((err) => {
if (err) return console.log(err)
state.user = {}
emit('render')
})
evt.preventDefault()
}
}
Create a new instance of the Google web platform component. Will attach the correct
<meta>
tag to the <head>
of the page when invoked. You must provide a valid
Google client ID.
Render the placeholder <div>
element for Google to render into. When the div
has been rendered, it will request the platform script to be loaded into the page
and then call the provided postLoad
function.
Load the Google platform script in the page unless it's been loaded already. Mostly
useless by itself. This is called automatically by #render
Make the <div>
returned by #div()
into a Google login button. The callback
will be invoked when the user has either rejected or accepted the OAuth request
from Google.
Attempt to log the user out of their local account. This actually requires
rendering the <div>
into the page. This will not revoke the permissions scope
they provided, but just allow the user to not be logged in Google.
Copyright © 2017 Scripto, LLC. Apache-2.0