diff options
author | Igor Pashev <pashev.igor@gmail.com> | 2016-10-27 22:57:34 +0300 |
---|---|---|
committer | Igor Pashev <pashev.igor@gmail.com> | 2016-11-19 23:29:43 +0300 |
commit | 4a9f329a6ea9bfa03352ca0d9dd1d556b93bec36 (patch) | |
tree | ec49e853364a61eb4c7c64b5f13b0153d21a4cc1 /src/Sproxy/Application/OAuth2/Common.hs | |
download | sproxy2-4a9f329a6ea9bfa03352ca0d9dd1d556b93bec36.tar.gz |
Initial release (1.90.0)1.90.0
Diffstat (limited to 'src/Sproxy/Application/OAuth2/Common.hs')
-rw-r--r-- | src/Sproxy/Application/OAuth2/Common.hs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/Sproxy/Application/OAuth2/Common.hs b/src/Sproxy/Application/OAuth2/Common.hs new file mode 100644 index 0000000..07fb759 --- /dev/null +++ b/src/Sproxy/Application/OAuth2/Common.hs @@ -0,0 +1,39 @@ +{-# LANGUAGE OverloadedStrings #-} +module Sproxy.Application.OAuth2.Common ( + AccessTokenBody(..) +, OAuth2Client(..) +, OAuth2Provider +) where + +import Control.Applicative (empty) +import Data.Aeson (FromJSON, parseJSON, Value(Object), (.:)) +import Data.ByteString(ByteString) + +import Sproxy.Application.Cookie (AuthUser) + +data OAuth2Client = OAuth2Client { + oauth2Description :: String +, oauth2AuthorizeURL + :: ByteString -- state + -> ByteString -- redirect url + -> ByteString +, oauth2Authenticate + :: ByteString -- code + -> ByteString -- redirect url + -> IO AuthUser +} + +type OAuth2Provider = (ByteString, ByteString) -> OAuth2Client + +-- | RFC6749. We ignore optional token_type ("Bearer" from Google, omitted by LinkedIn) +-- and expires_in because we don't use them, *and* expires_in creates troubles: +-- it's an integer from Google and string from LinkedIn (sic!) +data AccessTokenBody = AccessTokenBody { + accessToken :: String +} deriving (Eq, Show) + +instance FromJSON AccessTokenBody where + parseJSON (Object v) = AccessTokenBody + <$> v .: "access_token" + parseJSON _ = empty + |