Skip to main content

Doorkeeper Omniauth OAuth Client Discussion

General • Asked by Chris Oliver
8694ffce9c41ef3f7d7dc12867c2ac38
The video freeze between 0:18 and 0:40, not a big deal imo but I wanted to let you know :)
Ce795239ba5dd2384fc2f88ffaff5451
Thanks for the heads up! What a pain in the butt.

00371c2566c39bb46bfc39059ac5c14c

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

Ce795239ba5dd2384fc2f88ffaff5451

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

00371c2566c39bb46bfc39059ac5c14c

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.


A7b9f6518b2c9d1068ffd4c188d4331d

@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

Ce795239ba5dd2384fc2f88ffaff5451

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.

A7b9f6518b2c9d1068ffd4c188d4331d

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)

A7b9f6518b2c9d1068ffd4c188d4331d

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

Ce795239ba5dd2384fc2f88ffaff5451

Filter chain halted as :doorkeeper_authorize! rendered or redirected

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

A7b9f6518b2c9d1068ffd4c188d4331d

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

A7b9f6518b2c9d1068ffd4c188d4331d

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...


237fcaf76ed775b5315a1e12591f32a3

NoMethodError in Users::OmniauthCallbacksController#doorkept
undefined method `titleize' for :doorkept:Symbol
Extracted source (around line #57):
55
56
57
58
59
60

  elsif User.where(email: auth.info.email).any?
    # 5. User is logged out and they login to a new account which doesn't match their old one
    flash[:alert] = "An account with this email already exists. Please sign in with that account before connecting your #{auth.provider.titleize} account."
    redirect_to new_user_session_path
  else
    @user = create_user

237fcaf76ed775b5315a1e12591f32a3

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

Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 18,000+ developers who get early access to new screencasts, articles, guides, updates, and more.

By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

More of a social being? We're also on Twitter and YouTube.