Sha256: 45093be7290b492d864246039d90b4054a72ace9269e2e039d7a915557ec33cf

Contents?: true

Size: 999 Bytes

Versions: 2

Compression:

Stored size: 999 Bytes

Contents

# frozen_string_literal: true

require "nulogy_sso/engine"
require "immutable-struct"

module NulogySSO
  # Config variables for the engine
  mattr_accessor :sso_config, :find_user_by_email, :handle_sso_error

  # 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)
  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 = ImmutableStruct.new(*REQUIRED_SSO_CONFIG_KEYS)

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
nulogy_sso-1.0.0 lib/nulogy_sso.rb
nulogy_sso-0.5.0 lib/nulogy_sso.rb