doorkeeper-gem / doorkeeper

Doorkeeper is an OAuth 2 provider for Ruby on Rails / Grape.
https://doorkeeper.gitbook.io/guides/
MIT License
5.34k stars 1.07k forks source link

ActiveRecord::RecordInvalid - Validation failed: Application must exist with Rails 5 and EmberSimpleAuth #774

Closed ghost closed 8 years ago

ghost commented 8 years ago

I'm using the github gem in Gemfile of Doorkeeper, Rails and Devise.

I'm using Ember Simple Auth to login Using Resource Owner Password Credentials flow. But when I login with correct username (email) and password I have this error:

Started POST "/oauth/token" for 127.0.0.1 at 2016-01-03 00:10:46 +0100
Processing by Doorkeeper::TokensController#create as HTML
  Parameters: {"grant_type"=>"password", "username"=>"email@email.com", "password"=>"[FILTERED]"}
  User Load (0.6ms)  SELECT  "users".* FROM "users" WHERE "users"."email" = $1 ORDER BY "users"."id" ASC LIMIT $2  [["email", "email@email.com"], ["LIMIT", 1]]
   (0.2ms)  BEGIN
  Doorkeeper::AccessToken Exists (0.7ms)  SELECT  1 AS one FROM "oauth_access_tokens" WHERE "oauth_access_tokens"."token" = $1 LIMIT $2  [["token", "e7c23c36acaa18b6076e69fefbf5092038b1b76cbde7502c537a98e822f9c107"], ["LIMIT", 1]]
   (0.2ms)  ROLLBACK
Completed 422 Unprocessable Entity in 127ms

ActiveRecord::RecordInvalid - Validation failed: Application must exist:

Why I got this?

Which version I have to use?

Everything is pretty default, i'm not using nothing than standard defaults.

ghost commented 8 years ago

Anything?

tute commented 8 years ago

It looks like it needs to know what application are you asking a grant for?

This issue seems very specific to your application rather than with doorkeeper itself. I'd suggest you ask about it in http://stackoverflow.com/questions/tagged/doorkeeper, which will get attention from more people than in this issue tracker. Thank you!

ghost commented 8 years ago

No, I thought this. But not. Using the same configuration default Rails and Doorkeeper Devise and Rails 5 (all from github, with devise and doorkeeper also) and version 4 for the second all works ok, with 5 does not.

tute commented 8 years ago

I don't expect grabbing projects from master to work well together. If you can trigger this for specific versions, and we can replicate it, it is a bug, and we'll work on it. Thanks!

ghost commented 8 years ago

Test yourself with just postman and

grant_type: password
username: userdevise
password: passdevise

Which version I can try with Rails 5.0.0.beta1???

tute commented 8 years ago

Rails 5.0.0.beta1 works indeed with master of doorkeeper, as I didn't yet do a prerelease for doorkeeper 4. What version of devise are you using?

Also, where do I get postman from?

ghost commented 8 years ago

https://www.getpostman.com/

I tried with master of rails, door and devise.

Now i'm trying with rails 5beta, door 3.1.0 and devise master on github...

Devise's latest release is broken with Rails 5.

Now i get this:

Started POST "/oauth/token" for ::1 at 2016-01-04 00:49:16 +0100
  ActiveRecord::SchemaMigration Load (1.8ms)  SELECT "schema_migrations".* FROM "schema_migrations"

