diff --git a/.github/workflows/googleauth.yml b/.github/workflows/googleauth.yml index 5b326bb318e..314987683cf 100644 --- a/.github/workflows/googleauth.yml +++ b/.github/workflows/googleauth.yml @@ -40,6 +40,19 @@ jobs: - name: Build run: | ./test.sh FirebaseGoogleAuthUI + spm: + name: spm + runs-on: macOS-latest + + steps: + - name: Checkout + uses: actions/checkout@master + - name: List + run: | + xcodebuild -list + - name: Build + run: | + xcodebuild -scheme FirebaseGoogleAuthUI -sdk iphonesimulator pod: name: pod lib lint runs-on: macOS-latest diff --git a/FirebaseGoogleAuthUI.podspec b/FirebaseGoogleAuthUI.podspec index 74dcc040819..2dfe407b684 100644 --- a/FirebaseGoogleAuthUI.podspec +++ b/FirebaseGoogleAuthUI.podspec @@ -21,7 +21,7 @@ Pod::Spec.new do |s| s.dependency 'FirebaseAuth' s.dependency 'FirebaseCore' s.dependency 'FirebaseAuthUI' - s.dependency 'GoogleSignIn', '~> 5.0' + s.dependency 'GoogleSignIn', '~> 6.0' s.resource_bundles = { 'FirebaseGoogleAuthUI' => ['FirebaseGoogleAuthUI/Sources/{Resources,Strings}/*.{png,lproj}'] } diff --git a/FirebaseGoogleAuthUI/FirebaseGoogleAuthUI.xcodeproj/project.pbxproj b/FirebaseGoogleAuthUI/FirebaseGoogleAuthUI.xcodeproj/project.pbxproj index 44b91845589..ed279788d5a 100644 --- a/FirebaseGoogleAuthUI/FirebaseGoogleAuthUI.xcodeproj/project.pbxproj +++ b/FirebaseGoogleAuthUI/FirebaseGoogleAuthUI.xcodeproj/project.pbxproj @@ -775,12 +775,12 @@ "\"${PODS_CONFIGURATION_BUILD_DIR}/GTMSessionFetcher\"", "\"${PODS_CONFIGURATION_BUILD_DIR}/GoogleDataTransport\"", "\"${PODS_CONFIGURATION_BUILD_DIR}/GoogleUtilities\"", - "\"${PODS_ROOT}/GoogleSignIn/Frameworks\"", "\"${PODS_CONFIGURATION_BUILD_DIR}/AppAuth\"", "\"${PODS_CONFIGURATION_BUILD_DIR}/PromisesObjC\"", "\"${PODS_CONFIGURATION_BUILD_DIR}/GTMAppAuth\"", "\"${PODS_CONFIGURATION_BUILD_DIR}/nanopb\"", "\"$(PODS_CONFIGURATION_BUILD_DIR)/FirebaseAuthUI\"", + "\"$(PODS_CONFIGURATION_BUILD_DIR)/GoogleSignIn\"", ); OTHER_LDFLAGS = ( "$(inherited)", @@ -830,12 +830,12 @@ "\"${PODS_CONFIGURATION_BUILD_DIR}/GTMSessionFetcher\"", "\"${PODS_CONFIGURATION_BUILD_DIR}/GoogleDataTransport\"", "\"${PODS_CONFIGURATION_BUILD_DIR}/GoogleUtilities\"", - "\"${PODS_ROOT}/GoogleSignIn/Frameworks\"", "\"${PODS_CONFIGURATION_BUILD_DIR}/AppAuth\"", "\"${PODS_CONFIGURATION_BUILD_DIR}/PromisesObjC\"", "\"${PODS_CONFIGURATION_BUILD_DIR}/GTMAppAuth\"", "\"${PODS_CONFIGURATION_BUILD_DIR}/nanopb\"", "\"$(PODS_CONFIGURATION_BUILD_DIR)/FirebaseAuthUI\"", + "\"$(PODS_CONFIGURATION_BUILD_DIR)/GoogleSignIn\"", ); OTHER_LDFLAGS = ( "$(inherited)", diff --git a/FirebaseGoogleAuthUI/FirebaseGoogleAuthUITests/FirebaseGoogleAuthUITests.m b/FirebaseGoogleAuthUI/FirebaseGoogleAuthUITests/FirebaseGoogleAuthUITests.m index f839549f02f..58e7947039e 100644 --- a/FirebaseGoogleAuthUI/FirebaseGoogleAuthUITests/FirebaseGoogleAuthUITests.m +++ b/FirebaseGoogleAuthUI/FirebaseGoogleAuthUITests/FirebaseGoogleAuthUITests.m @@ -23,7 +23,12 @@ #import "FUIGoogleAuth.h" @interface FUIGoogleAuth (Testing) -- (GIDSignIn *)configuredGoogleSignIn; +- (NSString *)clientID; +- (GIDSignIn *)googleSignIn; +- (void)handleSignInWithUser:(GIDGoogleUser *)user + error:(NSError *)error + presentingViewController:(UIViewController *)presentingViewController + callback:(FUIAuthProviderSignInCompletionBlock)callback; @end @interface FirebaseGoogleAuthUITests : XCTestCase @@ -48,6 +53,7 @@ - (void)setUp { FIRAuth *auth = [FIRAuth auth]; self.authUI = [FUIAuth authUIWithAuth:auth]; self.mockProvider = OCMPartialMock([[FUIGoogleAuth alloc] initWithAuthUI:self.authUI]); + OCMStub([_mockProvider clientID]).andReturn(@"clientID"); } - (void)tearDown { @@ -82,7 +88,7 @@ - (void)testUseEmulatorCreatesOAuthProvider { OCMVerify([self.mockOAuthProvider providerWithProviderID:@"google.com"]); } -- (void)testSuccessfullLogin { +- (void)testSuccessfulLogin { NSString *testIdToken = @"idToken"; NSString *testAccessToken = @"accessToken"; @@ -99,11 +105,16 @@ - (void)testSuccessfullLogin { OCMExpect([mockGoogleUser authentication]).andReturn(mockAuthentication); OCMExpect([mockAuthentication idToken]).andReturn(testIdToken); - OCMExpect([_mockProvider configuredGoogleSignIn]).andReturn(mockSignIn); + OCMExpect([_mockProvider googleSignIn]).andReturn(mockSignIn); - //forward call to signIn delegate - OCMExpect([mockSignIn signIn]).andDo(^(NSInvocation *invocation) { - [mockSignInDelegate signIn:mockSignIn didSignInForUser:mockGoogleUser withError:nil]; + // forward call to signIn delegate + OCMExpect([mockSignIn signInWithConfiguration:[OCMArg any] + presentingViewController:[OCMArg any] + hint:[OCMArg any] + callback:[OCMArg any]]).andDo(^(NSInvocation *invocation) { + void (^callback)(GIDGoogleUser *, NSError *) = nil; + [invocation getArgument:&callback atIndex:5]; + callback(mockGoogleUser, nil); }); XCTestExpectation *expectation = [self expectationWithDescription:@"logged in"]; @@ -147,13 +158,15 @@ - (void)testLegacyInitSuccessfulLogin { NSString *testIdToken = @"idToken"; NSString *testAccessToken = @"accessToken"; - _mockProvider = OCMPartialMock([[FUIGoogleAuth alloc] init]); + _mockProvider = OCMPartialMock([[FUIGoogleAuth alloc] init]); id mockSignInDelegate = _mockProvider; id mockSignIn = OCMClassMock([GIDSignIn class]); id mockAuthentication = OCMClassMock([GIDAuthentication class]); id mockGoogleUser = OCMClassMock([GIDGoogleUser class]); + OCMStub([_mockProvider clientID]).andReturn(@"clientID"); + // mock accessToken OCMExpect([mockGoogleUser authentication]).andReturn(mockAuthentication); OCMExpect([mockAuthentication accessToken]).andReturn(testAccessToken); @@ -162,11 +175,16 @@ - (void)testLegacyInitSuccessfulLogin { OCMExpect([mockGoogleUser authentication]).andReturn(mockAuthentication); OCMExpect([mockAuthentication idToken]).andReturn(testIdToken); - OCMExpect([_mockProvider configuredGoogleSignIn]).andReturn(mockSignIn); + OCMExpect([_mockProvider googleSignIn]).andReturn(mockSignIn); - //forward call to signIn delegate - OCMExpect([mockSignIn signIn]).andDo(^(NSInvocation *invocation) { - [mockSignInDelegate signIn:mockSignIn didSignInForUser:mockGoogleUser withError:nil]; + // forward call to signIn delegate + OCMExpect([mockSignIn signInWithConfiguration:[OCMArg any] + presentingViewController:[OCMArg any] + hint:[OCMArg any] + callback:[OCMArg any]]).andDo(^(NSInvocation *invocation) { + void (^callback)(GIDGoogleUser *, NSError *) = nil; + [invocation getArgument:&callback atIndex:5]; + callback(mockGoogleUser, nil); }); XCTestExpectation *expectation = [self expectationWithDescription:@"logged in"]; @@ -222,11 +240,17 @@ - (void)testErrorLogin { OCMStub([mockGoogleUser authentication]).andReturn(mockAuthentication); OCMStub([mockAuthentication idToken]).andReturn(testIdToken); - OCMExpect([_mockProvider configuredGoogleSignIn]).andReturn(mockSignIn); + OCMExpect([_mockProvider googleSignIn]).andReturn(mockSignIn); NSError *signInError = [NSError errorWithDomain:@"sign in domain" code:kGIDSignInErrorCodeUnknown userInfo:@{}]; - OCMExpect([mockSignIn signIn]).andDo(^(NSInvocation *invocation) { - [mockSignInDelegate signIn:mockSignIn didSignInForUser:mockGoogleUser withError:signInError]; + // forward call to signIn delegate + OCMExpect([mockSignIn signInWithConfiguration:[OCMArg any] + presentingViewController:[OCMArg any] + hint:[OCMArg any] + callback:[OCMArg any]]).andDo(^(NSInvocation *invocation) { + void (^callback)(GIDGoogleUser *, NSError *) = nil; + [invocation getArgument:&callback atIndex:5]; + callback(mockGoogleUser, signInError); }); @@ -275,11 +299,17 @@ - (void)testCancelLogin { OCMStub([mockGoogleUser authentication]).andReturn(mockAuthentication); OCMStub([mockAuthentication idToken]).andReturn(testIdToken); - OCMExpect([_mockProvider configuredGoogleSignIn]).andReturn(mockSignIn); + OCMExpect([_mockProvider googleSignIn]).andReturn(mockSignIn); NSError *signInError = [NSError errorWithDomain:@"sign in domain" code:kGIDSignInErrorCodeCanceled userInfo:@{}]; - OCMExpect([mockSignIn signIn]).andDo(^(NSInvocation *invocation) { - [mockSignInDelegate signIn:mockSignIn didSignInForUser:mockGoogleUser withError:signInError]; + // forward call to signIn delegate + OCMExpect([mockSignIn signInWithConfiguration:[OCMArg any] + presentingViewController:[OCMArg any] + hint:[OCMArg any] + callback:[OCMArg any]]).andDo(^(NSInvocation *invocation) { + void (^callback)(GIDGoogleUser *, NSError *) = nil; + [invocation getArgument:&callback atIndex:5]; + callback(mockGoogleUser, signInError); }); XCTestExpectation *expectation = [self expectationWithDescription:@"logged in"]; @@ -313,7 +343,7 @@ - (void)testCancelLogin { - (void)testSignOut { id mockSignIn = OCMClassMock([GIDSignIn class]); - OCMExpect([_mockProvider configuredGoogleSignIn]).andReturn(mockSignIn); + OCMExpect([_mockProvider googleSignIn]).andReturn(mockSignIn); OCMExpect([mockSignIn signOut]); [_mockProvider signOut]; @@ -324,7 +354,7 @@ - (void)testSignOut { - (void)testUseEmulatorUsesOAuthProvider { [self.authUI useEmulatorWithHost:@"host" port:12345]; - self.mockProvider = OCMPartialMock([[FUIGoogleAuth alloc] initWithAuthUI:self.authUI]); + self.mockProvider = OCMPartialMock([[FUIGoogleAuth alloc] initWithAuthUI:self.authUI]); [self.mockProvider signInWithDefaultValue:nil presentingViewController:nil @@ -334,7 +364,7 @@ - (void)testUseEmulatorUsesOAuthProvider { NSDictionary *_Nullable userInfo) {}]; OCMVerify([self.mockOAuthProvider getCredentialWithUIDelegate:nil completion:OCMOCK_ANY]); - OCMVerify(never(), [self.mockProvider configuredGoogleSignIn]); + OCMVerify(never(), [self.mockProvider googleSignIn]); } diff --git a/FirebaseGoogleAuthUI/Podfile b/FirebaseGoogleAuthUI/Podfile index f5f05ee0035..392dbeb9a63 100644 --- a/FirebaseGoogleAuthUI/Podfile +++ b/FirebaseGoogleAuthUI/Podfile @@ -6,7 +6,7 @@ platform :ios, '10.0' target 'FirebaseGoogleAuthUI' do use_frameworks! - pod 'GoogleSignIn', '~> 5.0' + pod 'GoogleSignIn', '~> 6.0' pod 'FirebaseAuthUI', :path => '../' target 'FirebaseGoogleAuthUITests' do diff --git a/FirebaseGoogleAuthUI/Podfile.lock b/FirebaseGoogleAuthUI/Podfile.lock index 2aeaf38b595..119e286c6a9 100644 --- a/FirebaseGoogleAuthUI/Podfile.lock +++ b/FirebaseGoogleAuthUI/Podfile.lock @@ -25,8 +25,8 @@ PODS: - GoogleUtilities/Environment (~> 7.2) - nanopb (~> 2.30908.0) - PromisesObjC (< 3.0, >= 1.2) - - GoogleSignIn (5.0.2): - - AppAuth (~> 1.2) + - GoogleSignIn (6.0.0): + - AppAuth (~> 1.4) - GTMAppAuth (~> 1.0) - GTMSessionFetcher/Core (~> 1.1) - GoogleUtilities/AppDelegateSwizzler (7.5.0): @@ -58,7 +58,7 @@ PODS: DEPENDENCIES: - FirebaseAuthUI (from `../`) - - GoogleSignIn (~> 5.0) + - GoogleSignIn (~> 6.0) - OCMock SPEC REPOS: @@ -87,7 +87,7 @@ SPEC CHECKSUMS: FirebaseCore: a6dba751680d7033b9d3831e1cfc95ead0605118 FirebaseCoreDiagnostics: 7e873baabcfaa9512f538554ae4fa0817aaafbdb GoogleDataTransport: 85fd18ff3019bb85d3f2c551d04c481dedf71fc9 - GoogleSignIn: 7137d297ddc022a7e0aa4619c86d72c909fa7213 + GoogleSignIn: b7779a809e1dfb32ebb43131b10d8bfcd53c1383 GoogleUtilities: eea970f4a389963963bffe8d8fabe43540678b9c GTMAppAuth: ad5c2b70b9a8689e1a04033c9369c4915bfcbe89 GTMSessionFetcher: 36689134877faeb055b27dfa4ccc9ceaa42e029e @@ -95,6 +95,6 @@ SPEC CHECKSUMS: OCMock: 29f6e52085b4e7d9b075cbf03ed7c3112f82f934 PromisesObjC: 68159ce6952d93e17b2dfe273b8c40907db5ba58 -PODFILE CHECKSUM: 5b245dea8385cbe6f02f214577a97083894700bf +PODFILE CHECKSUM: 0ab8f1a707baefc68f0b4f5320060c1502798f29 COCOAPODS: 1.10.1 diff --git a/FirebaseGoogleAuthUI/Sources/FUIGoogleAuth.m b/FirebaseGoogleAuthUI/Sources/FUIGoogleAuth.m index 7e3cb541499..22f6a355d93 100644 --- a/FirebaseGoogleAuthUI/Sources/FUIGoogleAuth.m +++ b/FirebaseGoogleAuthUI/Sources/FUIGoogleAuth.m @@ -29,14 +29,18 @@ /** @var kBundleName @brief The name of the bundle to search for resources. */ +#if SWIFT_PACKAGE +static NSString *const kBundleName = @"FirebaseUI_FirebaseGoogleAuthUI"; +#else static NSString *const kBundleName = @"FirebaseGoogleAuthUI"; +#endif // SWIFT_PACKAGE /** @var kSignInWithGoogle @brief The string key for localized button text. */ static NSString *const kSignInWithGoogle = @"SignInWithGoogle"; -@interface FUIGoogleAuth () +@interface FUIGoogleAuth () /** @property authUI @brief FUIAuth instance of the application. @@ -50,16 +54,6 @@ @interface FUIGoogleAuth () @end @implementation FUIGoogleAuth { - /** @var _presentingViewController - @brief The presenting view controller for interactive sign-in. - */ - UIViewController *_presentingViewController; - - /** @var _pendingSignInCallback - @brief The callback which should be invoked when the sign in flow completes (or is cancelled.) - */ - FUIAuthProviderSignInCompletionBlock _pendingSignInCallback; - /** @var _email @brief The email address associated with this account. */ @@ -71,6 +65,10 @@ + (NSBundle *)bundle { inFrameworkBundle:[NSBundle bundleForClass:[self class]]]; } ++ (NSArray *)defaultScopes { + return @[kGoogleUserInfoEmailScope, kGoogleUserInfoProfileScope]; +} + - (instancetype)initWithAuthUI:(FUIAuth *)authUI { return [self initWithAuthUI:authUI scopes:@[kGoogleUserInfoEmailScope, kGoogleUserInfoProfileScope]]; } @@ -90,7 +88,7 @@ - (instancetype)initWithAuthUI:(FUIAuth *)authUI scopes:(NSArray *)s #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-implementations" - (instancetype)init { - return [self initWithScopes:@[kGoogleUserInfoEmailScope, kGoogleUserInfoProfileScope]]; + return [self initWithScopes:[[self class] defaultScopes]]; } - (instancetype)initWithScopes:(NSArray *)scopes { @@ -102,6 +100,13 @@ - (instancetype)initWithScopes:(NSArray *)scopes { } #pragma clang diagnostic pop +- (GIDSignIn *)googleSignIn { + return GIDSignIn.sharedInstance; +} + +- (NSString *)clientID { + return self.authUI.auth.app.options.clientID; +} #pragma mark - FUIAuthProvider @@ -113,14 +118,14 @@ - (nullable NSString *)accessToken { if (self.authUI.isEmulatorEnabled) { return nil; } - return [GIDSignIn sharedInstance].currentUser.authentication.accessToken; + return [self googleSignIn].currentUser.authentication.accessToken; } - (nullable NSString *)idToken { if (self.authUI.isEmulatorEnabled) { return nil; } - return [GIDSignIn sharedInstance].currentUser.authentication.idToken; + return [self googleSignIn].currentUser.authentication.idToken; } - (NSString *)shortName { @@ -159,7 +164,6 @@ - (void)signInWithEmail:(nullable NSString *)email - (void)signInWithDefaultValue:(nullable NSString *)defaultValue presentingViewController:(nullable UIViewController *)presentingViewController completion:(nullable FUIAuthProviderSignInCompletionBlock)completion { - _presentingViewController = presentingViewController; if (self.authUI.isEmulatorEnabled) { [self signInWithOAuthProvider:self.providerForEmulator @@ -168,26 +172,42 @@ - (void)signInWithDefaultValue:(nullable NSString *)defaultValue return; } - GIDSignIn *signIn = [self configuredGoogleSignIn]; - signIn.presentingViewController = presentingViewController; - _pendingSignInCallback = ^(FIRAuthCredential *_Nullable credential, + GIDSignIn *signIn = [self googleSignIn]; + NSString *clientID = [self clientID]; + + if (!clientID) { + [NSException raise:NSInternalInconsistencyException + format:@"OAuth client ID not found. Please make sure Google Sign-In is enabled in " + @"the Firebase console. You may have to download a new GoogleService-Info.plist file after " + @"enabling Google Sign-In."]; + } + + GIDConfiguration *config = [[GIDConfiguration alloc] initWithClientID:clientID]; + + FUIAuthProviderSignInCompletionBlock callback = ^(FIRAuthCredential *_Nullable credential, NSError *_Nullable error, _Nullable FIRAuthResultCallback result, NSDictionary *_Nullable userInfo) { - signIn.loginHint = nil; if (completion) { - completion(credential, error, result, nil); + completion(credential, error, result, userInfo); } }; - signIn.loginHint = defaultValue; - [signIn signIn]; + [signIn signInWithConfiguration:config + presentingViewController:presentingViewController + hint:defaultValue + callback:^(GIDGoogleUser *user, NSError *error) { + [self handleSignInWithUser:user + error:error + presentingViewController:presentingViewController + callback:callback]; + }]; } - (void)signInWithOAuthProvider:(FIROAuthProvider *)oauthProvider presentingViewController:(nullable UIViewController *)presentingViewController completion:(nullable FUIAuthProviderSignInCompletionBlock)completion { - oauthProvider.scopes = self.scopes; + oauthProvider.scopes = [[self class] defaultScopes]; [oauthProvider getCredentialWithUIDelegate:nil completion:^(FIRAuthCredential *_Nullable credential, @@ -214,11 +234,30 @@ - (void)signInWithOAuthProvider:(FIROAuthProvider *)oauthProvider }]; } +- (void)requestScopesWithPresentingViewController:(UIViewController *)presentingViewController + completion:(FUIAuthProviderSignInCompletionBlock)completion { + GIDSignIn *signIn = [self googleSignIn]; + [signIn addScopes:self.scopes presentingViewController:presentingViewController + callback:^(GIDGoogleUser *user, NSError *error) { + [self handleSignInWithUser:user + error:error + presentingViewController:presentingViewController + callback:^(FIRAuthCredential *credential, + NSError *error, + FIRAuthResultCallback result, + NSDictionary *userInfo) { + if (completion != nil) { + completion(credential, error, result, userInfo); + } + }]; + }]; +} + - (void)signOut { if (self.authUI.isEmulatorEnabled) { return; } - GIDSignIn *signIn = [self configuredGoogleSignIn]; + GIDSignIn *signIn = [self googleSignIn]; [signIn signOut]; } @@ -226,7 +265,7 @@ - (BOOL)handleOpenURL:(NSURL *)URL sourceApplication:(NSString *)sourceApplicati if (self.authUI.isEmulatorEnabled) { return NO; } - GIDSignIn *signIn = [self configuredGoogleSignIn]; + GIDSignIn *signIn = [self googleSignIn]; return [signIn handleURL:URL]; } @@ -234,72 +273,38 @@ - (NSString *)email { return _email; } -#pragma mark - GIDSignInDelegate methods - -- (void)signIn:(GIDSignIn *)signIn - didSignInForUser:(GIDGoogleUser *)user - withError:(NSError *)error { +- (void)handleSignInWithUser:(GIDGoogleUser *)user + error:(NSError *)error + presentingViewController:(UIViewController *)presentingViewController + callback:(FUIAuthProviderSignInCompletionBlock)callback { if (error) { if (error.code == kGIDSignInErrorCodeCanceled) { - [self callbackWithCredential:nil - error:[FUIAuthErrorUtils - userCancelledSignInError] result:nil]; + NSError *newError = [FUIAuthErrorUtils userCancelledSignInError]; + if (callback) { + callback(nil, newError, nil, nil); + } } else { NSError *newError = [FUIAuthErrorUtils providerErrorWithUnderlyingError:error providerID:FIRGoogleAuthProviderID]; - [self callbackWithCredential:nil error:newError result:nil]; + if (callback) { + callback(nil, newError, nil, nil); + } } return; } _email = user.profile.email; UIActivityIndicatorView *activityView = - [FUIAuthBaseViewController addActivityIndicator:_presentingViewController.view]; + [FUIAuthBaseViewController addActivityIndicator:presentingViewController.view]; [activityView startAnimating]; FIRAuthCredential *credential = [FIRGoogleAuthProvider credentialWithIDToken:user.authentication.idToken accessToken:user.authentication.accessToken]; - [self callbackWithCredential:credential error:nil result:^(FIRUser *_Nullable user, - NSError *_Nullable error) { + FIRAuthResultCallback result = ^(FIRUser *_Nullable user, + NSError *_Nullable error) { [activityView stopAnimating]; [activityView removeFromSuperview]; - }]; -} - -#pragma mark - Helpers - -/** @fn configuredGoogleSignIn - @brief Returns an instance of @c GIDSignIn which is configured to match the configuration - of this instance. - */ -- (GIDSignIn *)configuredGoogleSignIn { - GIDSignIn *signIn = [GIDSignIn sharedInstance]; - signIn.delegate = self; - signIn.shouldFetchBasicProfile = YES; - signIn.clientID = [[FIRApp defaultApp] options].clientID; - if (!signIn.clientID) { - [NSException raise:NSInternalInconsistencyException - format:@"OAuth client ID not found. Please make sure Google Sign-In is enabled in " - @"the Firebase console. You may have to download a new GoogleService-Info.plist file after " - @"enabling Google Sign-In."]; - } - signIn.scopes = _scopes; - return signIn; -} - -/** @fn callbackWithCredential:error: - @brief Ends the sign-in flow by cleaning up and calling back with given credential or error. - @param credential The credential to pass back, if any. - @param error The error to pass back, if any. - @param result The result of sign-in operation using provided @c FIRAuthCredential object. - @see @c FIRAuth.signInWithCredential:completion: - */ -- (void)callbackWithCredential:(nullable FIRAuthCredential *)credential - error:(nullable NSError *)error - result:(nullable FIRAuthResultCallback)result { - FUIAuthProviderSignInCompletionBlock callback = _pendingSignInCallback; - _presentingViewController = nil; - _pendingSignInCallback = nil; + }; if (callback) { callback(credential, error, result, nil); } diff --git a/FirebaseGoogleAuthUI/Sources/Public/FirebaseGoogleAuthUI/FUIGoogleAuth.h b/FirebaseGoogleAuthUI/Sources/Public/FirebaseGoogleAuthUI/FUIGoogleAuth.h index f657fc37188..5b9d5eea7ae 100644 --- a/FirebaseGoogleAuthUI/Sources/Public/FirebaseGoogleAuthUI/FUIGoogleAuth.h +++ b/FirebaseGoogleAuthUI/Sources/Public/FirebaseGoogleAuthUI/FUIGoogleAuth.h @@ -46,7 +46,9 @@ static NSString *const kGoogleUserInfoProfileScope = @"https://www.googleapis.co /** @property scopes @brief The scopes to use with Google Sign In. @remarks Defaults to using email and profile scopes. For a list of all scopes - see https://developers.google.com/identity/protocols/googlescopes + see https://developers.google.com/identity/protocols/googlescopes. + Starting with GoogleSignIn 6.0, scopes are no longer granted upon first authentication and + should be requested lazily. */ @property(nonatomic, copy, readonly) NSArray *scopes; @@ -66,7 +68,9 @@ static NSString *const kGoogleUserInfoProfileScope = @"https://www.googleapis.co @brief Designated initializer. @param authUI The @c FUIAuth instance that manages this provider. @param scopes The user account scopes required by the app. A list of possible scopes can be - found at https://developers.google.com/identity/protocols/googlescopes + found at https://developers.google.com/identity/protocols/googlescopes. + Starting with GoogleSignIn 6.0, scopes are no longer granted upon first authentication and + should be requested lazily. */ - (instancetype)initWithAuthUI:(FUIAuth *)authUI scopes:(NSArray *)scopes NS_DESIGNATED_INITIALIZER; @@ -85,6 +89,12 @@ __attribute__((deprecated("Instead use initWithAuthUI:"))); - (instancetype)initWithScopes:(NSArray *)scopes __attribute__((deprecated("Instead use initWithAuthUI:permissions:"))) NS_DESIGNATED_INITIALIZER; +/** @fn requestScopesWithPresentingViewController:completion: + @brief Requests the scopes in the `scopes` array. + */ +- (void)requestScopesWithPresentingViewController:(UIViewController *)presentingViewController + completion:(FUIAuthProviderSignInCompletionBlock)completion; + @end NS_ASSUME_NONNULL_END diff --git a/Package.swift b/Package.swift index 222140ab8a6..863f908f8b7 100644 --- a/Package.swift +++ b/Package.swift @@ -46,6 +46,10 @@ let package = Package( name: "FirebaseFirestoreUI", targets: ["FirebaseFirestoreUI"] ), + .library( + name: "FirebaseGoogleAuthUI", + targets: ["FirebaseGoogleAuthUI"] + ), .library( name: "FirebaseOAuthUI", targets: ["FirebaseOAuthUI"] @@ -70,6 +74,11 @@ let package = Package( url: "https://github.com/firebase/firebase-ios-sdk.git", from: "8.0.0" ), + .package( + name: "GoogleSignIn", + url: "https://github.com/google/GoogleSignIn-iOS", + from: "6.0.0" + ), .package( name: "GoogleUtilities", url: "https://github.com/google/GoogleUtilities.git", @@ -181,23 +190,23 @@ let package = Package( .headerSearchPath("../../"), ] ), - // .target( - // name: "GoogleAuthUI", - // dependencies: [ - // "AuthUI", - // // missing google auth dependency - // ], - // path: "GoogleAuth/FirebaseGoogleAuthUI", - // exclude: ["Info.plist"], - // resources: [ - // .process("Resources"), - // .process("Strings"), - // ], - // publicHeadersPath: ".", - // cSettings: [ - // .headerSearchPath("./"), - // ] - // ), + .target( + name: "FirebaseGoogleAuthUI", + dependencies: [ + "FirebaseAuthUI", + "GoogleSignIn" + ], + path: "FirebaseGoogleAuthUI/Sources", + exclude: ["Info.plist"], + resources: [ + .process("Resources"), + .process("Strings"), + ], + publicHeadersPath: "Public", + cSettings: [ + .headerSearchPath("../../"), + ] + ), .target( name: "FirebaseOAuthUI", dependencies: [ diff --git a/samples/swift/Podfile.lock b/samples/swift/Podfile.lock index d689ea01606..01835f141c8 100644 --- a/samples/swift/Podfile.lock +++ b/samples/swift/Podfile.lock @@ -239,7 +239,7 @@ PODS: - FirebaseAuth (~> 8.0) - FirebaseAuthUI - FirebaseCore - - FirebaseAuth (8.2.0): + - FirebaseAuth (8.3.0): - FirebaseCore (~> 8.0) - GoogleUtilities/AppDelegateSwizzler (~> 7.4) - GoogleUtilities/Environment (~> 7.4) @@ -247,16 +247,16 @@ PODS: - FirebaseAuthUI (11.0.3): - FirebaseAuth (~> 8.0) - FirebaseCore - - FirebaseCore (8.2.0): + - FirebaseCore (8.3.0): - FirebaseCoreDiagnostics (~> 8.0) - GoogleUtilities/Environment (~> 7.4) - GoogleUtilities/Logger (~> 7.4) - - FirebaseCoreDiagnostics (8.2.0): + - FirebaseCoreDiagnostics (8.3.0): - GoogleDataTransport (~> 9.0) - GoogleUtilities/Environment (~> 7.4) - GoogleUtilities/Logger (~> 7.4) - nanopb (~> 2.30908.0) - - FirebaseDatabase (8.2.0): + - FirebaseDatabase (8.3.0): - FirebaseCore (~> 8.0) - leveldb-library (~> 1.22) - FirebaseDatabaseUI (11.0.3): @@ -267,12 +267,12 @@ PODS: - FirebaseCore - GoogleUtilities/UserDefaults - FirebaseFacebookAuthUI (11.1.3): - - FBSDKCoreKit + - FBSDKCoreKit_Basics - FBSDKLoginKit (~> 11.0) - FirebaseAuth - FirebaseAuthUI - FirebaseCore - - FirebaseFirestore (8.2.0): + - FirebaseFirestore (8.3.0): - abseil/algorithm (= 0.20200225.0) - abseil/base (= 0.20200225.0) - abseil/memory (= 0.20200225.0) @@ -290,14 +290,14 @@ PODS: - FirebaseAuth - FirebaseAuthUI - FirebaseCore - - GoogleSignIn (~> 5.0) - - FirebaseOAuthUI (11.0.3): + - GoogleSignIn (~> 6.0) + - FirebaseOAuthUI (11.1.3): - FirebaseAuth (~> 8.0) - FirebaseAuthUI - FirebasePhoneAuthUI (11.0.3): - FirebaseAuth - FirebaseAuthUI - - FirebaseStorage (8.2.0): + - FirebaseStorage (8.3.0): - FirebaseCore (~> 8.0) - GTMSessionFetcher/Core (~> 1.5) - FirebaseStorageUI (11.0.3): @@ -334,30 +334,30 @@ PODS: - FirebasePhoneAuthUI (~> 11.0) - FirebaseUI/Storage (11.0.3): - FirebaseStorageUI (~> 11.0) - - GoogleDataTransport (9.0.1): + - GoogleDataTransport (9.1.0): - GoogleUtilities/Environment (~> 7.2) - nanopb (~> 2.30908.0) - - PromisesObjC (~> 1.2) - - GoogleSignIn (5.0.2): - - AppAuth (~> 1.2) + - PromisesObjC (< 3.0, >= 1.2) + - GoogleSignIn (6.0.0): + - AppAuth (~> 1.4) - GTMAppAuth (~> 1.0) - GTMSessionFetcher/Core (~> 1.1) - - GoogleUtilities/AppDelegateSwizzler (7.4.3): + - GoogleUtilities/AppDelegateSwizzler (7.5.0): - GoogleUtilities/Environment - GoogleUtilities/Logger - GoogleUtilities/Network - - GoogleUtilities/Environment (7.4.3): - - PromisesObjC (~> 1.2) - - GoogleUtilities/Logger (7.4.3): + - GoogleUtilities/Environment (7.5.0): + - PromisesObjC (< 3.0, >= 1.2) + - GoogleUtilities/Logger (7.5.0): - GoogleUtilities/Environment - - GoogleUtilities/Network (7.4.3): + - GoogleUtilities/Network (7.5.0): - GoogleUtilities/Logger - "GoogleUtilities/NSData+zlib" - GoogleUtilities/Reachability - - "GoogleUtilities/NSData+zlib (7.4.3)" - - GoogleUtilities/Reachability (7.4.3): + - "GoogleUtilities/NSData+zlib (7.5.0)" + - GoogleUtilities/Reachability (7.5.0): - GoogleUtilities/Logger - - GoogleUtilities/UserDefaults (7.4.3): + - GoogleUtilities/UserDefaults (7.5.0): - GoogleUtilities/Logger - "gRPC-C++ (1.28.2)": - "gRPC-C++/Implementation (= 1.28.2)" @@ -393,7 +393,7 @@ PODS: - nanopb/encode (= 2.30908.0) - nanopb/decode (2.30908.0) - nanopb/encode (2.30908.0) - - PromisesObjC (1.2.12) + - PromisesObjC (2.0.0) - SDWebImage (5.11.1): - SDWebImage/Core (= 5.11.1) - SDWebImage/Core (5.11.1) @@ -469,32 +469,32 @@ SPEC CHECKSUMS: FBSDKCoreKit_Basics: 06780a4a12e16596bde8406add02c6aa1bf38616 FBSDKLoginKit: 8243e04c590c38b85c69fcf09d1234514d2475c3 FirebaseAnonymousAuthUI: 64de9383870378e8f16ef428d73e8c18e74ce5cc - FirebaseAuth: 4c4fb0ba1a169f3acb4aa5b724f7ae7c0999ee44 + FirebaseAuth: fd12c82de44e7ad3b821610c387b8251f03aa0f9 FirebaseAuthUI: 3f6dcb6f9e1af8e889916e2e0f0f971a70c2d303 - FirebaseCore: 3a83f24c3de69ec9f9a426e2598125ea51f3a2ce - FirebaseCoreDiagnostics: 61384f54989065b15c36b5922b65112e86811d3c - FirebaseDatabase: 9c231733363229ac26a55ee9ae9031e94cdb9a7d + FirebaseCore: a6dba751680d7033b9d3831e1cfc95ead0605118 + FirebaseCoreDiagnostics: 7e873baabcfaa9512f538554ae4fa0817aaafbdb + FirebaseDatabase: 3cb36bbf667be87d72cebc8dbe72e2e8cac1d615 FirebaseDatabaseUI: 4db2acaaee3c1a73e0daf31e926a8b7212941607 FirebaseEmailAuthUI: 9d3ef1a6b89049079baaaea254f30c205176ceea - FirebaseFacebookAuthUI: fa945e464b3ec751b5768f03f97f3479b99111c5 - FirebaseFirestore: 844182d64f052a8177d1766d14332e3af4726f3c + FirebaseFacebookAuthUI: 4110202288720f9a74be9c1aa2d3308a39589566 + FirebaseFirestore: f4f42828c6d82f6945575611c23dd343e0e7d0aa FirebaseFirestoreUI: 24a7a35da1a570e8aabd592f60de9438f6959a4c - FirebaseGoogleAuthUI: d5dce74c7ae76b1fb18ece8a3be17c2fb6d47319 - FirebaseOAuthUI: 9f2f90a6cf72f1345473d205ff2071b994a071d8 + FirebaseGoogleAuthUI: 70d781b69bc933f7b43cd4363e3772376ed53d2a + FirebaseOAuthUI: 2cac38e94a39f9d930a7ffc30fbad1683b4e0b62 FirebasePhoneAuthUI: 12bb994905add3399eb0e48f64080d2b916309bb - FirebaseStorage: 001a1f6b1ec45ed60ff9689390d23988e4b95a61 + FirebaseStorage: ff380720c204593d98c3e5482e62ccfbb522f0c5 FirebaseStorageUI: d66a62c897de1d0f279ec80c7ece6b8afc9c5913 FirebaseUI: d2777b3abcb3fa40ea9eea9e40db5a154df608d3 - GoogleDataTransport: 04c3e9a480bbcaa2ec3f5d27f1cdeb6a92f20c8d - GoogleSignIn: 7137d297ddc022a7e0aa4619c86d72c909fa7213 - GoogleUtilities: 45dbb24a7f351d69d0a601482b39ad6c32e30dab + GoogleDataTransport: 85fd18ff3019bb85d3f2c551d04c481dedf71fc9 + GoogleSignIn: b7779a809e1dfb32ebb43131b10d8bfcd53c1383 + GoogleUtilities: eea970f4a389963963bffe8d8fabe43540678b9c "gRPC-C++": 13d8ccef97d5c3c441b7e3c529ef28ebee86fad2 gRPC-Core: 4afa11bfbedf7cdecd04de535a9e046893404ed5 GTMAppAuth: ad5c2b70b9a8689e1a04033c9369c4915bfcbe89 GTMSessionFetcher: 36689134877faeb055b27dfa4ccc9ceaa42e029e leveldb-library: 50c7b45cbd7bf543c81a468fe557a16ae3db8729 nanopb: a0ba3315591a9ae0a16a309ee504766e90db0c96 - PromisesObjC: 3113f7f76903778cf4a0586bd1ab89329a0b7b97 + PromisesObjC: 68159ce6952d93e17b2dfe273b8c40907db5ba58 SDWebImage: a7f831e1a65eb5e285e3fb046a23fcfbf08e696d PODFILE CHECKSUM: 50c55b4b9231c6141172c8e2aba7f1624a881dd7