Sha256: c89d2d32a6c83e467441df9494922f38644e34c5511f9b41ccd269a734d70f9f

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 KB

Contents

require "action_controller/metal"
require 'rails'

# Failure application that will be called every time :warden is thrown from
# any strategy or hook. 
module GDS
  module SSO
    class FailureApp < ActionController::Metal
      include ActionController::RackDelegation
      include ActionController::UrlFor
      include ActionController::Redirecting
      include Rails.application.routes.url_helpers

      def self.call(env)
        action(:respond).call(env)
      end

      def respond
        redirect
      end

      def redirect
        store_location!
        redirect_to '/auth/gds'
      end

      # Stores requested uri to redirect the user after signing in. We cannot use
      # scoped session provided by warden here, since the user is not authenticated
      # yet, but we still need to store the uri based on scope, so different scopes
      # would never use the same uri to redirect.

      # TOTALLY NOT DOING THE SCOPE THING. PROBABLY SHOULD.
      def store_location!
        session["return_to"] = env['warden.options'][:attempted_path] if request.get?
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gds-sso-0.1.1 lib/gds-sso/failure_app.rb
gds-sso-0.1.0 lib/gds-sso/failure_app.rb