Repository navigation
feat: Add SMS Auth - #1362
feat: Add SMS Auth#1362IzenDev wants to merge 39 commits into
Conversation
|
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
|
I have read the CLA Document and I hereby sign the CLA |
|
The test failed after I modified |
|
Could you try to run Since you have changed the database definitions it might simply be an issue with the database state that is out of sync. |
|
You can also run these test locally by executing the script |
|
@Isakdl All the tests passed locally. Thanks. |
SandPod
left a comment
There was a problem hiding this comment.
This is really awesome work and I look forward to getting this into Serverpod. It is a highly requested feature and will be very welcome by the community.
This is a first review on the backend code.
Once the comments are fixed, please rebase on latest main and I will review the frontend part.
Tests will be important for getting this merged.
| table: serverpod_sms_auth | ||
| fields: | ||
| ### The id of the user, corresponds to the id field in the [UserInfo]. | ||
| userId: int |
There was a problem hiding this comment.
Question: Would we benefit from using a one-to-one relation here instead? https://docs.serverpod.dev/concepts/database/relations/one-to-one
That would enable us to have the record automatically removed when the user entry is removed.
| if (await _hasTooManyFailedSignIns(session, phoneNumber)) { | ||
| return AuthenticationResponse( | ||
| success: false, | ||
| failReason: AuthenticationFailReason.tooManyFailedAttempts); |
There was a problem hiding this comment.
Suggestion (NIT): Add comma to improve formatting.
| failReason: AuthenticationFailReason.tooManyFailedAttempts); | |
| failReason: AuthenticationFailReason.tooManyFailedAttempts, | |
| ); |
| import 'package:serverpod_auth_server/src/business/sms_auth.dart'; | ||
|
|
||
| /// Endpoint for handling Sign in with SMS. | ||
| class SmsEndpoint extends Endpoint { |
There was a problem hiding this comment.
Suggestion: Move all business logic from Endpoint to make it testable without a client.
The more we can isolate what we test the better feedback future developers will get when they try and change the code. Moving the required tests from e2e tests to integration tests enables us to better control the environment and hopefully provide better feedback to future developers.
| var dataToHash = '$phoneNumber$otp$secretHashKey'; | ||
| var hmac = Hmac(sha256, utf8.encode(secretHashKey)); |
There was a problem hiding this comment.
Suggestion: Remove secretHashKey from dataToHash.
It is enough to use the secretHashKey as key for the Hmac encryption.
| var secretHashKey = | ||
| Serverpod.instance.getPassword('SMSHash') ?? 'serverpod SMS hash'; |
There was a problem hiding this comment.
Suggestion: Remove the default value and throw if no value is set.
Having default hash key values is not recommended, users will probably forget to set it and end up having easily guessable OTP hashes. Better to require users to set their own hash key.
We are aiming to change this for the other authentication methods as well.
There was a problem hiding this comment.
Suggestion: Enforce min key length based on best practice for Hmac-sha256.
As far as I can read the recommended key lenght is at least 64 bytes. We should help our users make good decisions there and enforce a minimum of 64 bytes when configuring the key.
| ); | ||
|
|
||
| if (entry == null) { | ||
| session.log(' - no entry found', level: LogLevel.debug); |
There was a problem hiding this comment.
Suggestion: change logging message to creating new user.
There was a problem hiding this comment.
Also, harmonize this log message with the next one. This seems to give a strange flow.
| // Create user if it doesn't exist and return it | ||
| if (userInfo == null) { | ||
| session.log('- user not fount', level: LogLevel.debug); | ||
| return AuthenticationResponse( | ||
| success: false, | ||
| failReason: AuthenticationFailReason.invalidCredentials, | ||
| ); | ||
| } |
There was a problem hiding this comment.
Question: The comment above doesn't seem to match what this code does.
Could we avoid multiple lookups for the user in the database? Maybe we could return it as a record from the SMSs.createUser method?
| @@ -0,0 +1,63 @@ | |||
| # This file is generated. Do not modify, instead edit the files in the templates/pubspecs directory. | |||
There was a problem hiding this comment.
Suggestion: This pubspec needs to be reflected in the templates folder.
Please check the other flutter pubspecs in the template folder.
| @@ -0,0 +1,4 @@ | |||
| include: package:flutter_lints/flutter.yaml | |||
There was a problem hiding this comment.
Suggestion: Change to include: package:serverpod_lints/public_flutter.yaml
| @@ -0,0 +1 @@ | |||
| //Todo: Write test | |||
There was a problem hiding this comment.
Chore: This code needs tests.
I'm working on a PR now that might help set the expectation around what tests are required: #1993
SandPod
left a comment
There was a problem hiding this comment.
Please see comments in the previous post.
|
Can u help me to get the sms of +971543566766 and |
|
Closing this as stale. This is connected to issue #2050 and can be used as refeference once this is picked up. Since we are working on the new authentication module. This will be added as a provider there instead. |
This adds the built-in feature for SMS Auth with the new package
serverpod_auth_sms_flutter, which allows the client to authenticate users with SMS and with their favorite SMS provider without worrying about the Verification code being stored in the database.Added
SMS Authto authenticate users with phones.Pre-launch Checklist
///), and made sure that the documentation follows the same style as other Serverpod documentation. I checked spelling and grammar.If you need help, consider asking for advice on the discussion board.
Breaking changes
None