From ef0157b13676c05c6c4e64b0d95cdb69053afb48 Mon Sep 17 00:00:00 2001 From: Kjetil Orbekk Date: Fri, 9 Oct 2015 22:16:45 -0400 Subject: Add token code (html part not working yet). --- src/Main.hs | 3 ++- web/index.html | 31 ++++++++++++++++++++++--------- 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); + // } + // }); + // }); -- cgit v1.2.3