Skip to content
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
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,4 @@ Mohd Faheem Ansari <codefaheem@gmail.com>
Om Phatak <everythingoutdated@gmail.com>
Horváth István <horvatska01@gmail.com>
Liu Zhisong <liuzs0666@gmail.com>
Ievgenii Kovtun <jeka.ns@gmail.com>
40 changes: 40 additions & 0 deletions packages/firebase_auth/firebase_auth/test/firebase_auth_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ void main() {
const String kMockEmail = 'test@example.com';
const String kMockPassword = 'passw0rd';
const String kMockIdToken = '12345';
const String kMockRawNonce = 'abcde12345';
const String kMockAccessToken = '67890';
const String kMockGithubToken = 'github';
const String kMockCustomToken = '12345';
Expand Down Expand Up @@ -587,6 +588,45 @@ void main() {
expect(captured.providerId, equals('apple.com'));
expect(captured.idToken, equals(kMockIdToken));
expect(captured.accessToken, equals(kMockAccessToken));
expect(captured.rawNonce, equals(null));
});

test('OAuthProvider signInWithCredential for Apple with rawNonce',
() async {
OAuthProvider oAuthProvider = OAuthProvider('apple.com');
final AuthCredential credential = oAuthProvider.credential(
idToken: kMockIdToken,
rawNonce: kMockRawNonce,
accessToken: kMockAccessToken,
);
await auth.signInWithCredential(credential);
final captured =
verify(mockAuthPlatform.signInWithCredential(captureAny))
.captured
.single;
expect(captured.providerId, equals('apple.com'));
expect(captured.idToken, equals(kMockIdToken));
expect(captured.rawNonce, equals(kMockRawNonce));
expect(captured.accessToken, equals(kMockAccessToken));
});

test(
'OAuthProvider signInWithCredential for Apple with rawNonce (empty accessToken)',
() async {
OAuthProvider oAuthProvider = OAuthProvider('apple.com');
final AuthCredential credential = oAuthProvider.credential(
idToken: kMockIdToken,
rawNonce: kMockRawNonce,
);
await auth.signInWithCredential(credential);
final captured =
verify(mockAuthPlatform.signInWithCredential(captureAny))
.captured
.single;
expect(captured.providerId, equals('apple.com'));
expect(captured.idToken, equals(kMockIdToken));
expect(captured.rawNonce, equals(kMockRawNonce));
expect(captured.accessToken, equals(null));
});

test('PhoneAuthProvider signInWithCredential', () async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -662,9 +662,18 @@ firebase::auth::Credential getCredentialFromArguments(
if (signInMethod == kSignInMethodOAuth) {
std::string providerId =
std::get<std::string>(arguments[kArgumentProviderId]);
return firebase::auth::OAuthProvider::GetCredential(
providerId.c_str(), idToken.value().c_str(),
accessToken.value().c_str());
std::optional<std::string> rawNonce = getStringOpt(kArgumentRawNonce);
// If rawNonce provided use corresponding credential builder
// e.g. AppleID auth through the webView
if (rawNonce) {
return firebase::auth::OAuthProvider::GetCredential(
providerId.c_str(), idToken.value().c_str(), rawNonce.value().c_str(),
accessToken ? accessToken.value().c_str() : nullptr);
} else {
return firebase::auth::OAuthProvider::GetCredential(
providerId.c_str(), idToken.value().c_str(),
accessToken.value().c_str());
}
}

// If no known auth method matched
Expand Down