diff options
author | Kjetil Orbekk <kjetil.orbekk@gmail.com> | 2015-10-11 13:51:32 -0400 |
---|---|---|
committer | Kjetil Orbekk <kjetil.orbekk@gmail.com> | 2015-10-11 13:51:32 -0400 |
commit | e9ea90182193cb6a813244bc676a8fe2f573fa29 (patch) | |
tree | d0e8abc7fc6966e381eae897ab7cf1bfdc113a26 /src/Authentication.hs | |
parent | 181b9f8beb296dbeef1739d4212ab2c3b8667756 (diff) |
Add Authentication module.
Diffstat (limited to 'src/Authentication.hs')
-rw-r--r-- | src/Authentication.hs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/Authentication.hs b/src/Authentication.hs new file mode 100644 index 0000000..2908309 --- /dev/null +++ b/src/Authentication.hs @@ -0,0 +1,31 @@ +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE TypeOperators #-} +{-# LANGUAGE TemplateHaskell #-} +module Authentication (User, queryUser) where + +import Data.Aeson +import GHC.Generics +import Network.HTTP.Conduit +import Data.ByteString.Lazy.Char8 (unpack) +import Control.Exception + +makeUrl = ("https://www.googleapis.com/oauth2/v3/tokeninfo?id_token="++) + +data User = User + { email :: String + , name :: String + } deriving (Eq, Show, Generic) + +instance FromJSON User + +queryUser :: String -> IO (Maybe User) +queryUser token = (queryUser' token) `catch` \e -> do + print (e :: HttpException) + return Nothing + +queryUser' token = do + response <- simpleHttp (makeUrl token) + return (decode response) |