Skip to content

Instantly share code, notes, and snippets.

@YuriFontella
Last active January 9, 2018 03:41
Show Gist options
  • Select an option

  • Save YuriFontella/2c993aefebebfdaa1e7c84b649e0d257 to your computer and use it in GitHub Desktop.

Select an option

Save YuriFontella/2c993aefebebfdaa1e7c84b649e0d257 to your computer and use it in GitHub Desktop.
gapi auth2
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