开发者

Working with Facebook Authentication in a Development Environment

When working with facebook authenticati开发者_StackOverflow社区on in a client-side server side mode with OAuth2, is there any way to test it out while working with local development environments for the redirect uris?

Obviously you could specify your IP and route port 80 on that IP to your computer, but is there a more simple way to achieve this?


you shouldn't have any problems developing a facebook app locally.
Just set the url's on facebook settings page to http://localhost/yourapp/ and work as usual.
All the OAuth procedures should work normally.


In my experience so far, you can use the same facebook application for dev, testing, staging, production, etc. The key (alluded to by lnetanel) is that the app should have a distinct return URL configured for each environment. For example, I use devise+omniauth, and have the following in .../config/initializers/omnniauth.rb, which is used to construct return URLs:

if Rails.env.production?
  OmniAuth.config.full_host = "https://www.mydomain.com"
elsif Rails.env.test?
  OmniAuth.config.full_host = "https://www.stag.mydomain.com"
elsif Rails.env.development?
  OmniAuth.config.full_host = "https://localhost.mydomain.com"
end

Note, I have a habit of adding localhost.mydomain.com in my local /etc/hosts file so there are no cross domain issues during development, though that is probably not relevant here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