简体   繁体   English

Omniauth-facebook登录无法正常工作

[英]Omniauth-facebook login not working

When I try to login in my Rails app using omniauth-facebook, I'm getting the following error. 当我尝试使用omniauth-facebook登录我的Rails应用程序时,我收到以下错误。 This is when testing on localhost:3000: 这是在localhost:3000上测试的时候:

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:// 尝试将页面重新加载为https://

I saw this other recent post on SO , but Facebook doesn't seem to be allowing me to change the "Enforce HTTPS for Web OAuth Login" settings in the developer console for this app that I created today. 在SO上看到了最近的另一篇文章 ,但Facebook似乎并没有允许我在今天创建的这个应用程序的开发者控制台中更改“为Web OAuth登录强制HTTPS”设置。 I can change that setting for old apps. 我可以更改旧应用的设置。

Any ideas on how to fix this or get around it? 关于如何解决这个问题或绕过它的任何想法? I'll use HTTPS in production, but just want to be able to use localhost (http) in development. 我将在生产中使用HTTPS,但只是希望能够在开发中使用localhost(http)。

Running local server in HTTPS mode can be useful many times, not just only for the facebook api. 以HTTPS模式运行本地服务器可能很多次,不仅仅适用于facebook api。

Though, Rails still do not provide an easy way to run rails server in SSL mode. 虽然,Rails仍然没有提供在SSL模式下运行rails服务器的简单方法 But there're several ways to achieve that: 但有几种方法可以实现这一目标:

Use thin server instead of puma/webrick rails default one 使用thin服务器而不是puma / webrick rails默认值

thin server allows you to run your application in SSL mode with a minimum effort: thin服务器允许您以最少的工作量以SSL模式运行应用程序:

Edit config/application.rb and add: 编辑config/application.rb并添加:

config.force_ssl = true

Start thin server: 启动thin服务器:

$ thin start --ssl

See full info about that here: How to enable SSL for Rails development environment in two minutes? 请参阅此处的完整信息: 如何在两分钟内为Rails开发环境启用SSL?

Use http tunnel tools like ngrok 使用像ngrok这样的http隧道工具

Tools like ngrok allow you to create a tunnel form your localhost to the Internet with ease - it also creates both http:// and https:// endpoints for you: ngrok这样的工具允许您轻松地创建从本地主机到Internet的隧道 - 它还为您创建http://https://端点:

$ rails s -p 3000
$ ./ngrok http 3000

ngrok by @inconshreveable                                                                                                                                            (Ctrl+C to quit)

Session Status                online                                                                                                                                                 
Session Expires               7 hours, 59 minutes                                                                                                                                    
Version                       2.2.8                                                                                                                                                  
Region                        United States (us)                                                                                                                                     
Web Interface                 http://127.0.0.1:4040                                                                                                                                  
Forwarding                    http://2608e936.ngrok.io -> localhost:3000                                                                                                             
Forwarding                    https://2608e936.ngrok.io -> localhost:3000    

Copy the generated url (like https://2608e936.ngrok.io and use it to access your local server. 复制生成的URL(如https://2608e936.ngrok.io并使用它来访问本地服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM