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

undefined method `match' for nil:NilClass #201

Closed
danielgatis opened this issue Mar 31, 2015 · 7 comments
Closed

undefined method `match' for nil:NilClass #201

danielgatis opened this issue Mar 31, 2015 · 7 comments

Comments

@danielgatis
Copy link

devise_token_auth (0.1.31) app/controllers/devise_token_auth/omniauth_callbacks_controller.rb:161:in `generate_url'

      # ensure that hash-bang is present BEFORE querystring for angularjs
      unless url.match(/#/)
        auth_url += '#'
      end

how can i fix this error?

@lynndylanhurley
Copy link
Owner

What is the value of url?

@danielgatis
Copy link
Author

i got nil at omniauth_params['auth_origin_url'] so the url is nil too

@lynndylanhurley
Copy link
Owner

So the question is, why is omniauth_params['auth_origin_url'] nil? Are you using ng-token-auth or jToker, or are you using a custom client?

@danielgatis
Copy link
Author

neither, I'm doing requests from the browser's adress bar

@jnylen
Copy link

jnylen commented Jun 19, 2015

I have the same issue,
If I uncomment it gets added to the db etc.
But no redirect.

And no current_user.

I'm using ng-token-auth

@saiqulhaq
Copy link

I got same issue here, I using omniauth facebook
I fixed this issue for a moment by modify the omniauth_callback_controller.rb

the @auth_origin_url variable is used by omniauth_response.html.erb for redirecting user, so I though this solution is not perfect

      @auth_origin_url = generate_url(omniauth_params['auth_origin_url'], {
        token:     @token,
        client_id: @client_id,
        uid:       @resource.uid,
        expiry:    @expiry
      })
      # set crazy password for new oauth users. this is only used to prevent
      # access via email sign-in.
      unless @resource.id
        p = SecureRandom.urlsafe_base64(nil, false)
        @resource.password = p
        @resource.password_confirmation = p
      end

      @resource.tokens[@client_id] = {
        token: BCrypt::Password.create(@token),
        expiry: @expiry
      }

      # sync user info with provider, update/generate auth token
      assign_provider_attrs(@resource, auth_hash)

      # assign any additional (whitelisted) attributes
      extra_params = whitelisted_params
      @resource.assign_attributes(extra_params) if extra_params

      # don't send confirmation email!!!
      @resource.skip_confirmation!

      sign_in(:user, @resource, store: false, bypass: false)

      @resource.save!

      # render user info to javascript postMessage communication window
      respond_to do |format|
        format.html { render :layout => "omniauth_response", :template => "devise_token_auth/omniauth_success" }
      end

so I thought it's safe to change generate_url method like this:

BEFORE

    def generate_url(url, params = {})
      auth_url = url

      # ensure that hash-bang is present BEFORE querystring for angularjs
      unless url.match(/#/)
        auth_url += '#'
      end

      # add query AFTER hash-bang
      auth_url += "?#{params.to_query}"

      return auth_url
    end

AFTER

    def generate_url(url, params = {})
      url = '' if url.nil?
      auth_url = url

      # ensure that hash-bang is present BEFORE querystring for angularjs
      unless url.match(/#/)
        auth_url += '#'
      end

      # add query AFTER hash-bang
      auth_url += "?#{params.to_query}"

      return auth_url
    end

I only tested this on facebook provider, I don't know with the others

@booleanbetrayal
Copy link
Collaborator

I don't understand the use-case where auth_origin_url or redirect_url would ever be nil ... Can someone please provide a use-case? Right now, this looks like it's stemming from some sort of mis-configuration.

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

5 participants