Facebook login - how to develop on both localhost and in production?

后端 未结 6 2408
南方客
南方客 2020-12-29 02:57

I am developing a website which uses the Facebook login. Now, I want to be able to get this to work both in my production environment, as well as in my development environme

相关标签:
6条回答
  • 2020-12-29 03:31

    I have the same problem.

    The only solutions I have found are:

    • yes... edit the host file on your local machine: How to Test Facebook Connect Locally
    • create another Facebook app only for development purposes: Facebook Oauth on localhost for testing during development (the blog is about Rails but the solution to use different apps depending on the environment is still valid for other languages)
    0 讨论(0)
  • 2020-12-29 03:35

    After I have worked with this for ~6 months, I have found a solution which works really well, based on the other two answers.

    In Facebook I add two apps:

    • Production app
    • Dev app

    Then, in my web.config app settings I have:

    <!--Prod-->
    <add key="_FacebookApiId" value="id"/>
    <add key="_FacebookApiSecretId" value="secret_id"/>
    <!--Dev-->
    <add key="FacebookApiId" value="dev_id"/>
    <add key="FacebookApiSecretId" value="dev_secret_id"/>
    

    Which of course is read through a helper-class.

    Then it works seamlessly on both production and localhost, and both myself and my team is happy.

    0 讨论(0)
  • 2020-12-29 03:40

    Update: As of 2018 the path to this setting is now Products > Facebook Login > Settings > Client OAuth Settings the rest of this answer is still valid.


    There is a better way. You just need to add valid callback URL's for your localhost to Settings > Advanced > OAuth Settings.

    enter image description here

    This method allows you still have your production website URL while allowing oauth from dev, staging, production, etc.

    0 讨论(0)
  • 2020-12-29 03:40

    Following the advice in this answer, it will work if set the Mobile URL to be your development domain (ie. localhost) and the Site URL to be your production domain.

    0 讨论(0)
  • 2020-12-29 03:45

    Facebook only allows localhost OAuth redirects when your app is in development mode. This means you can't run your application in production and perform local development tests.

    Instead, you need to create a test variant of your app. Head to https://developers.facebook.com and view the dashboard for your production application. Click the drop-down menu at the top-left and choose Create Test App.

    This populates a test application with almost the same settings as your production app. However, it gives you a new app ID and app secret, so you'll need to toggle these settings when running in development mode (as other answers suggest).

    Here's some further info on test apps: https://developers.facebook.com/docs/apps/test-apps/

    0 讨论(0)
  • 2020-12-29 03:48

    The updated way.

    In the App Dashboard, choose your app and go to Products > Facebook Login > Settings. Under the Client OAuth Settings, enter your redirect URL in the Valid OAuth redirect URIs field for successful authorization.

    Go to https://developers.facebook.com/docs/facebook-login/web for more info.

    0 讨论(0)
提交回复
热议问题