Skip to content

feat: Add support for login with additional auth data#1848

Closed
SteffenKeller wants to merge 3 commits into
parse-community:masterfrom
SteffenKeller:mfa
Closed

feat: Add support for login with additional auth data#1848
SteffenKeller wants to merge 3 commits into
parse-community:masterfrom
SteffenKeller:mfa

Conversation

@SteffenKeller

Copy link
Copy Markdown
Contributor

New Pull Request Checklist

Issue Description

Login with additional authData to allow multi-factor authentication (MFA).

Closes: #1839

Approach

A logInWithUsernameInBackground function is added that takes additional authData.

In order to prevent the SDK from passing the mfa object when saving the user the _convertToDictionaryForSaving function was updated to exclude the mfa object.

The login function can be called like this:

PFUser.logInWithUsername(inBackground: username, password: password, authData: ["mfa": ["token": authCode]])

TODOs before merging

  • Add tests
  • Add changes to documentation (guides, repository pages, in-code descriptions)

@parse-github-assistant

Copy link
Copy Markdown

Thanks for opening this pull request!

  • 🎉 We are excited about your hands-on contribution!

@mtrezza

mtrezza commented Mar 4, 2025

Copy link
Copy Markdown
Member

Could you please add a test?

@codecov

codecov Bot commented Mar 4, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.27273% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.98%. Comparing base (dd05d41) to head (0270169).
⚠️ Report is 53 commits behind head on master.

Files with missing lines Patch % Lines
Parse/Parse/Source/PFUser.m 0.00% 14 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master    #1848       +/-   ##
===========================================
+ Coverage   64.24%   82.98%   +18.74%     
===========================================
  Files         201      282       +81     
  Lines       23233    30844     +7611     
===========================================
+ Hits        14926    25596    +10670     
+ Misses       8307     5248     -3059     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@SteffenKeller

Copy link
Copy Markdown
Contributor Author

Yes added tests now

@mtrezza

mtrezza commented Mar 4, 2025

Copy link
Copy Markdown
Member

Restarted CI...

@SteffenKeller

SteffenKeller commented Mar 5, 2025

Copy link
Copy Markdown
Contributor Author

Is there a way to prevent the SDK from sending the mfa object in authData when saving the user without changing the _convertToDictionaryForSaving function?

Saving the user with MFA enabled will send the following to the server: { "key": "updated_value", "authData": { "mfa": { "status": "enabled" } } }

This will not be successful because Parse Server is calling validateUpdate inside the Auth Adapter which fails without a valid TOTP. To prevent this I changed the _convertToDictionaryForSaving function to exclude the mfa object. With this approach saving will be successful but it will also prevent setting up MFA initially since the client has to set the secret like { authData: { mfa: { secret: base32Secret, token: totp } } }.

To fix this and also allow setting up mfa I could update the _convertToDictionaryForSaving function to only exclude the mfa object if it contains "status": "enabled" but maybe there is a better way to solve this?

@mtrezza

mtrezza commented Mar 7, 2025

Copy link
Copy Markdown
Member

Not sure, @parse-community/ios-sdk

@SteffenKeller

Copy link
Copy Markdown
Contributor Author

Closing this as I found a better implementation in #1858

@SteffenKeller SteffenKeller deleted the mfa branch August 12, 2025 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for Login with additional authData

2 participants