Ask A Question

Notifications

You’re not receiving notifications from this thread.

Doorkeeper Omniauth OAuth Client Discussion

After I click "Authorize" it never makes it to the byebug. I get an error that says:

undefined method `[]' for nil:NilClass

uid { raw_info["id"] }

The error is inside "doorkept-client"

It is referring to the omniauth-doorkept gem inside the file doorkept.rb on line 16

Reply

Hey Trevor,

That means your raw_info is returning nil. It should be returning an hash {}.

Also I uploaded all the source code for these finally so you can reference my omniauth gem. I think I made some tweaks to it. https://github.com/gorails-screencasts/oauth-api-authentication

Reply

Thanks Chris, I fixed it. The problem was my me.json.jbuilder file was in the wrong directory. :)

Would have corrected this last night, but my comment didn't show up.

Reply

After I click "Authorize" it never makes it to the byebug and I get the following error:

undefined method `[]' for nil:NilClass

uid { raw_info["id"] }
Reply

Hello, after I click "Authorize" it never makes it to the byebug and I get the following error:

undefined method `[]' for nil:NilClass

uid { raw_info["id"] }

This happens inside the doorkept-client app and is referring to the omniauth-doorkept gem we made, specifically the file doorkept.rb on line 16.

Reply

Comments are not working for me! :(

Reply

@17:32

You did not show the process of creating the tweets.json scaffold... I realize you think you went over enough to have this be obvious but at this point its not, i went through and created all of the files manually you have in your repoistory but am getting

uninitialized constant Api::V1::TweetsController::Tweet
# GET /tweets.json
def index
@tweets = Tweet.all
render "tweets/index"
end

Reply

Correct, I did exactly as I said in the video at that timestamp:

All I did was run the Rails scaffold generator for Tweet rails g scaffold Tweet user:references body:text

Added Api::V1::TweetsController, with doorkeeper authentication and had it render the same views. As seen here: https://github.com/gorails-screencasts/oauth-api-authentication/blob/master/rails-oauth-provider-app/app/controllers/api/v1/tweets_controller.rb

You say you "created all of the files manually" but it says that the Tweet class is uninitialized. You either didn't create the Tweet model or you have something like Spring caching that hasn't reloaded it.

Reply

thank you for your response, I removed the files i had created and ran the scaffold... now just getting this back

Started GET "/api/v1/tweets.json" for ::1 at 2018-10-02 03:37:14 -0400
Processing by Api::V1::TweetsController#index as JSON
Filter chain halted as :doorkeeper_authorize! rendered or redirected
Completed 401 Unauthorized in 1ms (ActiveRecord: 0.0ms)

Reply

Also having this issue when i try to login from the client to my provider...

No route matches [GET] "/oauth/authorize"
Rails.root: /Users/username/project/my_client

Reply

Filter chain halted as :doorkeeper_authorize! rendered or redirected

That means that your API key was not passed over or not valid.

Reply

Thanks i did just notice my api key changed and fixed that.

Reply

When i run a scaffold i get this error:

(erb):1:in template': undefined local variable or methodmodel_resource_name' for #Erb::Generators::ScaffoldGenerator:0x007fa59de06e48 (NameError)

Please help, this is incredibly confusing...

Reply

NoMethodError
undefined method `provider' for nil:NilClass
Extracted source (around line #47):
45
46
47
48
49
50

def set_service
  @service = Service.where(provider: auth.provider, uid: auth.uid).first
end

def titleize
Reply

Were you able to navigate through this?

Reply

I've added non-gem strategy in lib/strategies and in initializers I have
module OmniAuth
module Strategies
autoload :Doorkeeper, Rails.root.join('lib', 'strategies', 'area_agent_doorkeeper')
end
end
I keep getting 'Could not authenticate you from Doorkeeper because "Invalid credentials".' - do I need to do anything differently if the strategy is not in a gem?

Reply

I am having an issue when trying to authenticate with my new strategy. It is telling me that
Missing required parameter: scope.

I have followed the tutorial closely and you do not seem to get that error. Please assist me on how I can fix this error.

Thanks in advance.

Reply

[Fixed] I finally got it to work

  • I think in the version of doorkeeper I am using scopes are compulsory
  • So visit localhost:5000/oauth/applications/1/edit (or whatever the id of the application you have in your oauth server)
  • Add a user.readonly scope in the scope textbox (You can use whatever scope name makes sense to you).
  • Now go to the client application and open initializers/devise.rb
  • On the line you setup your custom auth, restore the scope argument that was removed by Chris Oliver in the video like so config.omniauth :doorkept, 'APP_ID', 'APP_SECRET', scope: 'user.readonly'
  • Restart your rails server and tada it's running nice and smooth 🎉
Reply

Thank you!! I had the same problem and this fix worked for me.

Reply

Thank you Kudakwashe Paradzayi, it worked for me too.

Reply

@Kudakwashe Paradzayi any idea where we can get further reference material, to read and explore on. Thanks in advance.

Reply

Started GET "/users/auth/doorkept" for ::1 at 2021-04-24 16:27:32 +0300
I, [2021-04-24T16:27:32.933925 #12830] INFO -- omniauth: (doorkept) Request phase initiated.
Started GET "/users/auth/doorkept" for ::1 at 2021-04-24 16:27:33 +0300
I, [2021-04-24T16:27:33.106914 #12830] INFO -- omniauth: (doorkept) Request phase initiated.
Started GET "/users/auth/doorkept/callback?code=wfUmJI8vrh_IF8h7kZ8mml0sLbOlwW1mPf_Qqi3xTBE&state=b99de6db26d1906ead4b2fd5f87723d4fc484bb7e55213aa" for ::1 at 2021-04-24 16:27:33 +0300
I, [2021-04-24T16:27:33.178137 #12830] INFO -- omniauth: (doorkept) Callback phase initiated.
E, [2021-04-24T16:27:33.308938 #12830] ERROR -- omniauth: (doorkept) Authentication failure! invalid_credentials: OAuth2::Error, You need to sign in or sign up before continuing.:
{"error":"You need to sign in or sign up before continuing."}
Processing by Users::OmniauthCallbacksController#failure as HTML
Parameters: {"code"=>"wfUmJI8vrh_IF8h7kZ8mml0sLbOlwW1mPf_Qqi3xTBE", "state"=>"b99de6db26d1906ead4b2fd5f87723d4fc484bb7e55213aa"}
Completed 500 Internal Server Error in 7ms (ActiveRecord: 0.0ms | Allocations: 937)

NoMethodError (undefined method `provider' for nil:NilClass):

app/controllers/users/omniauth_callbacks_controller.rb:47:in `set_service'

The response I get after calling Sign In With Doorkept
What am I doing wrong?
Someone please help me interpret these logs.
THanks in advance.

Reply

Please help, still can't get this solution one month later.


app/controllers/users/omniauth_callbacks_controller.rb:48:in `set_service'
Started GET "/users/auth/doorkept/callback?code=7agPyKCsYDE38DR_YpwUGvONaPGkgR0mFInKp7c-Ip4" for ::1 at 2021-05-19 17:50:02 +0300
D, [2021-05-19T17:50:02.926676 #172579] DEBUG -- omniauth: (doorkept) Callback phase initiated.
E, [2021-05-19T17:50:02.927027 #172579] ERROR -- omniauth: (doorkept) Authentication failure! csrf_detected: OmniAuth::Strategies::OAuth2::CallbackError, csrf_detected | CSRF detected
Processing by Users::OmniauthCallbacksController#failure as HTML
Parameters: {"code"=>"7agPyKCsYDE38DR_YpwUGvONaPGkgR0mFInKp7c-Ip4"}
Completed 500 Internal Server Error in 4ms (Allocations: 1519)

E, [2021-05-19T17:50:02.940081 #172579] ERROR -- omniauth: (doorkept) Authentication failure! undefined method provider' for nil:NilClass: NoMethodError, undefined methodprovider' for nil:NilClass
Processing by Users::OmniauthCallbacksController#failure as HTML
Parameters: {"code"=>"7agPyKCsYDE38DR_YpwUGvONaPGkgR0mFInKp7c-Ip4"}
Completed 500 Internal Server Error in 2ms (Allocations: 927)

NoMethodError (undefined method `provider' for nil:NilClass):

app/controllers/users/omniauth_callbacks_controller.rb:48:in `set_service'

Reply

I see the same issue. Someone, please help. It is because request.env['omniauth.auth'] is always nil.

Reply

Chris - can you PLEASE chime in here as we are all having this same issue?

Reply

For anyone watching this now with Rails 7.1 and the latest getting this error, the fix is easy. Just add:

gem "omniauth-buckets", path: "/Users/jlippiner/Projects/buckets-tools/omniauth-buckets"

To your test app gem file and it should work.

Reply

I just watched the doorkeeper videos but cant figure out how to log out of the main app through the client app. Currently when a user logs out of the client app, they are still logged in to the main app.

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 86,946+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.