ActionController::RoutingError - uninitialized constant ActionController::RackDelegation:
  doorkeeper (3.1.0) app/controllers/doorkeeper/application_metal_controller.rb:4:in `<class:ApplicationMetalController>'
  doorkeeper (3.1.0) app/controllers/doorkeeper/application_metal_controller.rb:2:in `<module:Doorkeeper>'
  doorkeeper (3.1.0) app/controllers/doorkeeper/application_metal_controller.rb:1:in `<top (required)>'
  activesupport (5.0.0.beta1) lib/active_support/dependencies/interlock.rb:12:in `block in loading'
  activesupport (5.0.0.beta1) lib/active_support/concurrency/share_lock.rb:115:in `exclusive'
  activesupport (5.0.0.beta1) lib/active_support/dependencies/interlock.rb:11:in `loading'
  doorkeeper (3.1.0) app/controllers/doorkeeper/tokens_controller.rb:2:in `<module:Doorkeeper>'
  doorkeeper (3.1.0) app/controllers/doorkeeper/tokens_controller.rb:1:in `<top (required)>'
  activesupport (5.0.0.beta1) lib/active_support/dependencies/interlock.rb:12:in `block in loading'
  activesupport (5.0.0.beta1) lib/active_support/concurrency/share_lock.rb:115:in `exclusive'
  activesupport (5.0.0.beta1) lib/active_support/dependencies/interlock.rb:11:in `loading'
  activesupport (5.0.0.beta1) lib/active_support/inflector/methods.rb:261:in `const_get'
  activesupport (5.0.0.beta1) lib/active_support/inflector/methods.rb:261:in `block in constantize'
  activesupport (5.0.0.beta1) lib/active_support/inflector/methods.rb:257:in `each'
  activesupport (5.0.0.beta1) lib/active_support/inflector/methods.rb:257:in `inject'
  activesupport (5.0.0.beta1) lib/active_support/inflector/methods.rb:257:in `constantize'
  actionpack (5.0.0.beta1) lib/action_dispatch/http/request.rb:93:in `controller_class'
  actionpack (5.0.0.beta1) lib/action_dispatch/routing/route_set.rb:44:in `controller'
  actionpack (5.0.0.beta1) lib/action_dispatch/routing/route_set.rb:30:in `serve'
  actionpack (5.0.0.beta1) lib/action_dispatch/journey/router.rb:42:in `block in serve'
  actionpack (5.0.0.beta1) lib/action_dispatch/journey/router.rb:29:in `each'
  actionpack (5.0.0.beta1) lib/action_dispatch/journey/router.rb:29:in `serve'
  actionpack (5.0.0.beta1) lib/action_dispatch/routing/route_set.rb:715:in `call'
  bullet (4.14.10) lib/bullet/rack.rb:10:in `call'
  actionview (5.0.0.beta1) lib/action_view/digestor.rb:14:in `call'
  warden (1.2.4) lib/warden/manager.rb:35:in `block in call'
  warden (1.2.4) lib/warden/manager.rb:34:in `catch'
  warden (1.2.4) lib/warden/manager.rb:34:in `call'
  rack (2.0.0.alpha) lib/rack/etag.rb:25:in `call'
  rack (2.0.0.alpha) lib/rack/conditional_get.rb:38:in `call'
  rack (2.0.0.alpha) lib/rack/head.rb:12:in `call'
  rack (2.0.0.alpha) lib/rack/session/abstract/id.rb:220:in `context'
  rack (2.0.0.alpha) lib/rack/session/abstract/id.rb:214:in `call'
  actionpack (5.0.0.beta1) lib/action_dispatch/middleware/cookies.rb:608:in `call'
  activerecord (5.0.0.beta1) lib/active_record/query_cache.rb:36:in `call'
  activerecord (5.0.0.beta1) lib/active_record/connection_adapters/abstract/connection_pool.rb:963:in `call'
  activerecord (5.0.0.beta1) lib/active_record/migration.rb:524:in `call'
  actionpack (5.0.0.beta1) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
  activesupport (5.0.0.beta1) lib/active_support/callbacks.rb:97:in `__run_callbacks__'
  activesupport (5.0.0.beta1) lib/active_support/callbacks.rb:750:in `_run_call_callbacks'
  activesupport (5.0.0.beta1) lib/active_support/callbacks.rb:90:in `run_callbacks'
  actionpack (5.0.0.beta1) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (5.0.0.beta1) lib/action_dispatch/middleware/reloader.rb:71:in `call'
  actionpack (5.0.0.beta1) lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
  better_errors (2.1.1) lib/better_errors/middleware.rb:84:in `protected_app_call'
  better_errors (2.1.1) lib/better_errors/middleware.rb:79:in `better_errors_call'
  better_errors (2.1.1) lib/better_errors/middleware.rb:57:in `call'
  actionpack (5.0.0.beta1) lib/action_dispatch/middleware/debug_exceptions.rb:49:in `call'
  web-console (3.0.0) lib/web_console/middleware.rb:27:in `call'
  actionpack (5.0.0.beta1) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
  railties (5.0.0.beta1) lib/rails/rack/logger.rb:42:in `call_app'
  railties (5.0.0.beta1) lib/rails/rack/logger.rb:24:in `block in call'
  activesupport (5.0.0.beta1) lib/active_support/tagged_logging.rb:70:in `block in tagged'
  activesupport (5.0.0.beta1) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (5.0.0.beta1) lib/active_support/tagged_logging.rb:70:in `tagged'
  railties (5.0.0.beta1) lib/rails/rack/logger.rb:24:in `call'
  actionpack (5.0.0.beta1) lib/action_dispatch/middleware/request_id.rb:24:in `call'
  rack (2.0.0.alpha) lib/rack/method_override.rb:22:in `call'
  rack (2.0.0.alpha) lib/rack/runtime.rb:22:in `call'
  activesupport (5.0.0.beta1) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
  actionpack (5.0.0.beta1) lib/action_dispatch/middleware/load_interlock.rb:13:in `call'
  actionpack (5.0.0.beta1) lib/action_dispatch/middleware/static.rb:132:in `call'
  rack (2.0.0.alpha) lib/rack/sendfile.rb:111:in `call'
  rack-cors (0.4.0) lib/rack/cors.rb:80:in `call'
  railties (5.0.0.beta1) lib/rails/engine.rb:522:in `call'
  puma (2.15.3) lib/puma/server.rb:541:in `handle_request'
  puma (2.15.3) lib/puma/server.rb:388:in `process_client'
  puma (2.15.3) lib/puma/server.rb:270:in `block in run'
  puma (2.15.3) lib/puma/thread_pool.rb:106:in `call'
  puma (2.15.3) lib/puma/thread_pool.rb:106:in `block in spawn_thread'
