Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

SteffenKeller
Copy link

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)

Copy link

Thanks for opening this pull request!

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

@mtrezza
Copy link
Member

mtrezza commented Mar 4, 2025

Could you please add a test?

Copy link

codecov bot commented Mar 4, 2025

Codecov Report

Attention: 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 47 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.

@SteffenKeller
Copy link
Author

Yes added tests now

@mtrezza
Copy link
Member

mtrezza commented Mar 4, 2025

Restarted CI...

@SteffenKeller
Copy link
Author

SteffenKeller commented Mar 5, 2025

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?

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