Sha256: 9288a8c4b8de0abf035af28f93c67373ef90f5b60395cf2838675d1407ccd993

Contents?: true

Size: 1021 Bytes

Versions: 1

Compression:

Stored size: 1021 Bytes

Contents

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

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

  # 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

1 entries across 1 versions & 1 rubygems

Version Path
nulogy_sso-0.2.0 lib/nulogy_sso.rb