I'm trying to get access to Google Drive API and I read documentation. My iOS app sends first request to ask for permission to endpoint https://accounts.google.com/o/oauth2/v2/auth.
User grants permission. I get a code. Next step is to authorization code for refresh and access tokens.
As for installed apps, I don't need to send client secret. In order to do that iOS app sends POST request to the endpoint:
https://www.googleapis.com/oauth2/v4/token
with headers:
Content-Type : application/x-www-form-urlencoded
body:
code={CODE_FROM_OAUTH_SERVER}&client_id={CLIENT_ID_FROM_CONSOLE}&redirect_uri={APP_BUNDLE_IDENTIFIER}:/code&grant_type=authorization_code
I get the response:
{
"error": "unsupported_grant_type",
"error_description": "Invalid grant_type: "
}
App is registered in Google console.
My question is am I doing something wrong?
Does not require the Authorization header, however the client ID of the registered client app must be supplied in the request. When refreshing an access token, there is no re-authentication of the user. Here's a sample endpoint configuration for generating an access token using a refresh token.
If your application needs access to a Google API beyond the lifetime of a single access token, it can obtain a refresh token. A refresh token allows your application to obtain new access tokens. Note: Save refresh tokens in secure long-term storage and continue to use them as long as they remain valid.
Google handles the user authentication, session selection, and user consent. The result is an authorization code, which the application can exchange for an access token and a refresh token. The application should store the refresh token for future use and use the access token to access a Google API.
If the user grants at least one permission, the Google Authorization Server sends your application an access token (or an authorization code that your application can use to obtain an access token) and a list of scopes of access granted by that token. If the user does not grant the permission, the server returns an error.
It is sending the specified data in a POST request to the HTTP server, same as when browser do when we fill a HTML form and do submit . This will cause to pass the data to the server using the content-type application/x-www-form-urlencoded
.
You should try by changing the way you pass the OAuth parameters like client_id
, ,redirect_uri
, grant_type
, etc.
Or should try making Native client of default type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With