added newOAuth and newCredential
This commit is contained in:
parent
38c1fba4f0
commit
e33b3a8efb
@ -2,9 +2,9 @@
|
|||||||
{-# OPTIONS_GHC -Wall -fno-warn-orphans #-}
|
{-# OPTIONS_GHC -Wall -fno-warn-orphans #-}
|
||||||
module Web.Authenticate.OAuth
|
module Web.Authenticate.OAuth
|
||||||
( -- * Data types
|
( -- * Data types
|
||||||
OAuth(..), SignMethod(..), Credential(..), OAuthException(..),
|
OAuth(..), newOAuth, SignMethod(..), Credential(..), OAuthException(..),
|
||||||
-- * Operations for credentials
|
-- * Operations for credentials
|
||||||
emptyCredential, insert, delete, inserts,
|
newCredential, emptyCredential, insert, delete, inserts,
|
||||||
-- * Signature
|
-- * Signature
|
||||||
signOAuth, genSign,
|
signOAuth, genSign,
|
||||||
-- * Url & operation for authentication
|
-- * Url & operation for authentication
|
||||||
@ -43,17 +43,25 @@ import Data.Conduit.Blaze (builderToByteString)
|
|||||||
import Blaze.ByteString.Builder (Builder)
|
import Blaze.ByteString.Builder (Builder)
|
||||||
|
|
||||||
-- | Data type for OAuth client (consumer).
|
-- | Data type for OAuth client (consumer).
|
||||||
data OAuth = OAuth { oauthServerName :: String -- ^ Service name
|
-- The default values apply when you use 'newOAuth'
|
||||||
, oauthRequestUri :: String -- ^ URI to request temporary credential
|
data OAuth = OAuth { oauthServerName :: String -- ^ Service name (You MUST specify)
|
||||||
, oauthAccessTokenUri :: String -- ^ Uri to obtain access token
|
, oauthRequestUri :: String -- ^ URI to request temporary credential (You MUST specify)
|
||||||
, oauthAuthorizeUri :: String -- ^ Uri to authorize
|
, oauthAccessTokenUri :: String -- ^ Uri to obtain access token (You MUST specify)
|
||||||
, oauthSignatureMethod :: SignMethod -- ^ Signature Method
|
, oauthAuthorizeUri :: String -- ^ Uri to authorize (You MUST specify)
|
||||||
, oauthConsumerKey :: BS.ByteString -- ^ Consumer key
|
, oauthSignatureMethod :: SignMethod -- ^ Signature Method (default: 'HMACSHA1')
|
||||||
, oauthConsumerSecret :: BS.ByteString -- ^ Consumer Secret
|
, oauthConsumerKey :: BS.ByteString -- ^ Consumer key (You MUST specify)
|
||||||
, oauthCallback :: Maybe BS.ByteString -- ^ Callback uri to redirect after authentication
|
, oauthConsumerSecret :: BS.ByteString -- ^ Consumer Secret (You MUST specify)
|
||||||
, oauthRealm :: Maybe BS.ByteString -- ^ Optional authorization realm
|
, oauthCallback :: Maybe BS.ByteString -- ^ Callback uri to redirect after authentication (default: 'Nothing')
|
||||||
|
, oauthRealm :: Maybe BS.ByteString -- ^ Optional authorization realm (default: 'Nothing')
|
||||||
} deriving (Show, Eq, Ord, Read, Data, Typeable)
|
} deriving (Show, Eq, Ord, Read, Data, Typeable)
|
||||||
|
|
||||||
|
-- | Default value for OAuth datatype.
|
||||||
|
-- You must specify at least oauthServerName, URIs and Tokens.
|
||||||
|
newOAuth :: OAuth
|
||||||
|
newOAuth = OAuth { oauthSignatureMethod = HMACSHA1
|
||||||
|
, oauthCallback = Nothing
|
||||||
|
, oauthRealm = Nothing
|
||||||
|
}
|
||||||
|
|
||||||
-- | Data type for signature method.
|
-- | Data type for signature method.
|
||||||
data SignMethod = PLAINTEXT
|
data SignMethod = PLAINTEXT
|
||||||
@ -75,6 +83,12 @@ data Credential = Credential { unCredential :: [(BS.ByteString, BS.ByteString)]
|
|||||||
emptyCredential :: Credential
|
emptyCredential :: Credential
|
||||||
emptyCredential = Credential []
|
emptyCredential = Credential []
|
||||||
|
|
||||||
|
-- | Convenient function to create 'Credential' with OAuth Token and Token Secret.
|
||||||
|
newCredential :: BS.ByteString -- ^ value for oauth_token
|
||||||
|
-> BS.ByteString -- ^ value for oauth_token_secret
|
||||||
|
-> Credential
|
||||||
|
newCredential tok sec = Credential [("oauth_token", tok), ("oauth_token_secret", sec)]
|
||||||
|
|
||||||
token, tokenSecret :: Credential -> BS.ByteString
|
token, tokenSecret :: Credential -> BS.ByteString
|
||||||
token = fromMaybe "" . lookup "oauth_token" . unCredential
|
token = fromMaybe "" . lookup "oauth_token" . unCredential
|
||||||
tokenSecret = fromMaybe "" . lookup "oauth_token_secret" . unCredential
|
tokenSecret = fromMaybe "" . lookup "oauth_token_secret" . unCredential
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user