Skip to content

Commit

Permalink
added custom nonce parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
darwinmorocho-deuna committed May 7, 2024
1 parent 2d395c8 commit 7d50507
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 24 deletions.
3 changes: 3 additions & 0 deletions facebook_auth/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
28 changes: 14 additions & 14 deletions facebook_auth/example/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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
Expand Down
20 changes: 18 additions & 2 deletions facebook_auth/example/lib/login_page.dart
Original file line number Diff line number Diff line change
@@ -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});

Expand All @@ -13,6 +24,7 @@ class LoginPage extends StatefulWidget {

class _LoginPageState extends State<LoginPage> {
final _auth = FacebookAuth.instance;
String? _nonce;

late LoginPageState _state;

Expand Down Expand Up @@ -40,9 +52,10 @@ class _LoginPageState extends State<LoginPage> {

Future<void> _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();
Expand Down Expand Up @@ -73,11 +86,14 @@ class _LoginPageState extends State<LoginPage> {
}

Future<void> _login() async {
_nonce = generateNonce();

setState(() {
_state = LoginLoading();
});
final result = await _auth.login(
loginTracking: LoginTracking.limited,
nonce: _nonce,
);

switch (result.status) {
Expand Down
10 changes: 7 additions & 3 deletions facebook_auth/ios/Classes/FacebookAuth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion facebook_auth/ios/flutter_facebook_auth.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions facebook_auth/lib/flutter_facebook_auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<LoginResult> login({
List<String> 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
Expand Down
9 changes: 5 additions & 4 deletions facebook_auth/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit 7d50507

Please sign in to comment.