Sha256: 8be324481456528494742fc18757ef83927ffb179b90d0a5e14dad8a1f098883

Contents?: true

Size: 1.15 KB

Versions: 8

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

require "nulogy_sso/engine"

module NulogySSO
  # Config variables for the engine
  mattr_accessor :sso_config, :find_user_by_email, :handle_sso_error
  mattr_accessor :handle_unauthenticated_request, default: lambda { |controller|
    controller.redirect_to NulogySSO::Engine.routes.url_helpers.login_path
  }

  # Public Constants
  JWT_EMAIL_KEY = "https://nulogy.net/email"

  def self.sso_config=(sso_config_hash)
    raise "sso_config must be a Hash" unless sso_config_hash.is_a? Hash

    missing_keys = REQUIRED_SSO_CONFIG_KEYS - sso_config_hash.symbolize_keys.keys
    if missing_keys.present?
      raise "Missing required sso_config keys ['#{missing_keys.join("', '")}']"
    end

    @@sso_config = SSOConfig.new(**sso_config_hash.symbolize_keys.slice(*REQUIRED_SSO_CONFIG_KEYS))
  end

  REQUIRED_SSO_CONFIG_KEYS = %i[
    audience
    base_uri
    client_id
    client_secret
    cookie_prefix
    login_uri
    redirect_uri
  ]
  private_constant :REQUIRED_SSO_CONFIG_KEYS

  SSOConfig = Struct.new(*REQUIRED_SSO_CONFIG_KEYS, keyword_init: true)

  def self.sso_cookie_key
    "#{sso_config.cookie_prefix}_access_token"
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
nulogy_sso-2.5.0 lib/nulogy_sso.rb
nulogy_sso-2.4.0 lib/nulogy_sso.rb
nulogy_sso-2.3.1 lib/nulogy_sso.rb
nulogy_sso-2.3.0 lib/nulogy_sso.rb
nulogy_sso-2.2.0 lib/nulogy_sso.rb
nulogy_sso-2.1.3 lib/nulogy_sso.rb
nulogy_sso-2.1.2 lib/nulogy_sso.rb
nulogy_sso-2.1.1 lib/nulogy_sso.rb