All threads / Doorkeeper Omniauth OAuth Client Discussion

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

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

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

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.

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)

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

Filter chain halted as :doorkeeper_authorize! rendered or redirected

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

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

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

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.

[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
Join the discussion

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

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

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

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.