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

af: Fix email verified type #309

Merged
merged 8 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ extension UserProfileExtension on UserProfile {
final updatedAt = claims[PublicClaims.updatedAt] != null
? DateTime.parse(claims[PublicClaims.updatedAt] as String)
: null;
final isEmailVerified = claims[PublicClaims.emailVerified] != null
? claims[PublicClaims.emailVerified] is bool
? claims[PublicClaims.emailVerified] as bool
: claims[PublicClaims.emailVerified] == 'true'
: null;

return UserProfile(
sub: claims[PublicClaims.sub] as String,
Expand All @@ -41,7 +46,7 @@ extension UserProfileExtension on UserProfile {
pictureUrl: pictureUrl,
websiteUrl: websiteUrl,
email: claims[PublicClaims.email] as String?,
isEmailVerified: claims[PublicClaims.emailVerified] as bool?,
isEmailVerified: isEmailVerified,
gender: claims[PublicClaims.gender] as String?,
birthdate: claims[PublicClaims.birthdate] as String?,
zoneinfo: claims[PublicClaims.zoneinfo] as String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,64 @@ void main() {
expect(result.customClaims, customClaims);
});

test('creates UserProfile from claims with stringified email_verified',
() async {
const Map<String, dynamic> claims = {
...requiredValues,
PublicClaims.name: 'John Alexander Doe',
PublicClaims.givenName: 'John',
PublicClaims.familyName: 'Doe',
PublicClaims.middleName: 'Alexander',
PublicClaims.nickname: 'johnny',
PublicClaims.preferredUsername: 'johnnyD',
PublicClaims.profile: 'https://example.com/profile',
PublicClaims.picture: 'https://example.com/picture.png',
PublicClaims.website: 'https://example.com',
PublicClaims.email: 'john.doe@example.com',
PublicClaims.emailVerified: 'true',
PublicClaims.gender: 'male',
PublicClaims.birthdate: '01-01-2000',
PublicClaims.zoneinfo: 'America/Chicago',
PublicClaims.locale: 'en-US',
PublicClaims.phoneNumber: '111111111',
PublicClaims.phoneNumberVerified: true,
PublicClaims.address: {'street': '1 Foo St', 'zip_code': '11111-1111'},
PublicClaims.updatedAt: '2023-02-28T15:08:56+00:00',
'foo': 'bar'
};

final result = UserProfileExtension.fromClaims(claims);

expect(result.name, claims[PublicClaims.name]);
expect(result.givenName, claims[PublicClaims.givenName]);
expect(result.familyName, claims[PublicClaims.familyName]);
expect(result.middleName, claims[PublicClaims.middleName]);
expect(result.nickname, claims[PublicClaims.nickname]);
expect(result.preferredUsername, claims[PublicClaims.preferredUsername]);
expect(
result.profileUrl, Uri.parse(claims[PublicClaims.profile] as String));
expect(
result.pictureUrl, Uri.parse(claims[PublicClaims.picture] as String));
expect(
result.websiteUrl, Uri.parse(claims[PublicClaims.website] as String));
expect(result.email, claims[PublicClaims.email]);
expect(
result.isEmailVerified,
claims[PublicClaims.emailVerified] == 'true',
);
expect(result.gender, claims[PublicClaims.gender]);
expect(result.birthdate, claims[PublicClaims.birthdate]);
expect(result.zoneinfo, claims[PublicClaims.zoneinfo]);
expect(result.locale, claims[PublicClaims.locale]);
expect(result.phoneNumber, claims[PublicClaims.phoneNumber]);
expect(result.isPhoneNumberVerified,
claims[PublicClaims.phoneNumberVerified]);
expect(result.address, claims[PublicClaims.address]);
expect(result.updatedAt,
DateTime.parse(claims[PublicClaims.updatedAt] as String));
expect(result.customClaims?['foo'], claims['foo']);
});

test('throws exception with invalid profile URL', () async {
const Map<String, dynamic> claims = {
...requiredValues,
Expand Down
Loading