Closed alexgrant999 closed 2 days ago
Same issue here: {"code":190,"message":"Bad signature"} when trying to log in using FacebookAuth with limited login.
@alexgrant999 Thank you for reporting this issue. For Facebook limited login, you have to use the nonce field when invoking the login method. Please refer to this comment for more information: link.
This seems to have fixed it, thank you. 🙏🏻
String sha256ofString(String input) {
final bytes = utf8.encode(input);
final digest = sha256.convert(bytes);
return digest.toString();
}
String generateNonce([int length = 32]) {
// Define the character set to be used in the nonce
final charset =
'0123456789ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvwxyz-.';
// Create a secure random number generator
final random = Random.secure();
// Generate a string of the specified length using random characters from the charset
return String.fromCharCodes(List.generate(
length, (index) => charset.codeUnitAt(random.nextInt(charset.length))));
}
Future<void> _signInWithFacebook() async {
// Trigger the sign-in flow
final rawNonce = generateNonce();
final nonce = sha256ofString(rawNonce);
final result = await FacebookAuth.instance.login(
loginTracking: LoginTracking.limited,
nonce: nonce,
);
if (result.status == LoginStatus.success) {
print('${await FacebookAuth.instance.getUserData()}');
final token = result.accessToken as LimitedToken;
// Create a credential from the access token
OAuthCredential credential = OAuthCredential(
providerId: 'facebook.com',
signInMethod: 'oauth',
idToken: token.tokenString,
rawNonce: rawNonce,
);
await FirebaseAuth.instance.signInWithCredential(credential);
}
}
Is there an existing issue for this?
Which plugins are affected?
Auth
Which platforms are affected?
iOS
Description
When signing in with Facebook, the functions returns with the error: {"code":190,"message":"Bad signature"}
My AppID and Token are all correct. Plus the clientID and Secret in Firebase.
Reproducing the issue
Click on a button to activate the login with facebook function.
Firebase Core version
^3.1.1
Flutter Version
3.22.2
Relevant Log Output
Flutter dependencies
Expand
Flutter dependencies
snippet```yaml dependencies: flutter: sdk: flutter dio: ^4.0.0 google_fonts: ^6.2.1 image_picker: ^0.8.5+3 numberpicker: ^2.1.2 path_provider: ^2.0.11 permission_handler: ^10.2.0 persistent_bottom_nav_bar: ^5.0.2 provider: ^6.0.3 shared_preferences: ^2.0.15 youtube_player_flutter: ^9.0.1 webview_flutter: ^4.7.0 volume_controller: ^2.0.7 # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.6 supabase_flutter: ^2.5.3 url_launcher: ^6.2.6 dart_rss: ^3.0.3 audioplayers: ^6.0.0 flutter_launcher_icons: ^0.13.1 firebase_core: ^3.1.1 firebase_auth: ^5.1.1 firebase_messaging: ^15.0.2 google_sign_in: ^6.2.1 flutter_facebook_auth: ^7.0.1 ```
Additional context and comments
No response