Sha256: 2cd3835b8230145f337f5fb3f0d92217ae098e0d5dd5be7ad8b5ae48572530ba

Contents?: true

Size: 852 Bytes

Versions: 3

Compression:

Stored size: 852 Bytes

Contents

Warden::Manager.after_authentication do |user, auth, options|
  if auth.env["action_dispatch.cookies"]
    expected_cookie_value = "#{user.class}-#{user.public_send(Devise.second_factor_resource_id)}"
    actual_cookie_value = auth.env["action_dispatch.cookies"].signed[TwoFactorAuthentication::REMEMBER_TFA_COOKIE_NAME]
    bypass_by_cookie = actual_cookie_value == expected_cookie_value
  end

  if user.respond_to?(:need_two_factor_authentication?) && !bypass_by_cookie
    if auth.session(options[:scope])[TwoFactorAuthentication::NEED_AUTHENTICATION] = user.need_two_factor_authentication?(auth.request)
      user.send_new_otp if user.send_new_otp_after_login?
    end
  end
end

Warden::Manager.before_logout do |user, auth, _options|
  auth.cookies.delete TwoFactorAuthentication::REMEMBER_TFA_COOKIE_NAME if Devise.delete_cookie_on_logout
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
two_factor_authentication-2.2.0 lib/two_factor_authentication/hooks/two_factor_authenticatable.rb
two_factor_authentication-2.1.1 lib/two_factor_authentication/hooks/two_factor_authenticatable.rb
two_factor_authentication-2.1.0 lib/two_factor_authentication/hooks/two_factor_authenticatable.rb