on develop help sign in
Create a token request to exhange authorization code with token.

Currently, the InstalledApplication module retrieves the authorization code from the user but when it tries to exchange that code for an oauth token it queries the wrong endpoint (accounts.google.com). It needs to query the endpoint to exchange tokens, not the original accounts endpoint. This is documented at https://developers.google.com/identity/protocols/OAuth2InstalledApp#handlingtheresponse.

commit08f919696438c7dd51db98fa38a79baaac907de3 authorDavid Tulig <david.tulig@gmail.com> dateTue 3 Jan 2017, 20:55 (10 years ago) parent2e5b492
2 files changed+13−1
gogol/src/Network/Google/Auth/InstalledApplication.hs+1−1 gogol/src/Network/Google/Internal/Auth.hs+12
gogol/src/Network/Google/Auth/InstalledApplication.hs+1−1
@@ -109,7 +109,7 @@ exchangeCode :: (MonadIO m, MonadCatch m)
109109 -> Manager
110110 -> m (OAuthToken s)
111111exchangeCode c n = refreshRequest $
112− accountsRequest
112+ tokenRequest
113113 { Client.requestBody = textBody $
114114 "grant_type=authorization_code"
115115 <> "&client_id=" <> toQueryParam (_clientId c)
gogol/src/Network/Google/Internal/Auth.hs+12
@@ -260,6 +260,18 @@ accountsRequest = Client.defaultRequest
260260 ]
261261 }
262262
263+tokenRequest :: Client.Request
264+tokenRequest = Client.defaultRequest
265+ { Client.host = "www.googleapis.com"
266+ , Client.port = 443
267+ , Client.secure = True
268+ , Client.method = "POST"
269+ , Client.path = "/oauth2/v4/token"
270+ , Client.requestHeaders =
271+ [ (hContentType, "application/x-www-form-urlencoded")
272+ ]
273+ }
274+
263275refreshRequest :: (MonadIO m, MonadCatch m)
264276 => Client.Request
265277 -> Logger