Last active
January 9, 2018 03:41
-
-
Save YuriFontella/2c993aefebebfdaa1e7c84b649e0d257 to your computer and use it in GitHub Desktop.
gapi auth2
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 { Injectable } from '@angular/core'; | |
| declare const gapi: any; | |
| @Injectable() | |
| export class GoogleService { | |
| constructor() { } | |
| authenticateUser(callback) { | |
| let auth2: any; | |
| gapi.load('auth2', function () { | |
| auth2 = gapi.auth2.init({ | |
| client_id: 'apps.googleusercontent.com', | |
| cookiepolicy: 'single_host_origin', | |
| scope: 'profile email' | |
| }); | |
| auth2.attachClickHandler(document.getElementById('google-login-button'), {}, | |
| function (response) { | |
| const profile = response.getBasicProfile(); | |
| const result = { | |
| uid: profile.getId(), | |
| name: profile.getName(), | |
| image: profile.getImageUrl(), | |
| provider: 'google', | |
| email: profile.getEmail(), | |
| }; | |
| callback(result); | |
| }); | |
| }); | |
| }; | |
| logout() { | |
| const home = window.location.href; | |
| const logout = 'https://www.google.com/accounts/Logout?continue=https://appengine.google.com/_ah/logout?continue=' + home; | |
| document.location.href = logout; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment