summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKjetil Orbekk <kjetil.orbekk@gmail.com>2015-10-09 22:16:45 -0400
committerKjetil Orbekk <kjetil.orbekk@gmail.com>2015-10-09 22:16:45 -0400
commitef0157b13676c05c6c4e64b0d95cdb69053afb48 (patch)
treef7f7587b5b36fe1034208dbf5bf8ae4cc642bad8
parent1c6cf15cb9ad7663d12f4cea6600a7929d333dee (diff)
Add token code (html part not working yet).
-rw-r--r--src/Main.hs3
-rw-r--r--web/index.html31
2 files changed, 24 insertions, 10 deletions
diff --git a/src/Main.hs b/src/Main.hs
index fcdf9ea..75995fc 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -58,7 +58,8 @@ server = albums
rename (RenameRequest from to) = liftIO $
runEitherT (renameAlbum config from to)
- test token = return ()
+ test (Just token) = liftIO (putStrLn $ "Got token: " ++ token)
+ test _ = left err503 { errBody = "Not authenticated" }
photoApi :: Proxy PhotoApi
photoApi = Proxy
diff --git a/web/index.html b/web/index.html
index d1819b0..a8e28a8 100644
--- a/web/index.html
+++ b/web/index.html
@@ -105,22 +105,35 @@
var id_token = googleUser.getAuthResponse().id_token;
console.log("ID Token: " + id_token);
$('.g-signin2').remove();
- };
-
- $(document).ready(function() {
- fetchAlbums();
$.ajax({
url: '/api/test',
- type: 'GET',
- headers: {"X-Token": "foo"},
+ headers: {'X-Token:': id_token},
+ beforeSend: function(request) {
+ request.setRequestHeader('Token', id_token);
+ },
success: function(data) {
- console.log("Success. got response " + data);
+ console.log('Success:', data);
},
error: function(data) {
- console.log("Success. got response " + data);
+ console.log('Failure:', data);
}
});
- });
+ };
+
+ // $(document).ready(function() {
+ // fetchAlbums();
+ // $.ajax({
+ // url: '/api/test',
+ // type: 'GET',
+ // headers: {"X-Token": "foo"},
+ // success: function(data) {
+ // console.log("Success. got response " + data);
+ // },
+ // error: function(data) {
+ // console.log("Success. got response " + data);
+ // }
+ // });
+ // });
</script>
</head>
<body>