Skip to content

Commit 5ba9b4d

Browse files
author
xss
committed
WIP adding auth to the tracker
1 parent 5318db2 commit 5ba9b4d

File tree

4 files changed

+87
-0
lines changed

4 files changed

+87
-0
lines changed

build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ java -jar "../tools/yuicompressor-2.4.8.jar" --type=js --disable-optimizations -
2626
java -jar "../tools/yuicompressor-2.4.8.jar" --type=js --disable-optimizations --nomunge app.js >> mobile.js
2727
java -jar "../tools/yuicompressor-2.4.8.jar" --type=js --disable-optimizations --nomunge colour-map.js >> mobile.js
2828
java -jar "../tools/yuicompressor-2.4.8.jar" --type=js --disable-optimizations --nomunge format.js >> mobile.js
29+
java -jar "../tools/yuicompressor-2.4.8.jar" --type=js --disable-optimizations --nomunge auth.js >> mobile.js
2930

3031
#compile plot lib and config
3132
java -jar "../tools/yuicompressor-2.4.8.jar" --type=js --disable-optimizations --nomunge _jquery.flot.js >> init_plot.js

css/habitat-font.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,17 @@
7676
.icon-earth:before { content: "\f007"; }
7777
.icon-daylight:before { content: "\f008"; }
7878
.icon-settings:before { content: "\f010"; }
79+
.icon-user:before {
80+
content: "🔒";
81+
color: transparent;
82+
text-shadow: 0 0 0 white;
83+
line-height: 1;
84+
}
85+
86+
.icon-user {
87+
line-height: 1;
88+
}
7989

90+
.user {
91+
line-height: 1 !important;
92+
}

index.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<meta name="apple-mobile-web-app-capable" content="yes" />
1212
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
1313
<meta name="theme-color" content="#00a3d3" />
14+
<script src="https://sdk.amazonaws.com/js/aws-sdk-2.1130.0.min.js"></script>
1415
<link rel="apple-touch-icon" sizes="57x57" href="img/apple-touch-icon.png" />
1516
<link rel="apple-touch-icon" sizes="72x72" href="img/apple-touch-icon.png" />
1617
<link rel="apple-touch-icon" sizes="114x114" href="img/apple-touch-icon.png" />
@@ -42,6 +43,7 @@
4243
</div>
4344
<ol class="nav noselect">
4445
<li class="home"><i class="icon-habhub"></i></li>
46+
<li class="user"><i class="icon-user"></i></li>
4547
<li class="chasecar" style="display: none"><i class="icon-car"></i></li>
4648
<li class="settings"><i class="icon-settings"></i></li>
4749
<li class="weather">
@@ -264,6 +266,22 @@ <h2><i class="icon-car rfloat"></i>Chase Mode</h2>
264266
<hr>
265267
</div>
266268
</div>
269+
<div id="userbox" style="display: none" class="flatpage">
270+
<div class="slimContainer">
271+
<h2><i class="icon-user rfloat"></i>User</h2>
272+
<hr>
273+
<p id="login-prompt">
274+
<a href="" id="login_url">Click here to login.</a>
275+
</p>
276+
<p>
277+
<a onclick="do_a_thing()">Click here to do a thing</a>
278+
</p>
279+
<p id="payload-update-results">
280+
</p>
281+
282+
283+
</div>
284+
</div>
267285
<div id="homebox" style="width:0px;height:0px"></div>
268286
<div id="mapscreen">
269287
<div id="timebox" class="present slickbox animate" style="display: none">

js/auth.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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

Comments
 (0)