Use omniauth-facebook when app id and app secret are different for each request?

后端 未结 3 1315
迷失自我
迷失自我 2020-12-31 11:38

The omniauth-facebook README mentions how to set it up in an initializer and how to set options like scope per request only. I wonder if it is possible to set a

3条回答
  •  萌比男神i
    2020-12-31 12:31

    I use devise (followed this railscast: http://railscasts.com/episodes/235-devise-and-omniauth-revised), but it took me a while to understand how to implement Ivangrx' solution. It turned out to be quite easy. Here's my code:

    # /config/initializers/devise.rb
    config.omniauth :facebook, setup: true
    
    # routes.rb
    devise_scope :user do  
      #where omniauth_callback is the controller I made when following the Railscast
      get "users/auth/facebook/setup" => "omniauth_callbacks#setup"
    end
    
    # omniauth_callbacks_controller.rb
    def setup
      request.env['omniauth.strategy'].options[:client_id] = @site.facebook_id
      request.env['omniauth.strategy'].options[:client_secret] = @site.facebook_key
      render :text => "Setup complete.", :status => 404
    end
    

    Thanks for the help on this one!

提交回复
热议问题