因此,我使用OmniAuth和GitHub策略来处理我的项目的用户身份验证。当直接访问Rails服务器时,一切都正常工作。最近,我建立了Nginx来处理开发前端和后端服务器之间的代理。现在,当我访问/auth/github
时,OmniAuth发出了对GitHub的请求,但是在回调时失败了:
Started GET "/auth/github/callback?error=redirect_uri_mismatch" for 127.0.0.1 at 2014-01-22 11:54:35 -0800
I, [2014-01-22T11:54:35.365773 #13656] INFO -- omniauth: (github) Callback phase initiated.
E, [2014-01-22T11:54:35.366091 #13656] ERROR -- omniauth: (github) Authentication failure! redirect_uri_mismatch: OmniAuth::Strategies::OAuth2::CallbackError, redirect_uri_mismatch
E, [2014-01-22T11:54:35.366149 #13656] ERROR -- omniauth: (github) Authentication failure! invalid_credentials: OmniAuth::Strategies::OAuth2::CallbackError, redirect_uri_mismatch
我已经将我的应用程序在GitHub上的设置中的回调URL设置为正确的URL,它显然是正确地发出请求的,就在使用这个神秘的redirect_uri_mismatch
。
这里是我的Nginx服务器块:
server {
listen 8080;
server_name localhost;
location / {
proxy_pass http://localhost:9000;
}
location /api/ {
proxy_pass http://localhost:3000;
}
location /auth/ {
proxy_pass http://localhost:3000;
}
}
虽然我是配置Nginx的相对菜鸟,但我看不出有什么好的理由不应该这样做。
发布于 2014-01-28 01:05:21
好的,这里的问题是我没有正确地设置我的标题。将以下内容添加到Nginx配置中的位置块中,修复了以下问题:
location /api/ {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Client-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://localhost:3000;
}
发布于 2021-03-16 08:03:34
天哪,我花了一个月才修好这件事。我一直在- No route matches [GET] /auth/facebook
Nginx conf
location @rails {
proxy_set_header Host $http_host;
proxy_set_header Client-IP $remote_addr;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://rails_app;
}
Gemfile
#auth
gem 'omniauth-facebook', '~> 8.0'
gem 'omniauth', '~> 1.9.1' #this is important
application.rb
config.force_ssl = ENV['CLIENT_URL'].include?("https")
omniauth.rb
OmniAuth.config.logger = Rails.logger
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, ENV['FACEBOOK_APP_ID'], ENV['FACEBOOK_APP_SECRET'],
scope: 'email',
callback_path: '/api/v1/auth/facebook/callback',
image_size: 'large',
secure_image_url: true,
display: 'touch'
end
https://stackoverflow.com/questions/21292978
复制相似问题