Skip to content

Instantly share code, notes, and snippets.

{-# 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
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)
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
instance FromJSON (URIRef Absolute) where
parseJSON = parseJSON >>= either (fail . show) pure . (parseURI laxURIParserOptions)
data GrantErrorType =
GenericOAuthGrantError
| InvalidRequest
| UnauthorizedClient
| AccessDenied
| UnsupportedResponseType
| InvalidScope
| ServerError
| TemporarilyUnavailable
| InvalidClient
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
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
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)
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)
@reactormonk
reactormonk / em
Last active December 14, 2016 19:34
#!/usr/bin/bash
emacsclient -n -c "$@"