error unsupported_grant_type with Doorkeeper device Authorization Request flow

427 views Asked by At

When I send the access token request (polling) I receive the error: "unsupported_grant_type" (see as follows).

Note: this is the second request in the device flow, the first request works. Both are shown below.

Step 1, Device Authorization Request: (works)

POST http://localhost:3000/oauth/authorize_device
Content-Type: application/x-www-form-urlencoded 

client_id=2DIJRT72IRMycyeBS7PuGgYSJScCQ9bxnvo5_JyyKOA

(I use Insomnia to create the request)

Device Authorization Response: (as expected)

{
    "device_code": "IB7tQi1yGv2QddCUurWBsics26MZ8aUY1sriudewRn4",
    "user_code": "WTQB0W6S",
    "verification_uri": "http://localhost:3000/oauth/device",
    "verification_uri_complete": "http://localhost:3000/oauth/device?user_code=WTQB0W6S",
    "expires_in": 300,
    "interval": 5
}

Step 2, Device Access Token Request / polling: (fails)

POST http://localhost:3000/oauth/token 
Content-Type: application/x-www-form-urlencoded

grant_type=urn:ietf:params:oauth:grant-type:device_code
&device_code=IB7tQi1yGv2QddCUurWBsics26MZ8aUY1sriudewRn4
&client_id=2DIJRT72IRMycyeBS7PuGgYSJScCQ9bxnvo5_JyyKOA

Device Access Token Response: (400 Bad Request)

{
    "error": "unsupported_grant_type",
    "error_description": "The authorization grant type is not supported by the authorization server."
}

This is what the server logs show:

Started POST "/oauth/token" for 127.0.0.1 at 2022-07-21
Processing by Doorkeeper::TokensController#create as */*
  Parameters: {"grant_type"=>"urn:ietf:params:oauth:grant-type:device_code&device_code=IB7tQi1yGv2QddCUurWBsics26MZ8aUY1sriudewRn4&client_id=2DIJRT72IRMycyeBS7PuGgYSJScCQ9bxnvo5_JyyKOA"}
Completed 400 Bad Request in 0ms (ActiveRecord: 0.0ms | Allocations: 421)

About my code:

  • I created a new Rails 7 project (full, not the api only version)
  • Installed devise gem
  • Installed doorkeeper gem
  • Installed doorkeeper-device_authorization_grant gem

I used the following as guides:

Note: I did not install rack-cors, I don't think I need it at this point, as don't use a separate front-end, I may be mistaken.

Any ideas?

1

There are 1 answers

0
Tim On

I found the problem. It was my own St#$!& fault. I had submitted the body content of the polling request in the wrong way. All in one line, instead of separate key - value pairs.