Search code examples
oauth-2.0google-oauthandroid-youtube-api

Google Oauth 2.0 authentication for limited input device not working


I am trying to use a custom java application of mine to upload videos to my youtube account via an access limited device like a Raspberry pi running as a server.

For this I am using the Google Oauth 2.0 for limited input device as a reference.

Here I am facing following problem:

  1. After getting the Device code via following similar call (Step 2 from the link):

    POST /o/oauth2/device/code HTTP/1.1
    Host: accounts.google.com
    Content-Type: application/x-www-form-urlencoded
    
    client_id=1084945748469-eg34imk572gdhu83gj5p0an9fut6urp5.apps.googleusercontent.com&
    scope=https://www.googleapis.com/auth/youtube
    
  2. Google Oauth server responds with 'user_code' and 'verification_url' (Step 3 from the link):

    { "device_code" : "4/L9fTtLrhY96442SEuf1Rl3KLFg3y", "user_code" : "a9xfwk9c", "verification_url" : "http://www.google.com/device",
    "expires_in" : "1800" "interval" : 5, }

  3. Now I am giving the requisite permission by opening the url as responded by google server.

  4. Finally I am trying to get the access token from Google server (Step 4 from the link) by posting similar request:

POST /o/oauth2/token HTTP/1.1    
Host: accounts.google.com
Content-Type: application/x-www-form-urlencoded

client_id=1084945748469-eg34imk572gdhu83gj5p0an9fut6urp5.apps.googleusercontent.com&
client_secret=hDBmMRhz7eJRsM9Z2q1oFBSem&
code=4/YMSlR3fSCC1NtUh073DuZKTJJ3ss&
grant_type=http://oauth.net/grant_type/device/1.0

but instead of getting the 'access_token' as response I am getting the following :

Status Code:400 Response: {   "error" : "invalid_request", 
"error_description" : "Required parameter is missing: grant_type" }

Note : With or without url encoding, my problem stays the same.

Can someone please help me as to whether it's the Google Oauth 2.0 api is buggy or my request is faulty?

***************************************UPDATE*************************************

I tried the same steps with some alternative tools instead of my custom java application, so I tried Fiddler and curl, the surprise is as follows:

  1. All of the calls worked right as mentioned by Google Oauth 2.0 for limited input device for curl.

  2. Same issue was observed with Fiddler as was with my custom java app.

I am still unable to figure out the difference yet, still need help.

************UPDATE#2**************

Fiddler request:

(url encoded, obscured client secret)

(One can get oauth credentials (client_id and client_secret) by following this)

POST HTTP/1.1
https://accounts.google.com/o/oauth2/token?client_id=308065994473-ur9dd7003ajs6mvr5s4kqnugr6j8tsf2.apps.googleusercontent.com&client_secret=XXXXXXXXXXXXXXX&code=4%2FWR-qiTquqB0e4-0LCy0-7rZ2kkE2&grant_type=http%3A%2F%2Foauth.net%2Fgrant_type%2Fdevice%2F1.0

Content-Type: application/x-www-form-urlencoded

(non url encoded, obscured client secret)

POST HTTP/1.1
https://accounts.google.com/o/oauth2/token?client_id=308065994473-ur9dd7003ajs6mvr5s4kqnugr6j8tsf2.apps.googleusercontent.com&client_secret=XXXXXXXXXXXXXX&code=4/WR-qiTquqB0e4-0LCy0-7rZ2kkE2&grant_type=http://oauth.net/grant_type/device/1.0

Java code project is available at (maven project, check the test case for the Oauth calls):

https://docs.google.com/file/d/0B8ltWBtPF-DVMDZFNHNMZXpCQlk


Solution

  • The value is wrong, you should use grant_type=authorization_code as this says.