about summary refs log tree commit diff
path: root/website/sandbox/learnpianochords/src/server/Main.hs
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2020-08-08T16·55+0100
committerWilliam Carroll <wpcarro@gmail.com>2020-08-08T16·57+0100
commite8f35f0d10a1696ffa80e31434882287bea30fe3 (patch)
tree8d125f26cd6963dc49f048c7dae64a699233e5e3 /website/sandbox/learnpianochords/src/server/Main.hs
parent8a7a3b29a9413d634b8f8a71119cc54a6132df41 (diff)
Consume GoogleSignIn.validateJWT
TL;DR:
- Consume GoogleSignIn.validateJWT in the Handler for /verify
- Rename validation fn to validateJWT
- Prefer Text to String type
Diffstat (limited to 'website/sandbox/learnpianochords/src/server/Main.hs')
-rw-r--r--website/sandbox/learnpianochords/src/server/Main.hs13
1 files changed, 11 insertions, 2 deletions
diff --git a/website/sandbox/learnpianochords/src/server/Main.hs b/website/sandbox/learnpianochords/src/server/Main.hs
index 2d7120bd614c..67f9fd3aca59 100644
--- a/website/sandbox/learnpianochords/src/server/Main.hs
+++ b/website/sandbox/learnpianochords/src/server/Main.hs
@@ -7,10 +7,14 @@ module Main where
 import Servant
 import API
 import Control.Monad.IO.Class (liftIO)
+import GoogleSignIn (EncodedJWT(..), ValidationResult(..))
+import Data.String.Conversions (cs)
+import Utils
 
 import qualified Network.Wai.Handler.Warp as Warp
 import qualified Network.Wai.Middleware.Cors as Cors
 import qualified Types as T
+import qualified GoogleSignIn
 --------------------------------------------------------------------------------
 
 server :: Server API
@@ -18,8 +22,13 @@ server = verifyGoogleSignIn
   where
     verifyGoogleSignIn :: T.VerifyGoogleSignInRequest -> Handler NoContent
     verifyGoogleSignIn T.VerifyGoogleSignInRequest{..} = do
-      liftIO $ putStrLn $ "Received: " ++ idToken
-      pure NoContent
+    validationResult <- liftIO $ GoogleSignIn.validateJWT False (EncodedJWT idToken)
+    case validationResult of
+      Valid _ -> do
+        liftIO $ putStrLn "Sign-in valid! Let's create a session"
+        pure NoContent
+      err -> do
+        throwError err401 { errBody = err |> GoogleSignIn.explainResult |> cs }
 
 main :: IO ()
 main = do