Apache背后的Rails应用程序的OpenID [英] OpenID for rails app behind Apache

查看:83
本文介绍了Apache背后的Rails应用程序的OpenID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过Google帐户集成简单的OpenID身份验证.我使用的是omniauth gem,在我的本地开发系统(Win7,ruby 1.8.7-p302,rails 2.3.8,omniauth 0.1.5)上,一切正常.

I'm trying to integrate simple OpenID authentication through Google accounts. I'm using omniauth gem and on my local development system (Win7, ruby 1.8.7-p302, rails 2.3.8, omniauth 0.1.5) everything works nice.

问题显示当我将其部署到主机(HostGator)时,它的外观.该应用程序(杂种)从端口12002开始,并通过HostGator的cPanel将其配置为从以下子域之一重写:

The problem shows it's face when I deploy it to my hosting (HostGator). The app (mongrel) starts at port 12002 and through HostGator's cPanel it's configured to be rewritten from one of subdomains:

RewriteCond %{HTTP_HOST} ^subdomain.mycompany.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.subdomain.mycompany.com$
RewriteRule ^(.*)$ "http\:\/\/127\.0\.0\.1\:12002\/$1" [P,L]

当浏览器进入/auth/open_id时,它将重定向到Google进行授权,但它的return_to地址是subdomain.mycompany.com:12002这当然是不正确的,因为Apache不在12002上进行监听. :: Strategies :: OpenID和Rack :: OpenID,这样,如果属于以下情况,则在用户访问确认后的最后阶段,它们便在没有端口BUT的情况下汇编地址:

When browser goes /auth/open_id it's redirected to Google for authorization but it's return_to address is subdomain.mycompany.com:12002 which of course is incorrect because Apache doesn't listen on 12002. I've managed to monkey patch OmniAuth::Strategies::OpenID and Rack::OpenID so they assemble address without port BUT now on the final stage after user access confirmation if falls into:

Routing Error
No route matches "/403.shtml" with {:method=>:get}

我想问题是我的网站地址在其他授权请求参数处被编码(某种哈希)以避免

I guess the problem is what my site's address is encoded (some kind of hash) at other authorization request parameter to avoid

推荐答案

端口问题是由于RACK请求计算端口的方式引起的.这是补丁

The port issue is because of the the way RACK request computes the port. Here is the patch

require 'rack/utils'
module Rack
  class Request
    def port
      if host_with_port =~ /:(\d+)$/
        $1.to_i
      else
        standard_port
      end
    end

    # Returns the standard \port number for this request's protocol.
    def standard_port
      case protocol
        when 'https://' then 443
        else 80
      end
    end

    # Returns 'https://' if this is an SSL request and 'http://' otherwise.
    def protocol
      ssl? ? 'https://' : 'http://'
    end

    # Is this an SSL request?
    def ssl?
      @env['HTTPS'] == 'on' || @env['HTTP_X_FORWARDED_PROTO'] == 'https'
    end
  end
end

这是Rails ActionController :: Request计算端口的方式.

This is the way rails ActionController::Request computes the port.

希望这会有所帮助

这篇关于Apache背后的Rails应用程序的OpenID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