12

Rails, Devise and Doorkeeper... Trying to test password grant and getting error: URI::InvalidURIError: query conflicts with opaque Any ideas?

Update: I created a second rails app that was able to get a token.. so maybe something about native_redirect_uri

Doorkeeper.configure do
  orm :active_record

  resource_owner_authenticator do
      # current_user || warden.authenticate!(:scope => :user)
  end

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


  reuse_access_token

  use_refresh_token

  native_redirect_uri 'urn:ietf:wg:oauth:2.0:oob'

  grant_flows %w(password)


  skip_authorization do |resource_owner, client|
    true
  end

end

Using oauth2 I create an application, give it a random name and for site uri: urn:ietf:wg:oauth:2.0:oob

Then using a user's credentials I run these commands:

client = OAuth2::Client.new('caa5ia541111698b34e66056e18b9afd6cb90c0d200d5dac99584da5a6b83b411', 'e45c78992a9eeb609b72cf5b56aea8dd999ec7dc9594a4211b8265f525a75870', :site => "urn:ietf:wg:oauth:2.0:oob")
access_token = client.password.get_token('test@test.com', 'realpassword')

I'm roughly following this example here

esteban
  • 198
  • 1
  • 8
  • this wasn't quite the same question i had, but it was a result for google search "check password devise in doorkeeper" and the block that actually solved my problem is the `resource_owner_from_credentials` block you have here. – skilleo Mar 12 '16 at 05:08
  • Glad to hear it @twmulloy, you may find this example app of a provider helpful: https://github.com/rilian/devise-doorkeeper-cancan-api-example/tree/master/spec – esteban Mar 15 '16 at 22:04

2 Answers2

26

I ran into this error myself and was very confused, as it is a pretty cryptic error concerning internals of the URI library. My problem was that the first string I was joining did not specify a protocol (https:// or http://). Adding one solved my problem!

Community
  • 1
  • 1
NealJMD
  • 864
  • 8
  • 15
  • Thank you for making me check the beginning on my url. In case it helps somebody else in the future see their mistake, this error can also surface if you make a typo with an extra : such as `https:://` or `http:://` – DuckNG Sep 29 '21 at 20:37
0

For what its worth to anyone, I think I was misusing "urn:ietf:wg:oauth:2.0:oob". I set up a separate rails app as a Client and everything worked as expected.

esteban
  • 198
  • 1
  • 8