diff --git a/facebook_auth/CHANGELOG.md b/facebook_auth/CHANGELOG.md index c8c2e04f..8539895f 100644 --- a/facebook_auth/CHANGELOG.md +++ b/facebook_auth/CHANGELOG.md @@ -1,3 +1,6 @@ +### 7.0.0-dev.6 +- iOS: Added `nonce` parameter in `login` function. + ### 7.0.0-dev.3 - **BREAKING CHANGE** Removed the `grantedPermissions` getter. diff --git a/facebook_auth/example/ios/Podfile.lock b/facebook_auth/example/ios/Podfile.lock index 8090bd02..767234d4 100644 --- a/facebook_auth/example/ios/Podfile.lock +++ b/facebook_auth/example/ios/Podfile.lock @@ -1,14 +1,14 @@ PODS: - - FBAEMKit (17.0.0): - - FBSDKCoreKit_Basics (= 17.0.0) - - FBSDKCoreKit (17.0.0): - - FBAEMKit (= 17.0.0) - - FBSDKCoreKit_Basics (= 17.0.0) - - FBSDKCoreKit_Basics (17.0.0) - - FBSDKLoginKit (17.0.0): - - FBSDKCoreKit (= 17.0.0) + - FBAEMKit (17.0.1): + - FBSDKCoreKit_Basics (= 17.0.1) + - FBSDKCoreKit (17.0.1): + - FBAEMKit (= 17.0.1) + - FBSDKCoreKit_Basics (= 17.0.1) + - FBSDKCoreKit_Basics (17.0.1) + - FBSDKLoginKit (17.0.1): + - FBSDKCoreKit (= 17.0.1) - Flutter (1.0.0) - - flutter_facebook_auth (7.0.0-dev.1): + - flutter_facebook_auth (7.0.0-dev.6): - FBSDKLoginKit (~> 17.0.0) - Flutter - flutter_secure_storage (6.0.0): @@ -51,12 +51,12 @@ EXTERNAL SOURCES: :path: ".symlinks/plugins/url_launcher_ios/ios" SPEC CHECKSUMS: - FBAEMKit: 31a20c2d8744d8c57d3a5b7ae4e27b4fdd819193 - FBSDKCoreKit: dac911b656816f8d0b06e5fa4bac60e89505bb3b - FBSDKCoreKit_Basics: 92b7b7458d57091370b0b6cc197578874c3b4b16 - FBSDKLoginKit: 5d5271ebfd1e39c6b071de8db5c4bd6255be3561 + FBAEMKit: 97eaf41451b49691447df831f7f425229ae64b66 + FBSDKCoreKit: e34084567d11cfdd4787ace2b1a0255bedf34ade + FBSDKCoreKit_Basics: 3d78e5fe00504e5c1aed1c48de0654c3a1565d15 + FBSDKLoginKit: 9a581053879a1e6fc3fab8ead341c78c6a318255 Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7 - flutter_facebook_auth: 04b96c6d76be2080de9b4c266302e562f97b68a6 + flutter_facebook_auth: 3fdaeec95ae1042ba587f8f499b998ac3fbc3fb3 flutter_secure_storage: 23fc622d89d073675f2eaa109381aefbcf5a49be path_provider_foundation: 3784922295ac71e43754bd15e0653ccfd36a147c permission_handler_apple: 9878588469a2b0d0fc1e048d9f43605f92e6cec2 diff --git a/facebook_auth/example/lib/login_page.dart b/facebook_auth/example/lib/login_page.dart index f5412bc1..d7fe91a5 100644 --- a/facebook_auth/example/lib/login_page.dart +++ b/facebook_auth/example/lib/login_page.dart @@ -1,9 +1,20 @@ import 'dart:convert'; import 'dart:developer'; +import 'dart:math' as math; import 'package:flutter/material.dart'; import 'package:flutter_facebook_auth/flutter_facebook_auth.dart'; +/// Generates a cryptographically secure random nonce of the specified length. +/// Defaults to 32 characters, which is recommended for most use cases. +String generateNonce([int length = 32]) { + final charset = + '0123456789ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvwxyz-._'; + final random = math.Random.secure(); + return List.generate(length, (_) => charset[random.nextInt(charset.length)]) + .join(); +} + class LoginPage extends StatefulWidget { const LoginPage({super.key}); @@ -13,6 +24,7 @@ class LoginPage extends StatefulWidget { class _LoginPageState extends State { final _auth = FacebookAuth.instance; + String? _nonce; late LoginPageState _state; @@ -40,9 +52,10 @@ class _LoginPageState extends State { Future _getUserProfile(AccessToken accessToken) async { if (accessToken is LimitedToken) { - log('nonce: ${accessToken.nonce}'); + log('token nonce: ${accessToken.nonce}'); + log('_nonce: $_nonce'); } else { - log('accessToken is ClassicToken'); + log('accessToken is ClassicToken'); } final data = await _auth.getUserData(); @@ -73,11 +86,14 @@ class _LoginPageState extends State { } Future _login() async { + _nonce = generateNonce(); + setState(() { _state = LoginLoading(); }); final result = await _auth.login( loginTracking: LoginTracking.limited, + nonce: _nonce, ); switch (result.status) { diff --git a/facebook_auth/ios/Classes/FacebookAuth.swift b/facebook_auth/ios/Classes/FacebookAuth.swift index 0f5fa623..ad8f7e2a 100644 --- a/facebook_auth/ios/Classes/FacebookAuth.swift +++ b/facebook_auth/ios/Classes/FacebookAuth.swift @@ -39,10 +39,13 @@ class FacebookAuth: NSObject { case "login": let permissions = args?["permissions"] as! [String] let tracking = args?["tracking"] as! String + let customNonce = args?["nonce"] as? String + login( permissions: permissions, flutterResult: result, - tracking: tracking == "limited" ? .limited : .enabled + tracking: tracking == "limited" ? .limited : .enabled, + nonce: customNonce ) case "getAccessToken": @@ -92,7 +95,8 @@ class FacebookAuth: NSObject { private func login( permissions: [String], flutterResult: @escaping FlutterResult, - tracking: LoginTracking + tracking: LoginTracking, + nonce: String? ) { let isOK = setPendingResult(methodName: "login", flutterResult: flutterResult) if !isOK { @@ -104,7 +108,7 @@ class FacebookAuth: NSObject { guard let configuration = LoginConfiguration( permissions: permissions, tracking: isLimitedLogin ? .limited : tracking, - nonce: UUID().uuidString + nonce: nonce ?? UUID().uuidString ) else { return diff --git a/facebook_auth/ios/flutter_facebook_auth.podspec b/facebook_auth/ios/flutter_facebook_auth.podspec index fa7d3af1..3ea8b01e 100644 --- a/facebook_auth/ios/flutter_facebook_auth.podspec +++ b/facebook_auth/ios/flutter_facebook_auth.podspec @@ -4,7 +4,7 @@ # Pod::Spec.new do |s| s.name = 'flutter_facebook_auth' - s.version = '7.0.0-dev.5' + s.version = '7.0.0-dev.6' s.summary = 'Plugin to Facebook authentication for iOS in your Flutter app' s.description = <<-DESC Plugin to Facebook authentication for iOS in your Flutter app diff --git a/facebook_auth/lib/flutter_facebook_auth.dart b/facebook_auth/lib/flutter_facebook_auth.dart index 636e5b80..0c5d1859 100644 --- a/facebook_auth/lib/flutter_facebook_auth.dart +++ b/facebook_auth/lib/flutter_facebook_auth.dart @@ -80,15 +80,19 @@ class FacebookAuth { /// /// [loginBehavior] (only Android) use this param to set the UI for the authentication, /// like webview, native app, or a dialog. + /// + /// [nonce] a custom nonce Future login({ List permissions = const ['email', 'public_profile'], LoginBehavior loginBehavior = LoginBehavior.nativeWithFallback, LoginTracking loginTracking = LoginTracking.limited, + String? nonce, }) => _authPlatform.login( permissions: permissions, loginBehavior: loginBehavior, loginTracking: loginTracking, + nonce: nonce, ); /// call this method (ONLY FOR WEB) to initialize the facebook javascript sdk diff --git a/facebook_auth/pubspec.yaml b/facebook_auth/pubspec.yaml index eb9e5152..bba9217d 100644 --- a/facebook_auth/pubspec.yaml +++ b/facebook_auth/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_facebook_auth description: The easiest way to add facebook login to your flutter app. Feature includes getting user information, profile picture and more. This plugin also supports Web and macOS. -version: 7.0.0-dev.5 +version: 7.0.0-dev.6 homepage: https://github.com/darwin-morocho/flutter-facebook-auth environment: @@ -11,17 +11,18 @@ dependencies: flutter: sdk: flutter - flutter_facebook_auth_platform_interface: ^6.0.0-dev.3 + flutter_facebook_auth_platform_interface: ^6.0.0-dev.4 # flutter_facebook_auth_platform_interface: # path: ../facebook_auth_platform_interface - flutter_facebook_auth_web: ^6.0.0-dev.3 + flutter_facebook_auth_web: ^6.0.0-dev.4 # flutter_facebook_auth_web: # path: ../facebook_auth_web - facebook_auth_desktop: ^2.0.0-dev.3 + facebook_auth_desktop: ^2.0.0-dev.4 # facebook_auth_desktop: # path: ../facebook_auth_desktop + dev_dependencies: flutter_test: