Open RaghvindYadav opened 3 weeks ago
same issue in my unity game. Unity: 2021.3.37f1 Firebase SDK: 10.2.0 Facebook SDK: 17.0.0
Error Message: SignInWithCredentialAsync encountered an error: System.AggregateException: One or more errors occurred. (One or more errors occurred. (Bad access token: {"code":190,"message":"Malformed access token"}))
Firebase.FirebaseException: Bad access token: {"code":190,"message":"Invalid OAuth access token - Cannot parse access token"}
@owllyi Have you find any solution?
Hello @RaghvindYadav,
Thank you for reporting this issue. Based on the link you shared, it appears that the problem may not be related to FlutterFire but rather to the Facebook SDK plugin you are using. Did I understand that correctly? If so, you might consider opening an issue in their respective repository to get further assistance.
Hi @TarekkMA
May be you are right but I am getting failed error at this line of code return FirebaseAuth.instance.signInWithCredential(facebookAuthCredential);
And FirbaseAuth comes form firebase_auth package.
I will attempt to reproduce this issue. In the meantime, you might find it helpful to look at a similar issue reported with the Facebook SDK here: facebook-ios-sdk issue #2365. This may provide some insights into the problem you are encountering. Additionally, I suspect that FlutterFire may not be responsible for this error, but I will confirm this as I investigate further.
Hi @RaghvindYadav,
The issue is due to the Facebook SDK/plugin. As mentioned here we need to get the nonce. We'll need a plugin that supports limited login to utilize this updated code snippet:
final provider = OAuthCredential(
providerId: 'facebook.com',
signInMethod: 'oauth',
idToken: accessToken.token,
rawNonce: rawNonce,
);
@TarekkMA I did the above you mentioned, still getting the same error. Also use a new package https://pub.dev/packages/flutter_facebook_auth/versions/7.0.0-dev.3/changelog#700-dev3
@owllyi Have you find any solution?
credential = Firebase.Auth.FacebookAuthProvider.GetCredential(accessToken);
var authToken = FaceBookManager.Instance.GetToken();
var nonce = FaceBookManager.Instance.GetNonce();
credential = Firebase.Auth.OAuthProvider.GetCredential("facebook.com", authToken, nonce, null);
@TarekkMA I did the above you mentioned, still getting the same error. Also use a new package https://pub.dev/packages/flutter_facebook_auth/versions/7.0.0-dev.3/changelog#700-dev3
Thank you @TarekkMA, I used that package but still persisting with same problem. Now accessToken looks quite different than previous response.
I've looked into the new package, can you try using this instead and let me know if it works:
final AccessToken accessToken = result.accessToken!;
final AuthCredential credential;
switch (accessToken.type) {
case AccessTokenType.classic:
final token = accessToken as ClassicToken;
credential = FacebookAuthProvider.credential(token.authenticationToken!,);
break;
case AccessTokenType.limited:
final token = accessToken as LimitedToken;
credential = OAuthCredential(
providerId: 'facebook.com',
signInMethod: 'oauth',
idToken: token.tokenString,
rawNonce: token.nonce,
);
break;
}
// Login with token
await auth.signInWithCredential(credential);
We might need to add a new option in the future for limited login so it can be just FacebookAuthProvider.limitedCredential(....)
@TarekkMA AccessTokenType.limited getting this error for now Firebase Auth error: [firebase_auth/missing-or-invalid-nonce] The nonce in ID Token "C7D21692-B861-4E45-A912-DB9F4502AA2B" does not match the SHA256 hash of the raw nonce "C7D21692-B861-4E45-A912-DB9F4502AA2B" in the request.
If I changed this parameter signInMethod: 'oauth'
to signInMethod: 'facebook.com'
, then app get crashed.
I can reproduce this error, I guess the signInMethod should be oauth for it to work, since signInMethod: 'facebook.com'
will not use nonce, or the idToken.
/cc @Lyokone
@owllyi does your implementation work?
var authToken = FaceBookManager.Instance.GetToken(); var nonce = FaceBookManager.Instance.GetNonce(); credential = Firebase.Auth.OAuthProvider.GetCredential("facebook.com", authToken, nonce, null);
Would be interesting how your facebook-login implementation looks like. I got this error:
The nonce in ID Token "xxx" does not match the SHA256 hash of the raw nonce "xxx" in the request
Do you use the hashed nonce or raw nonce in
FB.Mobile.LoginWithTrackingPreference
method?
@owllyi does your implementation work?
var authToken = FaceBookManager.Instance.GetToken(); var nonce = FaceBookManager.Instance.GetNonce(); credential = Firebase.Auth.OAuthProvider.GetCredential("facebook.com", authToken, nonce, null);
Would be interesting how your facebook-login implementation looks like. I got this error:
The nonce in ID Token "xxx" does not match the SHA256 hash of the raw nonce "xxx" in the request
Do you use the hashed nonce or raw nonce in
FB.Mobile.LoginWithTrackingPreference
method?
Found a solution. This is what I found in firebase documentation:
"You will send the SHA-256 hash of the nonce with your sign-in request, which Facebook will pass unchanged in the response. Firebase validates the response by hashing the original nonce and comparing it to the value passed by Facebook."
Facebook-Login: string rawNonce = Nonce.GetNonce() // custom class that will create a nonce string hashedNonce = HashUtils.Sha256(rawNonce); // custom class that will hash the rawNonce FB.Mobile.LoginWithTrackingPreference(LoginTracking.LIMITED, scopes, hashedNonce, HandleResult);
Firebase Credentials: Credentials credential = Firebase.Auth.OAuthProvider.GetCredential("facebook.com", authToken, rawNonce, null); // authToken - the token you will get from facebook response // rawNonce - nonce you created in the previous step
I'm having this issue too with Flutter on IOS. The same code worked less than two months aga. The problem only occurs for me on IOS, not on Android.
after reading this thread I tried it on iphone 14 running iOS 16.4 in IOS Emulator. It works there. In iOS 17.4 it fails.
Workaround (downgrade facebook sdk version): 1) in pubspec.yaml replace flutter_facebook_auth: ^6.0.3 to flutter_facebook_auth: 6.0.3 2) flutter clean (not necessary, in my case worked without it) 3) Delete folders: /ios/Pods/FBAEMKit /ios/Pods/FBSDKCoreKit /ios/Pods/FBSDKCoreKit_Basics /ios/Pods/FBSDKLoginKit (also can delete all folder /ios/Pods) 4) Delete /ios/Podfile.lock 5) flutter pub get 6) from inside ios folder: pod install
After this my old code works on physical device iPhone 11 iOS 17.4.1
Firebase Auth iOS has documentation on how to login with limited login here: https://firebase.google.com/docs/auth/ios/facebook-login#implement_facebook_limited_login
The difference is, they create a nonce, and send a SHA-256 hash of the nonce to FacebookAuth, whilst passing in the raw nonce to firebase_auth OAuthCredential
which you use to signInWithCredential()
:
OAuthCredential credential = OAuthCredential(
providerId: 'facebook.com',
signInMethod: 'oauth',
idToken: token.tokenString,
rawNonce: rawNonce,
);
The above will work for limited login if you set it up correctly.
Any update on this? I have the same issue.
Workaround (downgrade facebook sdk version): 1) in pubspec.yaml replace flutter_facebook_auth: ^6.0.3 to flutter_facebook_auth: 6.0.3 2) flutter clean (not necessary, in my case worked without it) 3) Delete folders: /ios/Pods/FBAEMKit /ios/Pods/FBSDKCoreKit /ios/Pods/FBSDKCoreKit_Basics /ios/Pods/FBSDKLoginKit (also can delete all folder /ios/Pods) 4) Delete /ios/Podfile.lock 5) flutter pub get 6) from inside ios folder: pod install
After this my old code works on physical device iPhone 11 iOS 17.4.1
I found the workaround provided by @usilitel to work on IOS emulators and physical devices up to IOS 17.4.1. I haven't tried the method presented by @russellwheatley thus far, but if there are any thoughts as to "why?" downgrading works and the current version doesn't, and how if at all it relates to the issue described by @russellwheatley that would be of tremendous assistance. Thank you both though.
Is there an existing issue for this?
Which plugins are affected?
Auth
Which platforms are affected?
iOS
Description
I am integrating my app with Facebook login but facing a problem in iOS version which is greater than 17.0. The login get failed. Getting error : Firebase Auth error: [firebase_auth/invalid-credential] {"code":190,"message":"Invalid OAuth access token - Cannot parse access token"}
Reproducing the issue
The above is worked well for android and iOS device which ios version is less than 17, but we need to upgrade Facebook sign for iOS 17.o and greater. Here is a url of blog. https://developers.facebook.com/blog/post/2024/03/28/changes-made-to-fb-login-sdk/
Firebase Core version
2.30.1
Flutter Version
3.19.5
Relevant Log Output
Flutter dependencies
Additional context and comments
https://developers.facebook.com/blog/post/2024/03/28/changes-made-to-fb-login-sdk/