Class: Sanger::Rack::Authentication::SSO
- Inherits:
-
Object
- Object
- Sanger::Rack::Authentication::SSO
- Defined in:
- lib/rack_authentication_sso.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, settings = {}) ⇒ SSO
constructor
A new instance of SSO.
- #redirect_to_sso_server ⇒ Object
- #sso_login_from_cookie(cookie_value) ⇒ Object
Constructor Details
#initialize(app, settings = {}) ⇒ SSO
Returns a new instance of SSO.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/rack_authentication_sso.rb', line 11 def initialize(app, settings = {}) @config = OpenStruct.new @config.magic_header_name = settings["magic_header_name"] @config. = settings["cookie_name"] @config.validation_url = settings["validation_url"] @config.user_agent = settings["user_agent"] @config.sso_redirection_url = settings["sso_redirection_url"] @config.error_text = settings["error_text"] @app = app end |
Instance Method Details
#call(env) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rack_authentication_sso.rb', line 23 def call(env) @request = ::Rack::Request.new(env) @request.env.delete(@config.magic_header_name) = @request.[@config.] begin user = () unless .nil? if user @request.env[@config.magic_header_name] = user @app.call(@request.env) else redirect_to_sso_server end rescue ::OpenURI::HTTPError error_text = @config.error_text.to_s [503, {"Content-Type" => "text/plain", "Content-Length" => error_text.length.to_s}, [error_text]] end end |
#redirect_to_sso_server ⇒ Object
55 56 57 58 59 60 |
# File 'lib/rack_authentication_sso.rb', line 55 def redirect_to_sso_server @response = ::Rack::Response.new destination = ::CGI::escape(@request.url) @response.redirect([@config.sso_redirection_url, destination].join) @response.finish end |
#sso_login_from_cookie(cookie_value) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rack_authentication_sso.rb', line 41 def () login = nil ::OpenURI.open_uri(@config.validation_url, "Cookie" => "#{@config.}=#{}", "User-Agent" => @config.user_agent) do |http| login = http.read.strip end if login == '*' return nil else return login end end |