Class: Rack::Auth::NginxOmniauthAdapter::Initiate
- Inherits:
-
Object
- Object
- Rack::Auth::NginxOmniauthAdapter::Initiate
- Defined in:
- lib/rack/auth/nginx_omniauth_adapter.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, auth_host:, callback_path: '/_auth/callback') ⇒ Initiate
constructor
A new instance of Initiate.
Constructor Details
#initialize(app, auth_host:, callback_path: '/_auth/callback') ⇒ Initiate
Returns a new instance of Initiate.
28 29 30 |
# File 'lib/rack/auth/nginx_omniauth_adapter.rb', line 28 def initialize(app, auth_host:, callback_path: '/_auth/callback') @app, @auth_host, @callback_path = app, auth_host, callback_path end |
Instance Method Details
#call(env) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/rack/auth/nginx_omniauth_adapter.rb', line 32 def call(env) res = @app.call(env) if res[0].to_i == 401 https = Net::HTTP.new(@auth_host, 443) https.use_ssl = true req = Net::HTTP::Get.new('/initiate') req['x-ngx-omniauth-initiate-back-to'] = "https://#{env['HTTP_HOST']}#{env['REQUEST_URI']}" req['x-ngx-omniauth-initiate-callback'] = "https://#{env['HTTP_HOST']}#{@callback_path}" req['cookie'] = env['HTTP_COOKIE'] response = https.request(req) return [ response.code.to_i, response.to_hash, [ response.body ] ] end res end |