Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Network/Wreq.hs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ module Network.Wreq
, AWSAuthVersion(..)
, Lens.auth
, basicAuth
, oauth1Auth
, oauth2Bearer
, oauth2Token
, awsAuth
Expand Down Expand Up @@ -460,6 +461,16 @@ basicAuth :: S.ByteString -- ^ Username.
-> Auth
basicAuth = BasicAuth

-- | OAuth1 authentication. This consists of a consumer token,
-- a consumer secret, a token and a token secret
oauth1Auth :: S.ByteString -- ^ Consumer token
-> S.ByteString -- ^ Consumer secret
-> S.ByteString -- ^ OAuth token
-> S.ByteString -- ^ OAuth token secret
-> Auth
oauth1Auth = OAuth1


-- | An OAuth2 bearer token. This is treated by many services as the
-- equivalent of a username and password.
--
Expand Down
4 changes: 4 additions & 0 deletions Network/Wreq/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import qualified Network.HTTP.Client as HTTP
import qualified Network.HTTP.Types as HTTP
import qualified Network.Wreq.Internal.Lens as Lens
import qualified Network.Wreq.Internal.AWS as AWS (signRequest)
import qualified Network.Wreq.Internal.OAuth1 as OAuth1 (signRequest)
import qualified Network.Wreq.Lens as Lens hiding (checkStatus)

-- This mess allows this module to continue to load during interactive
Expand Down Expand Up @@ -117,8 +118,10 @@ prepare modify opts url = do
signRequest = maybe return f $ auth opts
where
f (AWSAuth versn key secret) = AWS.signRequest versn key secret
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[bos wrote] While you're at it, please also fix that API mistake for the AWS code in a separate commit

We're not passing the auth record to AWS.signRequest, but only the constituent parts. What could I do better here?

f (OAuth1 consumerToken consumerSecret token secret) = OAuth1.signRequest consumerToken consumerSecret token secret
f _ = return


setQuery :: Options -> Request -> Request
setQuery opts =
case params opts of
Expand All @@ -136,6 +139,7 @@ setAuth = maybe id f . auth
f (OAuth2Token token) = setHeader "Authorization" ("token " <> token)
-- for AWS request signature, see Internal/AWS
f (AWSAuth _ _ _) = id
f (OAuth1 _ _ _ _) = id

setProxy :: Options -> Request -> Request
setProxy = maybe id f . proxy
Expand Down
12 changes: 12 additions & 0 deletions Network/Wreq/Internal/OAuth1.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Network.Wreq.Internal.OAuth1 (signRequest) where

import Network.HTTP.Client (Request(..))
import Web.Authenticate.OAuth ( signOAuth, newOAuth, oauthConsumerKey
, oauthConsumerSecret, newCredential)
import qualified Data.ByteString as S

signRequest :: S.ByteString -> S.ByteString -> S.ByteString -> S.ByteString -> Request -> IO Request
signRequest consumerToken consumerSecret token tokenSecret = signOAuth app creds
where
app = newOAuth { oauthConsumerKey = consumerToken, oauthConsumerSecret = consumerSecret }
creds = newCredential token tokenSecret
3 changes: 3 additions & 0 deletions Network/Wreq/Internal/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ data Auth = BasicAuth S.ByteString S.ByteString
| AWSAuth AWSAuthVersion S.ByteString S.ByteString
-- ^ Amazon Web Services request signing
-- AWSAuthVersion key secret
| OAuth1 S.ByteString S.ByteString S.ByteString S.ByteString
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please document this field.

-- ^ OAuth1 request signing
-- OAuth1 consumerToken consumerSecret token secret
deriving (Eq, Show, Typeable)

data AWSAuthVersion = AWSv4
Expand Down
2 changes: 2 additions & 0 deletions wreq.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ library
Network.Wreq.Internal.AWS
Network.Wreq.Internal.Lens
Network.Wreq.Internal.Link
Network.Wreq.Internal.OAuth1
Network.Wreq.Internal.Types
Network.Wreq.Lens.Machinery
Network.Wreq.Lens.TH
Expand All @@ -90,6 +91,7 @@ library
PSQueue >= 1.1,
aeson >= 0.7.0.3,
attoparsec >= 0.11.1.0,
authenticate-oauth == 1.5.*,
base >= 4.5 && < 5,
base16-bytestring,
byteable,
Expand Down