Sha256: bccec79fde4117b7e35ef3bd893150844c547e320d01de20114a5a689d25e06a

Contents?: true

Size: 1.85 KB

Versions: 3

Compression:

Stored size: 1.85 KB

Contents

require "rails"

require "gds-sso/config"
require "gds-sso/version"
require "gds-sso/warden_config"
require "omniauth"
require "omniauth-gds"

require "gds-sso/railtie" if defined?(Rails)

module GDS
  module SSO
    autoload :FailureApp,        "gds-sso/failure_app"
    autoload :ControllerMethods, "gds-sso/controller_methods"
    autoload :User,              "gds-sso/user"
    autoload :ApiAccess,         "gds-sso/api_access"

    # User to return as logged in during tests
    mattr_accessor :test_user

    def self.config
      yield GDS::SSO::Config
    end

    class Engine < ::Rails::Engine
      # Force routes to be loaded if we are doing any eager load.
      # TODO - check this one - Stolen from Devise because it looked sensible...
      config.before_eager_load(&:reload_routes!)

      OmniAuth.config.allowed_request_methods = %i[post get]

      config.app_middleware.use ::OmniAuth::Builder do
        next if GDS::SSO::Config.api_only

        provider :gds, GDS::SSO::Config.oauth_id, GDS::SSO::Config.oauth_secret,
                 client_options: {
                   site: GDS::SSO::Config.oauth_root_url,
                   authorize_url: "#{GDS::SSO::Config.oauth_root_url}/oauth/authorize",
                   token_url: "#{GDS::SSO::Config.oauth_root_url}/oauth/access_token",
                   connection_opts: {
                     headers: {
                       user_agent: "gds-sso/#{GDS::SSO::VERSION} (#{ENV['GOVUK_APP_NAME']})",
                     },
                   },
                 }
      end

      def self.default_strategies
        Config.use_mock_strategies? ? %i[mock_gds_sso gds_bearer_token] : %i[gds_sso gds_bearer_token]
      end

      config.app_middleware.use Warden::Manager do |config|
        config.default_strategies(*default_strategies)
        config.failure_app = GDS::SSO::FailureApp
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
gds-sso-17.0.0 lib/gds-sso.rb
gds-sso-16.1.0 lib/gds-sso.rb
gds-sso-16.0.2 lib/gds-sso.rb