Sha256: 5bafefecd85e41a4c009f0717cce6c4ead913ca3be70c0599ad4a29c2587f0eb

Contents?: true

Size: 1016 Bytes

Versions: 4

Compression:

Stored size: 1016 Bytes

Contents

# frozen_string_literal: true

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

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

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

  def self.auth_config=(auth_config_hash)
    raise "auth_config must be a Hash" unless auth_config_hash.is_a? Hash

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

    @@auth_config = AuthConfig.new(**auth_config_hash.symbolize_keys)
  end

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

  AuthConfig = ImmutableStruct.new(*REQUIRED_AUTH_CONFIG_KEYS)

  def self.auth_cookie_key
    "#{auth_config.cookie_prefix}_access_token"
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
nulogy_sso-0.4.0 lib/nulogy_sso.rb
nulogy_sso-0.3.3 lib/nulogy_sso.rb
nulogy_sso-0.3.1 lib/nulogy_sso.rb
nulogy_sso-0.3.0 lib/nulogy_sso.rb