tute commented 8 years ago

Now i'm trying with rails 5beta, door 3.1.0 and devise master on github...

Doorkeeper's latest release is broken with Rails 5, you should use master (form that master I will cut a prerelease, hopefully before I leave for vacations).

ghost commented 8 years ago

Yes, and in fact for this reason I'm using everything on master for write my code. But now doorkeeper break with the error in the first post: "Application must exist".

Can you fix this in master?

What it means "Application must exist"?

ghost commented 8 years ago

Anything?

tute commented 8 years ago

I will need help to reproduce this behavior. Do you have a failing application in GitHub, or concrete steps I can take to get to that error message?

ghost commented 8 years ago

Ok, concrete steps:

Rails 5.0.0.beta1 rails new bla bla bla...

In gemfile:

gem 'doorkeeper', github: 'doorkeeper-gem/doorkeeper'
gem 'devise', github: 'plataformatec/devise'

in initializers/doorkeeper.rb:

...
resource_owner_from_credentials do |routes|
  user = User.find_for_database_authentication(:email => params[:username])
    if user && user.valid_for_authentication? { user.valid_password?(params[:password]) }
      user
    end
  end

...

  grant_flows %w(authorization_code client_credentials password)

...

skip_authorization do |resource_owner, client|
  #   client.superapp? or resource_owner.admin?
    true
  end

I then create a default application for test with name "Test", "urn:ietf:wg:oauth:2.0:oob" and without scopes.

When now I try to receive tokens with Postman (or others client...) I receive this error:

