houdini/client/js/common/google-api.js
Bradley M. Kuhn fc77ee76d6 Relicense Javascript code in accordance with project's new license
The primary license of the project is changing to:
  AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later

The Additional Permission is designed to permit publicly distributed
Javascript code to be relicensed under LGPL-3.0-or-later, but not server-side
Javascript code.  As such, we've relicensed here static Javscript files under
LGPL-3.0-or-later, and those that run as part of build and/or server side
under AGPL-3.0-or-later.

Note that in future, Javascript files may be updated to be stronger copyleft
license with the Additional Permission, particularly if they adapted to run
on server side and/or turned into templates.  Of course, we'd seek public
discussion with the contributor community about such changes.

This commit is one of the many steps to relicense the entire codebase.

Documentation granting permission for this relicensing (from all past
contributors who hold copyrights) is on file with Software Freedom
Conservancy, Inc.
2018-03-25 15:10:40 -04:00

49 lines
1.4 KiB
JavaScript

// License: LGPL-3.0-or-later
const flyd = require('flyd')
const filter = require('flyd/module/filter')
const R = require('ramda')
var googz = {}
// loads client API and returns a true stream if user is already signed in
googz.init = scope => {
if(document.getElementById('googzAuthApi')) return
var script = document.createElement('script')
script.type = 'text/javascript'
script.id = 'googzAuthApi'
document.body.appendChild(script)
script.src = 'https://apis.google.com/js/api.js?onload=loadGoogleClientLib'
const isSignedIn$ = flyd.stream()
window.loadGoogleClientLib = _ => {
gapi.load('client:auth2', _ => {
gapi.client.setApiKey(app.google_api)
gapi.auth2.init(
{'client_id': app.google_auth_client_id
, 'scope': scope}
).then(_ => {
isSignedIn$(gapi.auth2.getAuthInstance().isSignedIn.get())
})
})
}
return isSignedIn$
}
// returns a stream that will have a value once the user has signed in
googz.signIn = _ => {
const isSigningIn$ = flyd.stream()
gapi.auth2.getAuthInstance().signIn().then(isSigningIn$)
return isSigningIn$
}
// returns a stream with the email of the signed in user
googz.email = _ => {
const email$ = flyd.stream()
var profile = gapi.auth2.getAuthInstance()
var email = profile.currentUser.get().getBasicProfile().getEmail()
return email$(email)
}
module.exports = googz