Module: Parse::MFA::UserExtension::ClassMethods
- Defined in:
- lib/parse/two_factor_auth/user_extension.rb
Overview
Class methods added to Parse::User
Instance Method Summary collapse
-
#login_with_mfa(username, password, mfa_token) ⇒ User?
Login a user with username, password, and MFA token.
-
#mfa_required?(username) ⇒ Boolean
Check if a user requires MFA for login.
Instance Method Details
#login_with_mfa(username, password, mfa_token) ⇒ User?
Login a user with username, password, and MFA token.
This method handles the Parse Server MFA “additional” policy, which requires both standard credentials AND an MFA token.
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/parse/two_factor_auth/user_extension.rb', line 50 def login_with_mfa(username, password, mfa_token) raise MFA::RequiredError, "MFA token is required" if mfa_token.blank? response = client.login_with_mfa(username, password, mfa_token) return nil unless response.success? Parse::User.build(response.result) rescue Parse::Client::ResponseError => e if e..include?("Invalid MFA token") || e..include?("Missing additional authData") raise MFA::VerificationError, e. end raise end |
#mfa_required?(username) ⇒ Boolean
Check if a user requires MFA for login.
This queries the user’s authData.mfa status using the afterFind hook which returns { status: “enabled” } or { status: “disabled” }.
76 77 78 79 80 81 |
# File 'lib/parse/two_factor_auth/user_extension.rb', line 76 def mfa_required?(username) user = where(username: username).first return false unless user user.mfa_enabled? end |