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

Rails 5 current_user is returning NIL #27

Open
Random-Stack-Random-Day opened this issue Jul 18, 2017 · 2 comments
Open

Rails 5 current_user is returning NIL #27

Random-Stack-Random-Day opened this issue Jul 18, 2017 · 2 comments

Comments

@Random-Stack-Random-Day
Copy link

Random-Stack-Random-Day commented Jul 18, 2017

I've been having an issue since I re-tried this gem. I'm noticing that current_user is always being returned as NIL when I try to inact the omniauth-steam function.

I've discussed with multiple other developers, and I can use the exact same function/call for Twitter as I can Steam but Steam will always return 'nil' (Thus not allowing me to properly authorize it against the account).

Has anyone else experienced this, or similar? I see a few mentions from 2015 but no resolutions.

    def steam
        omni = request.env["omniauth.auth"]
        authentication = Authentication.find_by_provider_and_uid(omni['provider'], omni['uid'])
        
        if authentication
            flash[:notice] = "Logged in Successfully"
            sign_in_and_redirect User.find(authentication.user_id)
        elsif current_user # **This is where it should be hitting**
        token = omni['extra']['raw_info'].steamid
        # render :text => request.env["omniauth.auth"].info.to_hash.inspect

        puts token
        token_secret = ""
            
            current_user.authentications.create!(:provider => omni['provider'], 
                                                 :uid => omni['uid'], 
                                                 :token => token, 
                                                 :token_secret => token_secret)
            flash[:notice] = "Authentication successful."
            sign_in_and_redirect current_user
        else
            user = User.new
            user.steam_omni(omni)
        end
        
        if user.save
            flash[:notice] = "Logged in."
            sign_in_and_redirect User.find(user.id)             
        else # **This is where it's actually hitting**
            session[:omniauth] = omni.except('extra')
            redirect_to new_user_registration_path
        end
    end
@Random-Stack-Random-Day
Copy link
Author

Random-Stack-Random-Day commented Jul 18, 2017

For anyone who has this issue, it ended up being a native issue due to CSRF transfer,

Can't verify CSRF token authenticity. This might be due to my IDE needing SSL, but by modifing forgery prevention to

protect_from_forgery with: :null_session, if: Proc.new { |c| c.request.format == 'application/json' }
It will carry through as it should.

Please close if this isn't related to the gem itself - I'm unsure what can be done to fix it preemptively.

@basmoura
Copy link

I had this issue too and the @dnorthrupva suggestion worked fine. Thank you

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

2 participants