Dealing with Oauth 2.0-facebook gem error 100: This authorization code has been used

前端 未结 6 1585
囚心锁ツ
囚心锁ツ 2021-02-07 05:44

I have been working on setting up facebook authentication for my rails app and while testing, after logging-in with my facebook account, I keep getting this error:



        
6条回答
  •  眼角桃花
    2021-02-07 06:44

    I had the same problem and finally found what was the issue in my case. So for those, who has this problem and uses just Omniauth without Devise, the root cause of the problem might be in an incorrect route for redirection.

    1. Check you server development.log
    2. Find where it redirects (grep by "Redirected to")
    3. Here is the main point: Check in the log if the callback URL is correct

    In my case, in routes.rb I had, for example:

    get "mycontroller/home"
    

    which is okay, but in my SessionController I also had:

    def create
        auth_hash = request.env['omniauth.auth']
        user = User.from_omniauth(auth_hash)
        session[:user_id] = user.id
        redirect_to "mycontroller/home"
    end
    

    So I made it working by changing this line in the controller from:

    redirect_to "mycontroller/home"
    

    to

    redirect_to "/mycontroller/home"
    

提交回复
热议问题