Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoMethodError at /omniauth/facebook/callback - undefined method `[]' for nil:NilClass #76

Closed
kspe opened this issue Nov 23, 2014 · 5 comments

Comments

@kspe
Copy link

kspe commented Nov 23, 2014

Hi,

I've updated to:

devise_token_auth 0.1.30
ng-token-auth 0.0.24

and now after redirect to /auth/facebook/callback I get:
NoMethodError at /omniauth/facebook/callback undefined method[]' for nil:NilClass`

in

omniauth_success devise_token_auth (0.1.30) app/controllers/devise_token_auth/omniauth_callbacks_controller.rb:24

def omniauth_success
      # find or create user by provider and provider uid
      @resource = resource_class.where({
        uid:      auth_hash['uid'],
        provider: auth_hash['provider']
      }).first_or_initialize

when trying to access auth_hash.

I've tried to clean all browser cache/cookies, removed user from DB in order to have clean installation.

@lynndylanhurley
Copy link
Owner

Thanks @ignacykasperowicz - I'll look into this ASAP.

@kspe
Copy link
Author

kspe commented Nov 23, 2014

Hey,

As I dived into the code I found out that you've added:
OmniauthCallbacksController#redirect_callbacks before calling omniauth_success or omniauth_failure plus also views has changed.

I'm using in my routes:

if defined?(::OmniAuth)
    get "#{::OmniAuth.config.path_prefix}/:provider/callback", to: 'devise_token_auth/omniauth_callbacks#omniauth_success'
  end

in order to handle the callback before it gets redirected by Angular router with hash # in URL as I use

$locationProvider.html5Mode true

so simply I was redirecting to wrong method in my routes.

I have to dig more into new version of Gem to understand the changes.
I'm closing this issue.

Cheers!

@kspe kspe closed this as completed Nov 23, 2014
@stefanahman
Copy link

@ignacykasperowicz how did you solve it? I'm stuck with the same problem.

@kspe
Copy link
Author

kspe commented Jun 1, 2015

@stefanahman Hmmm, I do not think I was looking at it after in more details, I decided to switch to Ember and used other library for authentication. The issue here was that in devise_token_auth the names of methods had changed I think and that is why I was getting NoMethodError. Sorry I cannot help you more with this.

@eugenio1590
Copy link

eugenio1590 commented May 9, 2018

Hi @kspe , I got the same error using the following request:

GET /api/v1/auth/google_oauth2/callback.json?code=4/hNZXTWia27agrvVUGcbS_LwCIFq00BV0jP6GQ1ViQNM&amz;resource_class=User&redirect_uri= HTTP / 1.1
Host: localhost: 8080
X-Requested-With: XMLHttpRequest
Cache-Control: no-cache
Postman-Token: 9b3760ff-996d-4454-8a77-220f98178ed6

The gem is mounted on the path /api/ v1/auth. Is there a parameter missing in the request?
From what I could find, the auth_hash method returns a null value. Why?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants