0
votes

I was trying to write an UWP App in c++ (Visual Studio) for OAuth in to Google Drive API. I referred the notes from this project under Github - https://github.com/googlesamples/oauth-apps-for-windows/blob/master/OAuthUniversalApp/README.md

I was able to get the Authorization code from Google. But when I used the Authorization code to request for Authorization token then it is throwing me an error 404.

My Authorization token request URI looks like this -

https://googleapis.com/oauth2/v4/token?code=XXXXXXX#&client_id=ZZZZZZ&client_secret=YYYYYY&redirect_uri=uwapp.testgoogleoauth:/oauth2redirect&grant_type=authorization_code

Going by the notes mentioned in the link, I created the client ID using iOS application type. But I didnt get the client secret key at that step. I had to explicitly generate the client secret key again for the iOS application type.

Is there any issue which you see in the request URI being sent for the Authorization token request? What should be the value of client_secret to be used if the type of client has been selected as iOS in google console?

Thanks, /vikas

1

1 Answers

0
votes

Is there any issue which you see in the request URI being sent for the Authorization token request?

In you request URI you are using https://googleapis.com/oauth2/v4/token. However to make the token request, the correct token endpoint should be:

https://www.googleapis.com/oauth2/v4/token

And this is the reason why you get 404 (Not Found) error.

What should be the value of client_secret to be used if the type of client has been selected as iOS in google console?

In Handling the response and exchanging the code, we can find that

client_secret The client secret you obtained from the API Console (not applicable for clients registered as Android, iOS or Chrome applications).

So for iOS clients, there is no need to use client_secret. And as UWP is similar to iOS, we can also ignore this field in UWP.

The complete authorization token request might look like the following:

POST /oauth2/v4/token HTTP/1.1
Host: www.googleapis.com
Content-Type: application/x-www-form-urlencoded

code=XXXXXX&
client_id=ZZZZZZ&
redirect_uri=uwapp.testgoogleoauth:/oauth2redirect&
grant_type=authorization_code