-
-
Notifications
You must be signed in to change notification settings - Fork 258
feat(gotrue): Add phone mfa enrollment #1188
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8ca8187
feat: phone mfa enrollment
dshukertjr 0a37c2d
fix json parsing
dshukertjr 48bd503
properly get a challenge id in test
dshukertjr a7c91f6
format document
dshukertjr a17f875
format mfa api
dshukertjr c13ed34
Update packages/gotrue/lib/src/gotrue_mfa_api.dart
dshukertjr 30aa27a
format document
dshukertjr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,23 +4,33 @@ class AuthMFAEnrollResponse { | |
/// ID of the factor that was just enrolled (in an unverified state). | ||
final String id; | ||
|
||
/// Type of MFA factor. Only `[FactorType.totp] supported for now. | ||
/// Type of MFA factor. Supports both `[FactorType.totp]` and `[FactorType.phone]`. | ||
final FactorType type; | ||
|
||
/// TOTP enrollment information. | ||
final TOTPEnrollment totp; | ||
/// TOTP enrollment information (only present when type is totp). | ||
final TOTPEnrollment? totp; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know this isn't great, but I think we can call it that it's a fix. Open to suggestions to avoid this though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
/// Phone enrollment information (only present when type is phone). | ||
final PhoneEnrollment? phone; | ||
|
||
const AuthMFAEnrollResponse({ | ||
required this.id, | ||
required this.type, | ||
required this.totp, | ||
this.totp, | ||
this.phone, | ||
}); | ||
|
||
factory AuthMFAEnrollResponse.fromJson(Map<String, dynamic> json) { | ||
final type = FactorType.values.firstWhere((e) => e.name == json['type']); | ||
return AuthMFAEnrollResponse( | ||
id: json['id'], | ||
type: FactorType.values.firstWhere((e) => e.name == json['type']), | ||
totp: TOTPEnrollment.fromJson(json['totp']), | ||
type: type, | ||
totp: type == FactorType.totp && json['totp'] != null | ||
? TOTPEnrollment.fromJson(json['totp']) | ||
: null, | ||
phone: type == FactorType.phone && json['phone'] != null | ||
? PhoneEnrollment._fromJsonValue(json['phone']) | ||
: null, | ||
); | ||
} | ||
} | ||
|
@@ -54,6 +64,34 @@ class TOTPEnrollment { | |
} | ||
} | ||
|
||
class PhoneEnrollment { | ||
/// The phone number that will receive the SMS OTP. | ||
final String phone; | ||
|
||
const PhoneEnrollment({ | ||
required this.phone, | ||
}); | ||
|
||
factory PhoneEnrollment.fromJson(Map<String, dynamic> json) { | ||
return PhoneEnrollment( | ||
phone: json['phone'], | ||
); | ||
} | ||
|
||
factory PhoneEnrollment._fromJsonValue(dynamic value) { | ||
if (value is String) { | ||
// Server returns phone number as a string directly | ||
return PhoneEnrollment(phone: value); | ||
} else if (value is Map<String, dynamic>) { | ||
// Server returns phone data as an object | ||
return PhoneEnrollment.fromJson(value); | ||
} else { | ||
throw ArgumentError( | ||
'Invalid phone enrollment data type: ${value.runtimeType}'); | ||
} | ||
} | ||
} | ||
|
||
class AuthMFAChallengeResponse { | ||
/// ID of the newly created challenge. | ||
final String id; | ||
|
@@ -120,8 +158,13 @@ class AuthMFAUnenrollResponse { | |
class AuthMFAListFactorsResponse { | ||
final List<Factor> all; | ||
final List<Factor> totp; | ||
final List<Factor> phone; | ||
|
||
AuthMFAListFactorsResponse({required this.all, required this.totp}); | ||
AuthMFAListFactorsResponse({ | ||
required this.all, | ||
required this.totp, | ||
required this.phone, | ||
}); | ||
} | ||
|
||
class AuthMFAAdminListFactorsResponse { | ||
|
@@ -151,7 +194,7 @@ class AuthMFAAdminDeleteFactorResponse { | |
|
||
enum FactorStatus { verified, unverified } | ||
|
||
enum FactorType { totp } | ||
enum FactorType { totp, phone } | ||
|
||
class Factor { | ||
/// ID of the factor. | ||
|
@@ -160,7 +203,7 @@ class Factor { | |
/// Friendly name of the factor, useful to disambiguate between multiple factors. | ||
final String? friendlyName; | ||
|
||
/// Type of factor. Only `totp` supported with this version but may change in future versions. | ||
/// Type of factor. Supports both `totp` and `phone`. | ||
final FactorType factorType; | ||
|
||
/// Factor's status. | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.