1
+
2
+ // populate login url
3
+ document . getElementById ( "login_url" ) . href = "https://auth.v2.sondehub.org/oauth2/authorize?client_id=21dpr4kth8lonk2rq803loh5oa&response_type=token&scope=email+openid+phone&redirect_uri=" + window . location . protocol + "//" + window . location . host
4
+
5
+ // manage AWS cognito auth
6
+ if ( window . location . hash . indexOf ( "id_token" ) != - 1 ) {
7
+ console . log ( "Detected login" )
8
+ var args = window . location . hash . slice ( 1 )
9
+ var parms = new URLSearchParams ( args )
10
+ var id_token = parms . get ( "id_token" )
11
+ sessionStorage . setItem ( "id_token" , id_token )
12
+ }
13
+
14
+ // do AWS login
15
+ AWS . config . region = 'us-east-1' ;
16
+
17
+ AWS . config . credentials = new AWS . CognitoIdentityCredentials ( {
18
+ IdentityPoolId : 'us-east-1:55e43eac-9626-43e1-a7d2-bbc57f5f5aa9' ,
19
+ Logins : {
20
+ "cognito-idp.us-east-1.amazonaws.com/us-east-1_G4H7NMniM" : sessionStorage . getItem ( "id_token" )
21
+ }
22
+ } ) ;
23
+
24
+ AWS . config . credentials . get ( function ( ) {
25
+ // if this passes we update the login page to say logged in
26
+ if ( AWS . config . credentials . accessKeyId != undefined ) {
27
+ document . getElementById ( "login-prompt" ) . innerHTML = "Logged in. <a onclick='logout()'>Click here to logout</a>"
28
+ }
29
+ } ) ;
30
+
31
+ function logout ( ) {
32
+ logout_url = "https://auth.v2.sondehub.org/logout?client_id=21dpr4kth8lonk2rq803loh5oa&response_type=token&logout_uri=" + window . location . protocol + "//" + window . location . host
33
+ sessionStorage . removeItem ( "id_token" )
34
+ window . location = logout_url
35
+ }
36
+
37
+ function do_a_thing ( ) {
38
+
39
+
40
+
41
+ // this is what we'll use to do the updates
42
+ const lambda = new AWS . Lambda ( ) ;
43
+ const lambda_params = {
44
+ FunctionName : 'test' , /* required */
45
+ Payload : JSON . stringify ( { } )
46
+ } ;
47
+ lambda . invoke ( lambda_params , function ( err , data ) {
48
+ if ( err ) {
49
+ document . getElementById ( "payload-update-results" ) . textContent = err
50
+ } else {
51
+ document . getElementById ( "payload-update-results" ) . textContent = JSON . stringify ( data )
52
+ }
53
+ } )
54
+
55
+ }
0 commit comments