Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui_oauth_apple): set default scope to 'email' and add a way to provide custom scopes #9784

Merged
merged 1 commit into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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