Skip to content

Commit

Permalink
fix(ui_oauth_apple): set default scope to 'email' and add a way to pr…
Browse files Browse the repository at this point in the history
…ovide custom scopes (#9784)
  • Loading branch information
lesnitsky committed Oct 31, 2022
1 parent 44ac2a3 commit 19a54ed
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/firebase_ui_auth/example/macos/Podfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
platform :osx, '10.12'
platform :osx, '10.13'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ void main() async {
},
skip: !provider.supportsPlatform(defaultTargetPlatform),
);

group('AppleProvider', () {
test('has default scopes', () {
final provider = AppleProvider();
expect(provider.firebaseAuthProvider.scopes, ['email']);
});

test('provides a way to pass custom scopes', () {
final provider = AppleProvider(scopes: {'email', 'name'});
expect(provider.firebaseAuthProvider.scopes, ['email', 'name']);
});
});
}

class MockListener<T> extends Mock {
Expand Down Expand Up @@ -144,14 +156,16 @@ class MockApp extends Mock implements FirebaseApp {}

class MockAuth extends Mock implements FirebaseAuth {
@override
Future<UserCredential> signInWithAuthProvider(Object provider) async {
Future<UserCredential> signInWithProvider(Object provider) async {
return super.noSuchMethod(
Invocation.method(#signInWithAuthProvider, [provider]),
returnValue: Future.delayed(const Duration(milliseconds: 50))
.then((_) => MockCredential()),
returnValue: Future.delayed(const Duration(milliseconds: 10)).then(
(_) => MockCredential(),
),
returnValueForMissingStub:
Future.delayed(const Duration(milliseconds: 50))
.then((_) => MockCredential()),
Future.delayed(const Duration(milliseconds: 10)).then(
(_) => MockCredential(),
),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// BSD-style license that can be found in the LICENSE file.

import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';

Expand Down Expand Up @@ -36,8 +37,10 @@ Future<void> main() async {
phone_verification.main();
google_sign_in.main();
twitter_sign_in.main();
apple_sign_in.main();
facebook_sign_in.main();
apple_sign_in.main();
} else if (defaultTargetPlatform == TargetPlatform.macOS) {
apple_sign_in.main();
}

layout.main();
Expand Down
12 changes: 12 additions & 0 deletions packages/firebase_ui_oauth_apple/lib/src/provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,21 @@ class AppleProvider extends OAuthProvider {
@override
final style = const AppleProviderButtonStyle();

/// {@template ui.auth.oauth.apple_provider.scopes}
/// The scopes that will be passed down to the [fba.AppleAuthProvider].
/// {@endtemplate}
final Set<String> scopes;

@override
fba.AppleAuthProvider firebaseAuthProvider = fba.AppleAuthProvider();

AppleProvider({
/// {@macro ui.auth.oauth.apple_provider.scopes}
this.scopes = const <String>{'email'},
}) {
scopes.forEach(firebaseAuthProvider.addScope);
}

@override
void mobileSignIn(AuthAction action) {
authListener.onBeforeSignIn();
Expand Down

0 comments on commit 19a54ed

Please sign in to comment.