This repository has been archived by the owner on Oct 7, 2021. It is now read-only.
/
google-signin-component.ts
63 lines (55 loc) · 2.09 KB
/
google-signin-component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import {Component, ElementRef, AfterViewInit} from '@angular/core';
import { AwsService } from '../app/aws.service';
import { Callback } from '../app/aws.service';
declare const gapi: any;
@Component({
selector: 'google-signin',
template: '<md-radio-button class="radio-button" id="google" value="google">Google</md-radio-button>'
})
export class GoogleSigninComponent implements AfterViewInit {
//private clientId:string = '738519485992-fte4vuk3jeu03mme7lr93i69htgluq1e.apps.googleusercontent.com';
clientId:string = this.awsService.googleId;
private scope = [
'profile',
'email',
'https://www.googleapis.com/auth/plus.me',
'https://www.googleapis.com/auth/contacts.readonly',
'https://www.googleapis.com/auth/admin.directory.user.readonly'
].join(' ');
public auth2: any;
public googleInit() {
gapi.load('auth2', () => {
this.auth2 = gapi.auth2.init({
client_id: this.clientId,
cookiepolicy: 'single_host_origin',
scope: this.scope
});
this.attachSignin(this.element.nativeElement.firstChild);
});
}
public attachSignin(element) {
this.auth2.attachClickHandler(element, {},
(googleUser) => {
let profile = googleUser.getBasicProfile();
//console.log('Token || ' + googleUser.getAuthResponse().id_token);
let authResponse = googleUser.getAuthResponse();
//console.log(authResponse);
console.log("Authenticated to Google!")
//console.log('ID: ' + JSON.stringify(profile));
this.awsService.authenticateGoogle(authResponse,this.awsService.region,profile,this);
this.awsService.authenticateGoogle(authResponse,this.awsService.region,profile,this);
}, function (error) {
console.log(JSON.stringify(error, undefined, 2));
});
}
constructor(private element: ElementRef, public awsService:AwsService) {
//console.log('ElementRef: ', this.element);
}
ngAfterViewInit() {
this.googleInit();
}
googleCallback(creds: any, profile: any) {
this.awsService.setGoogleCreds(creds);
this.awsService.setGoogleProfile(profile);
}
}