Module: BetterAuth::SSO::Utils
- Defined in:
- lib/better_auth/sso/utils.rb
Class Method Summary collapse
- .domain_matches?(search_domain, domain_list) ⇒ Boolean
- .hostname_from_domain(domain) ⇒ Object
- .mask_client_id(client_id) ⇒ Object
- .parse_certificate(cert) ⇒ Object
- .safe_json_parse(value) ⇒ Object
- .validate_email_domain(email, domain) ⇒ Object
Class Method Details
.domain_matches?(search_domain, domain_list) ⇒ Boolean
20 21 22 |
# File 'lib/better_auth/sso/utils.rb', line 20 def domain_matches?(search_domain, domain_list) BetterAuth::Plugins.sso_email_domain_matches?(search_domain, domain_list) end |
.hostname_from_domain(domain) ⇒ Object
46 47 48 |
# File 'lib/better_auth/sso/utils.rb', line 46 def hostname_from_domain(domain) BetterAuth::Plugins.sso_hostname_from_domain(domain) end |
.mask_client_id(client_id) ⇒ Object
50 51 52 |
# File 'lib/better_auth/sso/utils.rb', line 50 def mask_client_id(client_id) BetterAuth::Plugins.sso_mask_client_id(client_id) end |
.parse_certificate(cert) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/better_auth/sso/utils.rb', line 28 def parse_certificate(cert) value = cert.to_s normalized = if value.include?("-----BEGIN") value else body = value.delete("\n\r\t ") "-----BEGIN CERTIFICATE-----\n#{body.scan(/.{1,64}/).join("\n")}\n-----END CERTIFICATE-----" end certificate = OpenSSL::X509::Certificate.new(normalized) fingerprint = OpenSSL::Digest::SHA256.hexdigest(certificate.to_der).upcase.scan(/../).join(":") { fingerprint_sha256: fingerprint, not_before: certificate.not_before, not_after: certificate.not_after, public_key_algorithm: certificate.public_key.class.name.split("::").last.upcase } end |
.safe_json_parse(value) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/better_auth/sso/utils.rb', line 11 def safe_json_parse(value) return nil if value.nil? || value == "" return value if value.is_a?(Hash) || value.is_a?(Array) JSON.parse(value.to_s) rescue JSON::ParserError => error raise Error, "Failed to parse JSON: #{error.}" end |
.validate_email_domain(email, domain) ⇒ Object
24 25 26 |
# File 'lib/better_auth/sso/utils.rb', line 24 def validate_email_domain(email, domain) BetterAuth::Plugins.sso_email_domain_matches?(email, domain) end |