Authorize a User via command line in Doorkeeper

2019-08-28 13:04发布

问题:

Is it possible to authorize a User for an Application using the Rails console, or even model code?

In certain situations, I want to be able to create and authorize a new user account for a particular application.

Essentially I want to be able generate an authorization_code on the command line.

回答1:

You need to disable the confirmation feature for the app owner:

$ app = Doorkeeper::Application.new :name => 'test', :redirect_uri => 'http://test.com' $ app.owner = User.last # Or any owner class that you want to be associated $ app.save

Take a look on the documentation for further details.



回答2:

Not sure its the best way to do it, but by manually creating a Doorkeeper::AccessGrant, with the proper associations you can get an authorization code from it.