Skip to content

Commit 12e87de

Browse files
authoredJul 31, 2024··
fix(firebase_auth): added supporting rawNonce for OAuth credential on Windows platform (#13086)
* fix(firebase_auth): added supporting rawNonce for OAuth credential on Windows platform * fix(firebase_auth): added supporting rawNonce for OAuth credential on Windows platform fix formating
1 parent 2b98417 commit 12e87de

File tree

3 files changed

+53
-3
lines changed

3 files changed

+53
-3
lines changed
 

‎AUTHORS

+1
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,4 @@ Mohd Faheem Ansari <codefaheem@gmail.com>
6464
Om Phatak <everythingoutdated@gmail.com>
6565
Horváth István <horvatska01@gmail.com>
6666
Liu Zhisong <liuzs0666@gmail.com>
67+
Ievgenii Kovtun <jeka.ns@gmail.com>

‎packages/firebase_auth/firebase_auth/test/firebase_auth_test.dart

+40
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ void main() {
2626
const String kMockEmail = 'test@example.com';
2727
const String kMockPassword = 'passw0rd';
2828
const String kMockIdToken = '12345';
29+
const String kMockRawNonce = 'abcde12345';
2930
const String kMockAccessToken = '67890';
3031
const String kMockGithubToken = 'github';
3132
const String kMockCustomToken = '12345';
@@ -587,6 +588,45 @@ void main() {
587588
expect(captured.providerId, equals('apple.com'));
588589
expect(captured.idToken, equals(kMockIdToken));
589590
expect(captured.accessToken, equals(kMockAccessToken));
591+
expect(captured.rawNonce, equals(null));
592+
});
593+
594+
test('OAuthProvider signInWithCredential for Apple with rawNonce',
595+
() async {
596+
OAuthProvider oAuthProvider = OAuthProvider('apple.com');
597+
final AuthCredential credential = oAuthProvider.credential(
598+
idToken: kMockIdToken,
599+
rawNonce: kMockRawNonce,
600+
accessToken: kMockAccessToken,
601+
);
602+
await auth.signInWithCredential(credential);
603+
final captured =
604+
verify(mockAuthPlatform.signInWithCredential(captureAny))
605+
.captured
606+
.single;
607+
expect(captured.providerId, equals('apple.com'));
608+
expect(captured.idToken, equals(kMockIdToken));
609+
expect(captured.rawNonce, equals(kMockRawNonce));
610+
expect(captured.accessToken, equals(kMockAccessToken));
611+
});
612+
613+
test(
614+
'OAuthProvider signInWithCredential for Apple with rawNonce (empty accessToken)',
615+
() async {
616+
OAuthProvider oAuthProvider = OAuthProvider('apple.com');
617+
final AuthCredential credential = oAuthProvider.credential(
618+
idToken: kMockIdToken,
619+
rawNonce: kMockRawNonce,
620+
);
621+
await auth.signInWithCredential(credential);
622+
final captured =
623+
verify(mockAuthPlatform.signInWithCredential(captureAny))
624+
.captured
625+
.single;
626+
expect(captured.providerId, equals('apple.com'));
627+
expect(captured.idToken, equals(kMockIdToken));
628+
expect(captured.rawNonce, equals(kMockRawNonce));
629+
expect(captured.accessToken, equals(null));
590630
});
591631

592632
test('PhoneAuthProvider signInWithCredential', () async {

‎packages/firebase_auth/firebase_auth/windows/firebase_auth_plugin.cpp

+12-3
Original file line numberDiff line numberDiff line change
@@ -662,9 +662,18 @@ firebase::auth::Credential getCredentialFromArguments(
662662
if (signInMethod == kSignInMethodOAuth) {
663663
std::string providerId =
664664
std::get<std::string>(arguments[kArgumentProviderId]);
665-
return firebase::auth::OAuthProvider::GetCredential(
666-
providerId.c_str(), idToken.value().c_str(),
667-
accessToken.value().c_str());
665+
std::optional<std::string> rawNonce = getStringOpt(kArgumentRawNonce);
666+
// If rawNonce provided use corresponding credential builder
667+
// e.g. AppleID auth through the webView
668+
if (rawNonce) {
669+
return firebase::auth::OAuthProvider::GetCredential(
670+
providerId.c_str(), idToken.value().c_str(), rawNonce.value().c_str(),
671+
accessToken ? accessToken.value().c_str() : nullptr);
672+
} else {
673+
return firebase::auth::OAuthProvider::GetCredential(
674+
providerId.c_str(), idToken.value().c_str(),
675+
accessToken.value().c_str());
676+
}
668677
}
669678

670679
// If no known auth method matched

0 commit comments

Comments
 (0)
Please sign in to comment.