1
1
// This is where it all goes :)
2
2
3
3
$ ( function ( ) {
4
+ sjcl . random . startCollectors ( ) ;
5
+
4
6
AWS . config . region = 'us-east-1' ;
5
7
AWS . config . credentials = new AWS . CognitoIdentityCredentials ( {
6
8
IdentityPoolId : 'us-east-1:04bf3f30-8ea2-44d5-961f-1b7f61450363' ,
9
+ Logins : { }
7
10
} ) ;
8
11
9
12
AWS . config . logger = console ;
10
13
11
14
console . log ( "Hello world." ) ;
12
15
13
- var identityId = AWS . config . credentials . identityId ;
14
-
15
- console . log ( identityId ) ;
16
-
17
16
AWS . config . credentials . get ( function ( ) {
18
- console . log ( "Got into credentials.get" ) ;
17
+ var identityId = AWS . config . credentials . identityId ;
18
+ console . log ( identityId ) ;
19
+
19
20
var syncClient = new AWS . CognitoSyncManager ( ) ;
20
21
syncClient . openOrCreateDataset ( 'rubyonrails.co.uk' , function ( err , dataset ) {
21
22
dataset . put ( 'hello' , 'World' , function ( err , record ) {
@@ -28,5 +29,78 @@ $(function() {
28
29
} ) ;
29
30
} ) ;
30
31
} ) ;
32
+
33
+ var poolData = {
34
+ UserPoolId : 'us-east-1_XRvr3oTui' ,
35
+ ClientId : '7bqasb3pgsgt5cduktgqqugrgd' ,
36
+ Paranoia : 7
37
+ } ;
38
+
39
+ var userPool = new AWSCognito . CognitoIdentityServiceProvider . CognitoUserPool ( poolData ) ;
40
+
41
+ var cognitoUser = userPool . getCurrentUser ( ) ;
42
+ if ( cognitoUser != null ) {
43
+ cognitoUser . getSession ( function ( err , result ) {
44
+ if ( result ) {
45
+ console . log ( 'You are now logged in.' ) ;
46
+ }
47
+ } ) ;
48
+ }
49
+
31
50
} ) ;
32
51
} ) ;
52
+
53
+ function statusChangeCallback ( response ) {
54
+ console . log ( 'statusChangeCallback' ) ;
55
+ console . log ( response ) ;
56
+
57
+ if ( response . status === 'connected' ) {
58
+ testAPI ( ) ;
59
+ } else if ( response . status === 'not_authorized' ) {
60
+ document . getElementById ( 'status' ) . innerHTML = 'Please log into this app' ;
61
+ } else {
62
+ document . getElementById ( 'status' ) . innerHTML = 'Please log into Facebook' ;
63
+ }
64
+ }
65
+
66
+ function checkLoginState ( ) {
67
+ FB . getLoginStatus ( function ( response ) {
68
+ statusChangeCallback ( response ) ;
69
+ } ) ;
70
+ }
71
+
72
+ function testAPI ( ) {
73
+ console . log ( 'Welcome! Fetching your information...' ) ;
74
+ FB . api ( '/me' , function ( response ) {
75
+ console . log ( 'Successful login for: ' + response . name ) ;
76
+ document . getElementById ( 'status' ) . innerHTML = 'Thanks for logging in, ' + response . name + '!' ;
77
+ } ) ;
78
+ }
79
+
80
+ function onSignIn ( googleUser ) {
81
+ var profile = googleUser . getBasicProfile ( ) ;
82
+ console . log ( "Google user information" ) ;
83
+ console . log ( profile ) ;
84
+
85
+ AWS . config . credentials . params . Logins [ 'accounts.google.com' ] = googleUser . getAuthResponse ( ) . id_token ;
86
+ AWS . config . credentials . expired = true ;
87
+
88
+ AWS . config . credentials . get ( function ( ) {
89
+ console . log ( "Credentials gotten for Google. identityId = " + AWS . config . credentials . identityId ) ;
90
+
91
+ var syncClient = new AWS . CognitoSyncManager ( ) ;
92
+ syncClient . openOrCreateDataset ( 'rubyonrails.co.uk' , function ( err , dataset ) {
93
+ dataset . put ( 'currentLogin' , 'Google' , function ( err , record ) {
94
+ dataset . put ( 'name' , profile . getName ( ) , function ( err , record ) {
95
+ dataset . put ( 'email' , profile . getEmail ( ) , function ( err , record ) {
96
+ dataset . synchronize ( {
97
+ onSuccess : function ( data , newRecords ) {
98
+ console . log ( 'Google profile synchronised.' ) ;
99
+ }
100
+ } ) ;
101
+ } ) ;
102
+ } ) ;
103
+ } ) ;
104
+ } ) ;
105
+ } ) ;
106
+ }
0 commit comments