Sha256: 39d0a660ce7587bcb4be544eecfca6c68ea7e8215786706091d80723637e5a43

Contents?: true

Size: 1.18 KB

Versions: 3

Compression:

Stored size: 1.18 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 ActionController::HttpAuthentication::Basic::ControllerMethods
      include Rails.application.routes.url_helpers

      def self.call(env)
        if ! ::GDS::SSO::ApiAccess.api_call?(env)
          action(:redirect).call(env)
        end
      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

3 entries across 3 versions & 1 rubygems

Version Path
gds-sso-0.4.1 lib/gds-sso/failure_app.rb
gds-sso-0.4.0 lib/gds-sso/failure_app.rb
gds-sso-0.3.0 lib/gds-sso/failure_app.rb