module Clerk

We're not including this in clerk-rails/app/helpers because it is injected into ActionController::Base via initializes/add_application_helpers and cannot be in the autoload path stackoverflow.com/questions/29636334/a-copy-of-xxx-has-been-removed-from-the-module-tree-but-is-still-active

Constants

VERSION

Attributes

config[R]

Public Class Methods

accounts_url() click to toggle source
# File lib/clerk-rails.rb, line 36
def accounts_url
  @accounts_url ||= "https://#{Clerk.config.accounts_host}"
end
api() click to toggle source
# File lib/clerk-rails.rb, line 21
def api
  @conn ||= Clerk::Api::Connection.new(
    (ENV["CLERK_API_PATH"] || "https://api.clerk.dev"),
    key_secret
  )
end
app_url() click to toggle source
# File lib/clerk-rails.rb, line 40
def app_url
  @app_url ||= "https://#{Clerk.config.app_host}"
end
cipher_key() click to toggle source
# File lib/clerk-rails.rb, line 44
def cipher_key
  @cipher_key ||= ::Base64.strict_decode64(Clerk.config.cipher_key)
end
configure() { |config| ... } click to toggle source
# File lib/clerk-rails.rb, line 12
def configure
  @config = Configuration.new
  yield config
end
database_connection_url() click to toggle source
# File lib/clerk-rails.rb, line 17
def database_connection_url
  @database_connection_url ||= "#{Clerk.config.database_url}?prepared_statements=false"
end
decrypt(encrypted_message) click to toggle source
# File lib/clerk-rails.rb, line 48
def decrypt(encrypted_message)
  cipher = OpenSSL::Cipher.new("aes-256-gcm")

  encrypted_data, iv, auth_tag = encrypted_message.split("--".freeze).map { |v| ::Base64.strict_decode64(v) }

  # Currently the OpenSSL bindings do not raise an error if auth_tag is
  # truncated, which would allow an attacker to easily forge it. See
  # https://github.com/ruby/openssl/issues/63
  raise InvalidMessage if (auth_tag.nil? || auth_tag.bytes.length != 16)

  cipher.decrypt
  cipher.key = cipher_key
  cipher.iv  = iv
  cipher.auth_tag = auth_tag
  cipher.auth_data = ""

  message = cipher.update(encrypted_data)
  message << cipher.final
  message
end
email( account: nil, to_email_address: nil, from_email_name: nil, email_template_token: nil, replacements: nil, subject: nil, body: nil ) click to toggle source
# File lib/clerk-rails.rb, line 69
def email(
  account: nil,
  to_email_address: nil,
  from_email_name: nil,
  email_template_token: nil,
  replacements: nil,
  subject: nil,
  body: nil
)
  email = Clerk::Email.create(
    account_id: account&.id,
    to_email_address: to_email_address, 
    from_email_name: from_email_name,
    email_template_token: email_template_token,
    replacements: replacements.nil? ? nil : replacements.to_json,
    subject: subject,
    body: body
  )
end
key() click to toggle source
# File lib/clerk-rails.rb, line 28
def key
  ENV['CLERK_KEY']
end
key_secret() click to toggle source
# File lib/clerk-rails.rb, line 32
def key_secret
  ENV['CLERK_KEY']&.slice(5..-1)
end