This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {-# LANGUAGE TypeFamilies #-} | |
| module Network.OAuth.OAuth2.Services where | |
| import Network.OAuth.OAuth2.Internal | |
| import Network.HTTP.Conduit | |
| import qualified Network.HTTP.Types as HT | |
| import qualified Network.OAuth.OAuth2.TokenRequest as TokenRequest | |
| import qualified Network.OAuth.OAuth2.AuthorizationRequest as AuthorizationRequest | |
| import URI.ByteString |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| data Google | |
| data GoogleError = | |
| G1Err | |
| | G2Err | |
| class OAuth2Service a where | |
| exchangeTokenUrl :: OAuth2 -> [Scope] -> URI | |
| exchangeToken :: OAuth2-> ExchangeToken -> Manager -> IO (OAuth2Result TokenRequest.Errors OAuth2Token) | |
| accessResource :: OAuth2-> AccessToken -> Request -> Manager -> IO (OAuth2Result err result) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ParseJSONURI a where | |
| parseJSONURI :: BS.ByteString -> Either URIParseError (URIRef a) | |
| instance ParseJSONURI Absolute where | |
| parseJSONURI = parseURI laxURIParserOptions | |
| instance ParseJSONURI Relative where | |
| parseJSONURI = parseRelativeRef laxURIParserOptions | |
| instance ParseJSONURI a => FromJSON (URIRef a) where |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| instance FromJSON (URIRef Absolute) where | |
| parseJSON = parseJSON >>= either (fail . show) pure . (parseURI laxURIParserOptions) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| data GrantErrorType = | |
| GenericOAuthGrantError | |
| | InvalidRequest | |
| | UnauthorizedClient | |
| | AccessDenied | |
| | UnsupportedResponseType | |
| | InvalidScope | |
| | ServerError | |
| | TemporarilyUnavailable | |
| | InvalidClient |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| data GrantErrors = | |
| GenericOAuthGrantError | |
| { error :: Text | |
| , errorDescription :: Maybe Text | |
| , error_uri :: Maybe (URIRef Absolute) } | |
| | InvalidToken | |
| { errorDescription :: Maybe Text | |
| , error_uri :: Maybe (URIRef Absolute) } | |
| | InvalidRequest | |
| { errorDescription :: Maybe Text |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Control.Monad | |
| main = print "foo" | |
| data Free f a = Pure a | BindFree (f (Free f a)) | |
| instance Functor f => Functor (Free f) where | |
| fmap fun = liftM fun | |
| instance Functor f => Applicative (Free f) where |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| newtype AccessToken = AccessToken { atoken :: Text } deriving (Show) | |
| instance FromJSON AccessToken where | |
| parseJSON x = fmap AccessToken (parseJSON x) | |
| newtype RefreshToken = RefreshToken { rtoken :: Text } deriving (Show) | |
| instance FromJSON RefreshToken where | |
| parseJSON x = fmap RefreshToken (parseJSON x) | |
| newtype IdToken = IdToken { idtoken :: Text } deriving (Show) | |
| instance FromJSON IdToken where | |
| parseJSON x = fmap IdToken (parseJSON x) | |
| newtype ExchangeToken = ExchangeToken { extoken :: Text } deriving (Show) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| uriToRequest :: MonadThrow m => URIRef Absolute -> m Request | |
| uriToRequest uri = do | |
| ssl <- case (view (uriSchemeL . schemeBSL) uri) of | |
| "http" -> return False | |
| "https" -> return True | |
| s -> throwM $ InvalidUrlException (show uri) ("Invalid scheme: " ++ show s) | |
| let | |
| maybeModify sa ra = over ra . maybe id const . preview sa | |
| query = fmap (\(a, b) -> (a, Just b)) (view (queryL . queryPairsL) uri) | |
| hostL = (authorityL . _Just . authorityHostL . hostBSL) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/bash | |
| emacsclient -n -c "$@" |