Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Christopher League
bookme
Commits
feb20b30
Commit
feb20b30
authored
May 23, 2018
by
Christopher League
Browse files
Authorization program complete
parent
86fcf897
Changes
3
Hide whitespace changes
Inline
Side-by-side
.gitignore
View file @
feb20b30
...
...
@@ -19,3 +19,6 @@ cabal.sandbox.config
*~
\#*
bookme.cabal
/TAGS
/deps.png
/devenv.sh
package.yaml
View file @
feb20b30
...
...
@@ -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
...
...
src/Settings/Auth.hs
View file @
feb20b30
{-# 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
$
"
\n
To authorize w/Google, open the following URL:
\n\n
"
<>
formURL
oac
calendarScope
<>
"
\n\n
Then 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
$
"
\n
Add this to your environment:
\n\n
"
<>
"export "
<>
varGoogleRefreshToken
<>
"="
<>
tok
<>
"
\n
"
Nothing
->
putStrLn
"Hmm, didn't get refresh token."
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment