on develop help sign in
Replacing ToText usage for authorisation calls
a1a5982Brendan Hay
gogol/src/Network/Google/Auth.hs+1−2
@@ -79,7 +79,6 @@ module Network.Google.Auth
79import Control.Concurrent
79import Control.Concurrent
80import Control.Monad.Catch (MonadCatch)
80import Control.Monad.Catch (MonadCatch)
81import Control.Monad.IO.Class (MonadIO (..))
81import Control.Monad.IO.Class (MonadIO (..))
82−import qualified Data.Text.Encoding as Text
83import Data.Time (getCurrentTime)
82import Data.Time (getCurrentTime)
84import GHC.TypeLits (Symbol)
83import GHC.TypeLits (Symbol)
85import Network.Google.Auth.ApplicationDefault
84import Network.Google.Auth.ApplicationDefault
@@ -184,6 +183,6 @@ authorize rq s l m = bearer <$> getToken s l m
184 bearer t = rq
183 bearer t = rq
185 { Client.requestHeaders =
184 { Client.requestHeaders =
186 ( hAuthorization
185 ( hAuthorization
187− , "Bearer " <> Text.encodeUtf8 (toText (_tokenAccess t))
186+ , toHeader (_tokenAccess t)
188 ) : Client.requestHeaders rq
187 ) : Client.requestHeaders rq
189 }
188 }
gogol/src/Network/Google/Auth/InstalledApplication.hs+7−7
@@ -40,7 +40,7 @@ formURL c = formURLWith c . allowScopes
40formURLWith :: OAuthClient -> [OAuthScope] -> Text
40formURLWith :: OAuthClient -> [OAuthScope] -> Text
41formURLWith c ss = accountsURL
41formURLWith c ss = accountsURL
42 <> "?response_type=code"
42 <> "?response_type=code"
43− <> "&client_id=" <> toText (_clientId c)
43+ <> "&client_id=" <> toQueryParam (_clientId c)
44 <> "&redirect_uri=" <> redirectURI
44 <> "&redirect_uri=" <> redirectURI
45 <> "&scope=" <> Text.decodeUtf8 (queryEncodeScopes ss)
45 <> "&scope=" <> Text.decodeUtf8 (queryEncodeScopes ss)
46
46
@@ -58,9 +58,9 @@ exchangeCode c n = refreshRequest $
58 accountsRequest
58 accountsRequest
59 { Client.requestBody = textBody $
59 { Client.requestBody = textBody $
60 "grant_type=authorization_code"
60 "grant_type=authorization_code"
61− <> "&client_id=" <> toText (_clientId c)
61+ <> "&client_id=" <> toQueryParam (_clientId c)
62− <> "&client_secret=" <> toText (_clientSecret c)
62+ <> "&client_secret=" <> toQueryParam (_clientSecret c)
63− <> "&code=" <> toText n
63+ <> "&code=" <> toQueryParam n
64 <> "&redirect_uri=" <> redirectURI
64 <> "&redirect_uri=" <> redirectURI
65 }
65 }
66
66
@@ -77,7 +77,7 @@ refreshToken c t = refreshRequest $
77 accountsRequest
77 accountsRequest
78 { Client.requestBody = textBody $
78 { Client.requestBody = textBody $
79 "grant_type=refresh_token"
79 "grant_type=refresh_token"
80− <> "&client_id=" <> toText (_clientId c)
80+ <> "&client_id=" <> toQueryParam (_clientId c)
81− <> "&client_secret=" <> toText (_clientSecret c)
81+ <> "&client_secret=" <> toQueryParam (_clientSecret c)
82− <> maybe mempty ("&refresh_token=" <>) (toText <$> _tokenRefresh t)
82+ <> maybe mempty ("&refresh_token=" <>) (toQueryParam <$> _tokenRefresh t)
83 }
83 }
gogol/src/Network/Google/Auth/ServiceAccount.hs+4−4
@@ -45,7 +45,7 @@ metadataToken :: (MonadIO m, MonadCatch m)
45metadataToken s = refreshRequest $
45metadataToken s = refreshRequest $
46 metadataRequest
46 metadataRequest
47 { Client.path = "instance/service-accounts/"
47 { Client.path = "instance/service-accounts/"
48− <> Text.encodeUtf8 (toText s)
48+ <> Text.encodeUtf8 (toQueryParam s)
49 <> "/token"
49 <> "/token"
50 }
50 }
51
51
@@ -62,9 +62,9 @@ authorizedUserToken u r = refreshRequest $
62 accountsRequest
62 accountsRequest
63 { Client.requestBody = textBody $
63 { Client.requestBody = textBody $
64 "grant_type=refresh_token"
64 "grant_type=refresh_token"
65− <> "&client_id=" <> toText (_userId u)
65+ <> "&client_id=" <> toQueryParam (_userId u)
66− <> "&client_secret=" <> toText (_userSecret u)
66+ <> "&client_secret=" <> toQueryParam (_userSecret u)
67− <> "&refresh_token=" <> toText (fromMaybe (_userRefresh u) r)
67+ <> "&refresh_token=" <> toQueryParam (fromMaybe (_userRefresh u) r)
68 }
68 }
69
69
70
70
gogol/src/Network/Google/Internal/Auth.hs+5−1
@@ -174,7 +174,11 @@ instance FromJSON (UTCTime -> OAuthToken) where
174 pure (OAuthToken t r . addUTCTime e)
174 pure (OAuthToken t r . addUTCTime e)
175
175
176newtype OAuthCode = OAuthCode Text
176newtype 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
178
182
179-- | An error thrown when attempting to read AuthN/AuthZ information.
183-- | An error thrown when attempting to read AuthN/AuthZ information.
180data AuthError
184data AuthError