{
    "status": 422,
    "error": "Unprocessable Entity",
    "exception": "#<ActiveRecord::RecordInvalid: Validation failed: Application must exist>",
    "traces": {
        "Application Trace": [],
        "Framework Trace": [
            {
                "id": 0,
                "trace": "activerecord (5.0.0.beta1.1) lib/active_record/validations.rb:78:in `raise_validation_error'"
            },
            {
                "id": 1,
                "trace": "activerecord (5.0.0.beta1.1) lib/active_record/validations.rb:50:in `save!'"
            },
            {
                "id": 2,
                "trace": "activerecord (5.0.0.beta1.1) lib/active_record/attribute_methods/dirty.rb:30:in `save!'"
            },
            {
                "id": 3,
                "trace": "activerecord (5.0.0.beta1.1) lib/active_record/transactions.rb:324:in `block in save!'"
            },
            {
                "id": 4,
                "trace": "activerecord (5.0.0.beta1.1) lib/active_record/transactions.rb:395:in `block in with_transaction_returning_status'"
            },
            {
                "id": 5,
                "trace": "activerecord (5.0.0.beta1.1) lib/active_record/connection_adapters/abstract/database_statements.rb:222:in `block in transaction'"
            },
            {
                "id": 6,
                "trace": "activerecord (5.0.0.beta1.1) lib/active_record/connection_adapters/abstract/transaction.rb:183:in `within_new_transaction'"
            },
            {
                "id": 7,
                "trace": "activerecord (5.0.0.beta1.1) lib/active_record/connection_adapters/abstract/database_statements.rb:222:in `transaction'"
            },
            {
                "id": 8,
                "trace": "activerecord (5.0.0.beta1.1) lib/active_record/transactions.rb:211:in `transaction'"
            },
            {
                "id": 9,
                "trace": "activerecord (5.0.0.beta1.1) lib/active_record/transactions.rb:392:in `with_transaction_returning_status'"
            },
            {
                "id": 10,
                "trace": "activerecord (5.0.0.beta1.1) lib/active_record/transactions.rb:324:in `save!'"
            },
            {
                "id": 11,
                "trace": "activerecord (5.0.0.beta1.1) lib/active_record/persistence.rb:51:in `create!'"
            },
            {
                "id": 12,
                "trace": "/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/bundler/gems/doorkeeper-56bfa579484a/lib/doorkeeper/models/access_token_mixin.rb:77:in `find_or_create_for'"
            },
            {
                "id": 13,
                "trace": "/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/bundler/gems/doorkeeper-56bfa579484a/lib/doorkeeper/oauth/request_concern.rb:33:in `find_or_create_access_token'"
            },
            {
                "id": 14,
                "trace": "/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/bundler/gems/doorkeeper-56bfa579484a/lib/doorkeeper/oauth/password_access_token_request.rb:30:in `before_successful_response'"
            },
            {
                "id": 15,
                "trace": "/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/bundler/gems/doorkeeper-56bfa579484a/lib/doorkeeper/oauth/request_concern.rb:7:in `authorize'"
            },
            {
                "id": 16,
                "trace": "/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/bundler/gems/doorkeeper-56bfa579484a/lib/doorkeeper/request/strategy.rb:6:in `authorize'"
            },
            {
                "id": 17,
                "trace": "/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/bundler/gems/doorkeeper-56bfa579484a/app/controllers/doorkeeper/tokens_controller.rb:42:in `authorize_response'"
            },
            {
                "id": 18,
                "trace": "/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/bundler/gems/doorkeeper-56bfa579484a/app/controllers/doorkeeper/tokens_controller.rb:4:in `create'"
            },
            {
                "id": 19,
                "trace": "actionpack (5.0.0.beta1.1) lib/abstract_controller/base.rb:183:in `process_action'"
            },
            {
                "id": 20,
                "trace": "actionpack (5.0.0.beta1.1) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'"
            },
            {
                "id": 21,
                "trace": "activesupport (5.0.0.beta1.1) lib/active_support/notifications.rb:164:in `block in instrument'"
            },
            {
                "id": 22,
                "trace": "activesupport (5.0.0.beta1.1) lib/active_support/notifications/instrumenter.rb:21:in `instrument'"
            },
            {
                "id": 23,
                "trace": "activesupport (5.0.0.beta1.1) lib/active_support/notifications.rb:164:in `instrument'"
            },
            {
                "id": 24,
                "trace": "actionpack (5.0.0.beta1.1) lib/action_controller/metal/instrumentation.rb:29:in `process_action'"
            },
            {
                "id": 25,
                "trace": "actionpack (5.0.0.beta1.1) lib/action_controller/metal/rendering.rb:30:in `process_action'"
            },
            {
                "id": 26,
                "trace": "actionpack (5.0.0.beta1.1) lib/abstract_controller/base.rb:128:in `process'"
            },
            {
                "id": 27,
                "trace": "actionpack (5.0.0.beta1.1) lib/action_controller/metal.rb:192:in `dispatch'"
            },
            {
                "id": 28,
                "trace": "actionpack (5.0.0.beta1.1) lib/action_controller/metal.rb:264:in `dispatch'"
            },
            {
                "id": 29,
                "trace": "actionpack (5.0.0.beta1.1) lib/action_dispatch/routing/route_set.rb:50:in `dispatch'"
            },
            {
                "id": 30,
                "trace": "actionpack (5.0.0.beta1.1) lib/action_dispatch/routing/route_set.rb:32:in `serve'"
            },
            {
                "id": 31,
                "trace": "actionpack (5.0.0.beta1.1) lib/action_dispatch/journey/router.rb:42:in `block in serve'"
            },
            {
                "id": 32,
                "trace": "actionpack (5.0.0.beta1.1) lib/action_dispatch/journey/router.rb:29:in `each'"
            },
            {
                "id": 33,
                "trace": "actionpack (5.0.0.beta1.1) lib/action_dispatch/journey/router.rb:29:in `serve'"
            },
            {
                "id": 34,
                "trace": "actionpack (5.0.0.beta1.1) lib/action_dispatch/routing/route_set.rb:715:in `call'"
            },
            {
                "id": 35,
                "trace": "bullet (5.0.0) lib/bullet/rack.rb:10:in `call'"
            },
            {
                "id": 36,
                "trace": "actionview (5.0.0.beta1.1) lib/action_view/digestor.rb:14:in `call'"
            },
            {
                "id": 37,
                "trace": "warden (1.2.4) lib/warden/manager.rb:35:in `block in call'"
            },
            {
                "id": 38,
                "trace": "warden (1.2.4) lib/warden/manager.rb:34:in `catch'"
            },
            {
                "id": 39,
                "trace": "warden (1.2.4) lib/warden/manager.rb:34:in `call'"
            },
            {
                "id": 40,
                "trace": "rack (2.0.0.alpha) lib/rack/etag.rb:25:in `call'"
            },
            {
                "id": 41,
                "trace": "rack (2.0.0.alpha) lib/rack/conditional_get.rb:38:in `call'"
            },
            {
                "id": 42,
                "trace": "rack (2.0.0.alpha) lib/rack/head.rb:12:in `call'"
            },
            {
                "id": 43,
                "trace": "rack (2.0.0.alpha) lib/rack/session/abstract/id.rb:220:in `context'"
            },
            {
                "id": 44,
                "trace": "rack (2.0.0.alpha) lib/rack/session/abstract/id.rb:214:in `call'"
            },
            {
                "id": 45,
                "trace": "actionpack (5.0.0.beta1.1) lib/action_dispatch/middleware/cookies.rb:608:in `call'"
            },
            {
                "id": 46,
                "trace": "activerecord (5.0.0.beta1.1) lib/active_record/query_cache.rb:36:in `call'"
            },
            {
                "id": 47,
                "trace": "activerecord (5.0.0.beta1.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:963:in `call'"
            },
            {
                "id": 48,
                "trace": "activerecord (5.0.0.beta1.1) lib/active_record/migration.rb:524:in `call'"
            },
            {
                "id": 49,
                "trace": "actionpack (5.0.0.beta1.1) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'"
            },
            {
                "id": 50,
                "trace": "activesupport (5.0.0.beta1.1) lib/active_support/callbacks.rb:97:in `__run_callbacks__'"
            },
            {
                "id": 51,
                "trace": "activesupport (5.0.0.beta1.1) lib/active_support/callbacks.rb:750:in `_run_call_callbacks'"
            },
            {
                "id": 52,
                "trace": "activesupport (5.0.0.beta1.1) lib/active_support/callbacks.rb:90:in `run_callbacks'"
            },
            {
                "id": 53,
                "trace": "actionpack (5.0.0.beta1.1) lib/action_dispatch/middleware/callbacks.rb:27:in `call'"
            },
            {
                "id": 54,
                "trace": "actionpack (5.0.0.beta1.1) lib/action_dispatch/middleware/reloader.rb:71:in `call'"
            },
            {
                "id": 55,
                "trace": "actionpack (5.0.0.beta1.1) lib/action_dispatch/middleware/remote_ip.rb:79:in `call'"
            },
            {
                "id": 56,
                "trace": "better_errors (2.1.1) lib/better_errors/middleware.rb:59:in `call'"
            },
            {
                "id": 57,
                "trace": "actionpack (5.0.0.beta1.1) lib/action_dispatch/middleware/debug_exceptions.rb:49:in `call'"
            },
            {
                "id": 58,
                "trace": "web-console (3.0.0) lib/web_console/middleware.rb:19:in `call'"
            },
            {
                "id": 59,
                "trace": "actionpack (5.0.0.beta1.1) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'"
            },
            {
                "id": 60,
                "trace": "railties (5.0.0.beta1.1) lib/rails/rack/logger.rb:42:in `call_app'"
            },
            {
                "id": 61,
                "trace": "railties (5.0.0.beta1.1) lib/rails/rack/logger.rb:24:in `block in call'"
            },
            {
                "id": 62,
                "trace": "activesupport (5.0.0.beta1.1) lib/active_support/tagged_logging.rb:70:in `block in tagged'"
            },
            {
                "id": 63,
                "trace": "activesupport (5.0.0.beta1.1) lib/active_support/tagged_logging.rb:26:in `tagged'"
            },
            {
                "id": 64,
                "trace": "activesupport (5.0.0.beta1.1) lib/active_support/tagged_logging.rb:70:in `tagged'"
            },
            {
                "id": 65,
                "trace": "railties (5.0.0.beta1.1) lib/rails/rack/logger.rb:24:in `call'"
            },
            {
                "id": 66,
                "trace": "quiet_assets (1.1.0) lib/quiet_assets.rb:27:in `call_with_quiet_assets'"
            },
            {
                "id": 67,
                "trace": "actionpack (5.0.0.beta1.1) lib/action_dispatch/middleware/request_id.rb:24:in `call'"
            },
            {
                "id": 68,
                "trace": "rack (2.0.0.alpha) lib/rack/method_override.rb:22:in `call'"
            },
            {
                "id": 69,
                "trace": "rack (2.0.0.alpha) lib/rack/runtime.rb:22:in `call'"
            },
            {
                "id": 70,
                "trace": "activesupport (5.0.0.beta1.1) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'"
            },
            {
                "id": 71,
                "trace": "actionpack (5.0.0.beta1.1) lib/action_dispatch/middleware/load_interlock.rb:13:in `call'"
            },
            {
                "id": 72,
                "trace": "actionpack (5.0.0.beta1.1) lib/action_dispatch/middleware/static.rb:132:in `call'"
            },
            {
                "id": 73,
                "trace": "rack (2.0.0.alpha) lib/rack/sendfile.rb:111:in `call'"
            },
            {
                "id": 74,
                "trace": "rack-cors (0.4.0) lib/rack/cors.rb:80:in `call'"
            },
            {
                "id": 75,
                "trace": "railties (5.0.0.beta1.1) lib/rails/engine.rb:522:in `call'"
            },
            {
                "id": 76,
                "trace": "puma (2.15.3) lib/puma/server.rb:541:in `handle_request'"
            },
            {
                "id": 77,
                "trace": "puma (2.15.3) lib/puma/server.rb:388:in `process_client'"
            },
            {
                "id": 78,
                "trace": "puma (2.15.3) lib/puma/server.rb:270:in `block in run'"
            },
            {
                "id": 79,
                "trace": "puma (2.15.3) lib/puma/thread_pool.rb:106:in `block in spawn_thread'"
            }
        ],
        "Full Trace": [
            {
                "id": 0,
                "trace": "activerecord (5.0.0.beta1.1) lib/active_record/validations.rb:78:in `raise_validation_error'"
            },
            {
                "id": 1,
                "trace": "activerecord (5.0.0.beta1.1) lib/active_record/validations.rb:50:in `save!'"
            },
            {
                "id": 2,
                "trace": "activerecord (5.0.0.beta1.1) lib/active_record/attribute_methods/dirty.rb:30:in `save!'"
            },
            {
                "id": 3,
                "trace": "activerecord (5.0.0.beta1.1) lib/active_record/transactions.rb:324:in `block in save!'"
            },
            {
                "id": 4,
                "trace": "activerecord (5.0.0.beta1.1) lib/active_record/transactions.rb:395:in `block in with_transaction_returning_status'"
            },
            {
                "id": 5,
                "trace": "activerecord (5.0.0.beta1.1) lib/active_record/connection_adapters/abstract/database_statements.rb:222:in `block in transaction'"
            },
            {
                "id": 6,
                "trace": "activerecord (5.0.0.beta1.1) lib/active_record/connection_adapters/abstract/transaction.rb:183:in `within_new_transaction'"
            },
            {
                "id": 7,
                "trace": "activerecord (5.0.0.beta1.1) lib/active_record/connection_adapters/abstract/database_statements.rb:222:in `transaction'"
            },
            {
                "id": 8,
                "trace": "activerecord (5.0.0.beta1.1) lib/active_record/transactions.rb:211:in `transaction'"
            },
            {
                "id": 9,
                "trace": "activerecord (5.0.0.beta1.1) lib/active_record/transactions.rb:392:in `with_transaction_returning_status'"
            },
            {
                "id": 10,
                "trace": "activerecord (5.0.0.beta1.1) lib/active_record/transactions.rb:324:in `save!'"
            },
            {
                "id": 11,
                "trace": "activerecord (5.0.0.beta1.1) lib/active_record/persistence.rb:51:in `create!'"
            },
            {
                "id": 12,
                "trace": "/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/bundler/gems/doorkeeper-56bfa579484a/lib/doorkeeper/models/access_token_mixin.rb:77:in `find_or_create_for'"
            },
            {
                "id": 13,
                "trace": "/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/bundler/gems/doorkeeper-56bfa579484a/lib/doorkeeper/oauth/request_concern.rb:33:in `find_or_create_access_token'"
            },
            {
                "id": 14,
                "trace": "/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/bundler/gems/doorkeeper-56bfa579484a/lib/doorkeeper/oauth/password_access_token_request.rb:30:in `before_successful_response'"
            },
            {
                "id": 15,
                "trace": "/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/bundler/gems/doorkeeper-56bfa579484a/lib/doorkeeper/oauth/request_concern.rb:7:in `authorize'"
            },
            {
                "id": 16,
                "trace": "/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/bundler/gems/doorkeeper-56bfa579484a/lib/doorkeeper/request/strategy.rb:6:in `authorize'"
            },
            {
                "id": 17,
                "trace": "/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/bundler/gems/doorkeeper-56bfa579484a/app/controllers/doorkeeper/tokens_controller.rb:42:in `authorize_response'"
            },
            {
                "id": 18,
                "trace": "/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/bundler/gems/doorkeeper-56bfa579484a/app/controllers/doorkeeper/tokens_controller.rb:4:in `create'"
            },
            {
                "id": 19,
                "trace": "actionpack (5.0.0.beta1.1) lib/abstract_controller/base.rb:183:in `process_action'"
            },
            {
                "id": 20,
                "trace": "actionpack (5.0.0.beta1.1) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'"
            },
            {
                "id": 21,
                "trace": "activesupport (5.0.0.beta1.1) lib/active_support/notifications.rb:164:in `block in instrument'"
            },
            {
                "id": 22,
                "trace": "activesupport (5.0.0.beta1.1) lib/active_support/notifications/instrumenter.rb:21:in `instrument'"
            },
            {
                "id": 23,
                "trace": "activesupport (5.0.0.beta1.1) lib/active_support/notifications.rb:164:in `instrument'"
            },
            {
                "id": 24,
                "trace": "actionpack (5.0.0.beta1.1) lib/action_controller/metal/instrumentation.rb:29:in `process_action'"
            },
            {
                "id": 25,
                "trace": "actionpack (5.0.0.beta1.1) lib/action_controller/metal/rendering.rb:30:in `process_action'"
            },
            {
                "id": 26,
                "trace": "actionpack (5.0.0.beta1.1) lib/abstract_controller/base.rb:128:in `process'"
            },
            {
                "id": 27,
                "trace": "actionpack (5.0.0.beta1.1) lib/action_controller/metal.rb:192:in `dispatch'"
            },
            {
                "id": 28,
                "trace": "actionpack (5.0.0.beta1.1) lib/action_controller/metal.rb:264:in `dispatch'"
            },
            {
                "id": 29,
                "trace": "actionpack (5.0.0.beta1.1) lib/action_dispatch/routing/route_set.rb:50:in `dispatch'"
            },
            {
                "id": 30,
                "trace": "actionpack (5.0.0.beta1.1) lib/action_dispatch/routing/route_set.rb:32:in `serve'"
            },
            {
                "id": 31,
                "trace": "actionpack (5.0.0.beta1.1) lib/action_dispatch/journey/router.rb:42:in `block in serve'"
            },
            {
                "id": 32,
                "trace": "actionpack (5.0.0.beta1.1) lib/action_dispatch/journey/router.rb:29:in `each'"
            },
            {
                "id": 33,
                "trace": "actionpack (5.0.0.beta1.1) lib/action_dispatch/journey/router.rb:29:in `serve'"
            },
            {
                "id": 34,
                "trace": "actionpack (5.0.0.beta1.1) lib/action_dispatch/routing/route_set.rb:715:in `call'"
            },
            {
                "id": 35,
                "trace": "bullet (5.0.0) lib/bullet/rack.rb:10:in `call'"
            },
            {
                "id": 36,
                "trace": "actionview (5.0.0.beta1.1) lib/action_view/digestor.rb:14:in `call'"
            },
            {
                "id": 37,
                "trace": "warden (1.2.4) lib/warden/manager.rb:35:in `block in call'"
            },
            {
                "id": 38,
                "trace": "warden (1.2.4) lib/warden/manager.rb:34:in `catch'"
            },
            {
                "id": 39,
                "trace": "warden (1.2.4) lib/warden/manager.rb:34:in `call'"
            },
            {
                "id": 40,
                "trace": "rack (2.0.0.alpha) lib/rack/etag.rb:25:in `call'"
            },
            {
                "id": 41,
                "trace": "rack (2.0.0.alpha) lib/rack/conditional_get.rb:38:in `call'"
            },
            {
                "id": 42,
                "trace": "rack (2.0.0.alpha) lib/rack/head.rb:12:in `call'"
            },
            {
                "id": 43,
                "trace": "rack (2.0.0.alpha) lib/rack/session/abstract/id.rb:220:in `context'"
            },
            {
                "id": 44,
                "trace": "rack (2.0.0.alpha) lib/rack/session/abstract/id.rb:214:in `call'"
            },
            {
                "id": 45,
                "trace": "actionpack (5.0.0.beta1.1) lib/action_dispatch/middleware/cookies.rb:608:in `call'"
            },
            {
                "id": 46,
                "trace": "activerecord (5.0.0.beta1.1) lib/active_record/query_cache.rb:36:in `call'"
            },
            {
                "id": 47,
                "trace": "activerecord (5.0.0.beta1.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:963:in `call'"
            },
            {
                "id": 48,
                "trace": "activerecord (5.0.0.beta1.1) lib/active_record/migration.rb:524:in `call'"
            },
            {
                "id": 49,
                "trace": "actionpack (5.0.0.beta1.1) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'"
            },
            {
                "id": 50,
                "trace": "activesupport (5.0.0.beta1.1) lib/active_support/callbacks.rb:97:in `__run_callbacks__'"
            },
            {
                "id": 51,
                "trace": "activesupport (5.0.0.beta1.1) lib/active_support/callbacks.rb:750:in `_run_call_callbacks'"
            },
            {
                "id": 52,
                "trace": "activesupport (5.0.0.beta1.1) lib/active_support/callbacks.rb:90:in `run_callbacks'"
            },
            {
                "id": 53,
                "trace": "actionpack (5.0.0.beta1.1) lib/action_dispatch/middleware/callbacks.rb:27:in `call'"
            },
            {
                "id": 54,
                "trace": "actionpack (5.0.0.beta1.1) lib/action_dispatch/middleware/reloader.rb:71:in `call'"
            },
            {
                "id": 55,
                "trace": "actionpack (5.0.0.beta1.1) lib/action_dispatch/middleware/remote_ip.rb:79:in `call'"
            },
            {
                "id": 56,
                "trace": "better_errors (2.1.1) lib/better_errors/middleware.rb:59:in `call'"
            },
            {
                "id": 57,
                "trace": "actionpack (5.0.0.beta1.1) lib/action_dispatch/middleware/debug_exceptions.rb:49:in `call'"
            },
            {
                "id": 58,
                "trace": "web-console (3.0.0) lib/web_console/middleware.rb:19:in `call'"
            },
            {
                "id": 59,
                "trace": "actionpack (5.0.0.beta1.1) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'"
            },
            {
                "id": 60,
                "trace": "railties (5.0.0.beta1.1) lib/rails/rack/logger.rb:42:in `call_app'"
            },
            {
                "id": 61,
                "trace": "railties (5.0.0.beta1.1) lib/rails/rack/logger.rb:24:in `block in call'"
            },
            {
                "id": 62,
                "trace": "activesupport (5.0.0.beta1.1) lib/active_support/tagged_logging.rb:70:in `block in tagged'"
            },
            {
                "id": 63,
                "trace": "activesupport (5.0.0.beta1.1) lib/active_support/tagged_logging.rb:26:in `tagged'"
            },
            {
                "id": 64,
                "trace": "activesupport (5.0.0.beta1.1) lib/active_support/tagged_logging.rb:70:in `tagged'"
            },
            {
                "id": 65,
                "trace": "railties (5.0.0.beta1.1) lib/rails/rack/logger.rb:24:in `call'"
            },
            {
                "id": 66,
                "trace": "quiet_assets (1.1.0) lib/quiet_assets.rb:27:in `call_with_quiet_assets'"
            },
            {
                "id": 67,
                "trace": "actionpack (5.0.0.beta1.1) lib/action_dispatch/middleware/request_id.rb:24:in `call'"
            },
            {
                "id": 68,
                "trace": "rack (2.0.0.alpha) lib/rack/method_override.rb:22:in `call'"
            },
            {
                "id": 69,
                "trace": "rack (2.0.0.alpha) lib/rack/runtime.rb:22:in `call'"
            },
            {
                "id": 70,
                "trace": "activesupport (5.0.0.beta1.1) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'"
            },
            {
                "id": 71,
                "trace": "actionpack (5.0.0.beta1.1) lib/action_dispatch/middleware/load_interlock.rb:13:in `call'"
            },
            {
                "id": 72,
                "trace": "actionpack (5.0.0.beta1.1) lib/action_dispatch/middleware/static.rb:132:in `call'"
            },
            {
                "id": 73,
                "trace": "rack (2.0.0.alpha) lib/rack/sendfile.rb:111:in `call'"
            },
            {
                "id": 74,
                "trace": "rack-cors (0.4.0) lib/rack/cors.rb:80:in `call'"
            },
            {
                "id": 75,
                "trace": "railties (5.0.0.beta1.1) lib/rails/engine.rb:522:in `call'"
            },
            {
                "id": 76,
                "trace": "puma (2.15.3) lib/puma/server.rb:541:in `handle_request'"
            },
            {
                "id": 77,
                "trace": "puma (2.15.3) lib/puma/server.rb:388:in `process_client'"
            },
            {
                "id": 78,
                "trace": "puma (2.15.3) lib/puma/server.rb:270:in `block in run'"
            },
            {
                "id": 79,
                "trace": "puma (2.15.3) lib/puma/thread_pool.rb:106:in `block in spawn_thread'"
            }
        ]
    }
}

What to do?

If now I modify this file: https://github.com/ginolon/doorkeeper/commit/6d304c8e0aeb04a0ba2f5ced60181f7227e009a9

I receive the token with this params:

grant_type: password
username: userdevise
password: passdevise
ghost commented 8 years ago

Is this a good explanation?

ashishtajane commented 8 years ago

I am also getting the same error with rails 5.0.0.beta1.1 and doorkeeper#master. I was not getting this error couple of days back with rails 4.2.5 and doorkeeper 3.0.1

ashishtajane commented 8 years ago

I think I found why this is happening. This issue (rails/rails#18233) and this PR (rails/rails#18937) makes all belongs_to relations required by default. Thats why absence of application now raises Application must exist validation error. After this change (https://github.com/doorkeeper-gem/doorkeeper/compare/56bfa579484ae9e554028b081227ec8d1b74c21d...ashishtajane:master), I no longer get that validation error.

tute commented 8 years ago

That's great, thank you both! @ashishtajane, would you like to send a Pull Request with that change, and context from this issue in the commit message? Thank you!

ashishtajane commented 8 years ago

Done. #780

tute commented 8 years ago

Thank you all! Closing in favor of PR: https://github.com/doorkeeper-gem/doorkeeper/pull/780