instance method
message_verifiers
Ruby on Rails 7.2.3
Since v7.1.6Signature
message_verifiers()
Returns a message verifier factory (ActiveSupport::MessageVerifiers). This factory can be used as a central point to configure and create message verifiers (ActiveSupport::MessageVerifier) for your application.
By default, message verifiers created by this factory will generate messages using the default ActiveSupport::MessageVerifier options. You can override these options with a combination of ActiveSupport::MessageVerifiers#clear_rotations and ActiveSupport::MessageVerifiers#rotate. However, this must be done prior to building any message verifier instances. For example, in a before_initialize block:
# Use `url_safe: true` when generating messages
config.before_initialize do |app|
app.message_verifiers.clear_rotations
app.message_verifiers.rotate(url_safe: true)
end
Message verifiers created by this factory will always use a secret derived from #secret_key_base when generating messages. clear_rotations will not affect this behavior. However, older secret_key_base values can be rotated for verifying messages:
# Fall back to old `secret_key_base` when verifying messages
config.before_initialize do |app|
app.message_verifiers.rotate(secret_key_base: "old secret_key_base")
end
Source
# File railties/lib/rails/application.rb, line 203
def message_verifiers
@message_verifiers ||=
ActiveSupport::MessageVerifiers.new do |salt, secret_key_base: self.secret_key_base|
key_generator(secret_key_base).generate_key(salt)
end.rotate_defaults
end
Defined in railties/lib/rails/application.rb line 203
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in Rails::Application