djangofacebookfacebook-javascript-sdkfacebook-logindjango-allauth

How to test Facebook login with localhost


I'm using Django, and want to make Facebook login with django-allauth.

I made Facebook login with few time, and tested it with localhost.

But I found out that FB login require https after 2018 march, so when I login fb in local runserver, it gives error like Insecure Login Blocked: You can't get an access token or log in to this app from an insecure page. Try re-loading the page as https://.

Is there any way to test fb login in localhost?


Solution

  • You can just use a real subdomain like dev.yourdomain.com and point its DNS to 127.0.0.1 (or can use lvh.me domain since it also point to 127.0.0.1 - but if you trust them all the time)

    Then you need a layer to handle HTTPS in local for https://dev.yourdomain.com. I recommend https://caddyserver.com/

    With a very simple config like this then Caddy can use its self-signed SSL cert (checkout Caddy docs to get the detail)

    dev.yourdomain.com:443 {
        tls self_signed
        proxy / localhost:8080
    }
    

    Then you can open https://dev.yourdomain.com in some browsers like Firefox, Safari, Brave, etc. (I think Chrome blocked self-signed SSL site by default)

    UPDATE I create a note here with more detail

    https://gist.github.com/ralavay/5d74d35859f87d22c74984488f20186c