Module: BetterAuth::SSO::Routes::Schemas

Defined in:
lib/better_auth/sso/routes/schemas.rb

Constant Summary collapse

OIDC_MAPPING_KEYS =
%i[id email email_verified name image extra_fields].freeze
SAML_MAPPING_KEYS =
%i[id email email_verified name first_name last_name extra_fields].freeze
OIDC_CONFIG_KEYS =
%i[
  client_id
  client_secret
  authorization_endpoint
  token_endpoint
  user_info_endpoint
  token_endpoint_authentication
  jwks_endpoint
  discovery_endpoint
  scopes
  pkce
  override_user_info
  mapping
].freeze
SAML_CONFIG_KEYS =
%i[
  entry_point
  cert
  callback_url
  audience
  idp_metadata
  sp_metadata
  want_assertions_signed
  authn_requests_signed
  want_logout_request_signed
  want_logout_response_signed
  signature_algorithm
  digest_algorithm
  identifier_format
  private_key
  decryption_pvk
  additional_params
  mapping
].freeze

Class Method Summary collapse

Class Method Details

.oidc_config_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/better_auth/sso/routes/schemas.rb', line 67

def oidc_config_key?(key)
  OIDC_CONFIG_KEYS.include?(BetterAuth::Plugins.normalize_key(key))
end

.plugin_schema(config = {}) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/better_auth/sso/routes/schemas.rb', line 45

def plugin_schema(config = {})
  normalized = BetterAuth::Plugins.normalize_hash(config || {})
  fields = {
    issuer: {type: "string", required: true},
    oidcConfig: {type: "string", required: false},
    samlConfig: {type: "string", required: false},
    userId: {type: "string", required: true},
    providerId: {type: "string", required: true, unique: true},
    domain: {type: "string", required: true},
    organizationId: {type: "string", required: false}
  }
  if normalized.dig(:domain_verification, :enabled)
    fields[:domainVerified] = {type: "boolean", required: false, default_value: false}
  end
  {
    ssoProvider: {
      model_name: normalized[:model_name] || "ssoProviders",
      fields: fields
    }
  }
end

.saml_config_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/better_auth/sso/routes/schemas.rb', line 71

def saml_config_key?(key)
  SAML_CONFIG_KEYS.include?(BetterAuth::Plugins.normalize_key(key))
end