on develop help sign in
Replacing ToText usage for authorisation calls
commita1a59824f7c5a6029a119d120f1b948c452f8674 authorBrendan Hay <brendan.g.hay@gmail.com> dateTue 10 May 2016, 17:32 (10 years ago) parent90016c1
4 files changed+17−14
gogol/src/Network/Google/Auth.hs+1−2 gogol/src/Network/Google/Auth/InstalledApplication.hs+7−7 gogol/src/Network/Google/Auth/ServiceAccount.hs+4−4 gogol/src/Network/Google/Internal/Auth.hs+5−1
gogol/src/Network/Google/Auth.hs+1−2
@@ -79,7 +79,6 @@ module Network.Google.Auth
7979import Control.Concurrent
8080import Control.Monad.Catch (MonadCatch)
8181import Control.Monad.IO.Class (MonadIO (..))
82−import qualified Data.Text.Encoding as Text
8382import Data.Time (getCurrentTime)
8483import GHC.TypeLits (Symbol)
8584import Network.Google.Auth.ApplicationDefault
@@ -184,6 +183,6 @@ authorize rq s l m = bearer <$> getToken s l m
184183 bearer t = rq
185184 { Client.requestHeaders =
186185 ( hAuthorization
187− , "Bearer " <> Text.encodeUtf8 (toText (_tokenAccess t))
186+ , toHeader (_tokenAccess t)
188187 ) : Client.requestHeaders rq
189188 }
gogol/src/Network/Google/Auth/InstalledApplication.hs+7−7
@@ -40,7 +40,7 @@ formURL c = formURLWith c . allowScopes
4040formURLWith :: OAuthClient -> [OAuthScope] -> Text
4141formURLWith c ss = accountsURL
4242 <> "?response_type=code"
43− <> "&client_id=" <> toText (_clientId c)
43+ <> "&client_id=" <> toQueryParam (_clientId c)
4444 <> "&redirect_uri=" <> redirectURI
4545 <> "&scope=" <> Text.decodeUtf8 (queryEncodeScopes ss)
4646
@@ -58,9 +58,9 @@ exchangeCode c n = refreshRequest $
5858 accountsRequest
5959 { Client.requestBody = textBody $
6060 "grant_type=authorization_code"
61− <> "&client_id=" <> toText (_clientId c)
62− <> "&client_secret=" <> toText (_clientSecret c)
63− <> "&code=" <> toText n
61+ <> "&client_id=" <> toQueryParam (_clientId c)
62+ <> "&client_secret=" <> toQueryParam (_clientSecret c)
63+ <> "&code=" <> toQueryParam n
6464 <> "&redirect_uri=" <> redirectURI
6565 }
6666
@@ -77,7 +77,7 @@ refreshToken c t = refreshRequest $
7777 accountsRequest
7878 { Client.requestBody = textBody $
7979 "grant_type=refresh_token"
80− <> "&client_id=" <> toText (_clientId c)
81− <> "&client_secret=" <> toText (_clientSecret c)
82− <> maybe mempty ("&refresh_token=" <>) (toText <$> _tokenRefresh t)
80+ <> "&client_id=" <> toQueryParam (_clientId c)
81+ <> "&client_secret=" <> toQueryParam (_clientSecret c)
82+ <> maybe mempty ("&refresh_token=" <>) (toQueryParam <$> _tokenRefresh t)
8383 }
gogol/src/Network/Google/Auth/ServiceAccount.hs+4−4
@@ -45,7 +45,7 @@ metadataToken :: (MonadIO m, MonadCatch m)
4545metadataToken s = refreshRequest $
4646 metadataRequest
4747 { Client.path = "instance/service-accounts/"
48− <> Text.encodeUtf8 (toText s)
48+ <> Text.encodeUtf8 (toQueryParam s)
4949 <> "/token"
5050 }
5151
@@ -62,9 +62,9 @@ authorizedUserToken u r = refreshRequest $
6262 accountsRequest
6363 { Client.requestBody = textBody $
6464 "grant_type=refresh_token"
65− <> "&client_id=" <> toText (_userId u)
66− <> "&client_secret=" <> toText (_userSecret u)
67− <> "&refresh_token=" <> toText (fromMaybe (_userRefresh u) r)
65+ <> "&client_id=" <> toQueryParam (_userId u)
66+ <> "&client_secret=" <> toQueryParam (_userSecret u)
67+ <> "&refresh_token=" <> toQueryParam (fromMaybe (_userRefresh u) r)
6868 }
6969
7070
gogol/src/Network/Google/Internal/Auth.hs+5−1
@@ -174,7 +174,11 @@ instance FromJSON (UTCTime -> OAuthToken) where
174174 pure (OAuthToken t r . addUTCTime e)
175175
176176newtype OAuthCode = OAuthCode Text
177− deriving (Eq, Ord, Show, Read, IsString, Generic, Typeable, ToText, FromJSON, ToJSON)
177+ deriving (Eq, Ord, Show, Read, IsString, Generic, Typeable, FromJSON, ToJSON)
178+
179+instance ToHttpApiData OAuthCode where
180+ toQueryParam (OAuthCode c) = c
181+ toHeader (OAuthCode c) = "Bearer " <> Text.encodeUtf8 c
178182
179183-- | An error thrown when attempting to read AuthN/AuthZ information.
180184data AuthError