doorkeeper gem gives "invalid_client" after successfully validated username and password

Viewed 889

http://localhost:3000/oauth/token

{
"error": "invalid_client",
"error_description": "Client authentication failed due to unknown client, no client authentication included, or unsupported authentication method."
}

while implementing doorkeeper..

Started POST "/oauth/token" for ::1 at 2021-06-13 19:56:20 +0530 Processing by Doorkeeper::TokensController#create as / Parameters: {"grant_type"=>"password", "username"=>"bhagwan", "password"=>"[FILTERED]"} User Load (7.0ms) SELECT "users". FROM "users" WHERE "users"."email" = ? LIMIT ? [["email", "bhagwan"], ["LIMIT", 1]] ↳ config/initializers/doorkeeper.rb:19:in `block (2 levels) in ' Completed 401 Unauthorized in 1654ms (Views: 0.5ms | ActiveRecord: 28.7ms | Allocations: 5869)*

in doorkeeper.rb

grant_flows %w[password]

resource_owner_from_credentials do
User.find_by(email: params[:username])
&.authenticate(params[:password]) || nil
end
2 Answers

You can use skip_client_authentication_for_password_grant config option to skip client authentication for your case:

Doorkeeper.configure do
  skip_client_authentication_for_password_grant true
end

In my case, it was because the application is private by default. Had to update the application to be public with update!(confidential: false).Since Doorkeeper 5.0.0 applications are private by default (reference).

Related