Commit feb20b30 authored by Christopher League's avatar Christopher League 🖥
Browse files

Authorization program complete

parent 86fcf897
......@@ -19,3 +19,6 @@ cabal.sandbox.config
*~
\#*
bookme.cabal
/TAGS
/deps.png
/devenv.sh
......@@ -23,9 +23,9 @@ dependencies:
- gogol >=0.3.0 && <0.4
- gogol-apps-calendar >=0.3.0 && <0.4
- hjsmin >=0.1 && <0.3
- http-types
- http-client-tls >=0.3 && <0.4
- http-conduit >=2.3 && <2.4
- http-types
- lens
- monad-control >=0.3 && <1.1
- monad-logger >=0.3 && <0.4
......
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-|
Module: Settings.Auth
Description: TODO
......@@ -10,8 +14,50 @@ module Settings.Auth
( authorizeMain
) where
import Import
import Import
import Network.Google
import Network.Google.AppsCalendar
import Network.Google.Auth
import Network.HTTP.Client.TLS (tlsManagerSettings)
import System.Environment (getEnv)
varGoogleClientId :: IsString s => s
varGoogleClientId = "BOOKME_GOOGLE_ID"
varGoogleSecret :: IsString s => s
varGoogleSecret = "BOOKME_GOOGLE_SECRET"
varGoogleRefreshToken :: IsString s => s
varGoogleRefreshToken = "BOOKME_GOOGLE_REFRESH"
oauthClientFromEnv :: IO OAuthClient
oauthClientFromEnv =
OAuthClient <$> (ClientId . pack <$> getEnv varGoogleClientId) <*>
(Secret . pack <$> getEnv varGoogleSecret)
type CalendarScope = '[ "https://www.googleapis.com/auth/calendar"]
authorizeMain :: IO ()
authorizeMain =
putStrLn "Hello world"
authorizeMain = do
oac <- oauthClientFromEnv
codeOpt <- headMay <$> getArgs
case codeOpt of
Nothing ->
putStr $
"\nTo authorize w/Google, open the following URL:\n\n" <>
formURL oac calendarScope <>
"\n\nThen run again with code as first argument.\n"
Just code -> do
let creds = FromClient oac (OAuthCode code) :: Credentials CalendarScope
mgr <- newManagerSettings tlsManagerSettings
lgr <- newLogger Error stdout
auth <- exchange creds lgr mgr
case _tokenRefresh (_token auth) of
Just (RefreshToken tok) ->
putStr $
"\nAdd this to your environment:\n\n" <> "export " <>
varGoogleRefreshToken <>
"=" <>
tok <>
"\n"
Nothing -> putStrLn "Hmm, didn't get refresh token."
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment