Skip to content

Clean up FIRAuth bits from FIRApp #2110

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

Merged
merged 4 commits into from
Dec 7, 2018
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
18 changes: 2 additions & 16 deletions Example/Auth/Tests/FIRAuthTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -365,20 +365,6 @@ - (void)testLifeCycle {
XCTAssertNil(auth);
}

/** @fn testGetUID
@brief Verifies that FIRApp's getUIDImplementation is correctly set by FIRAuth.
*/
- (void)testGetUID {
// TODO: Remove this test once Firestore, Database, and Storage move over to the new Auth interop
// library.
FIRApp *app = [FIRApp defaultApp];
XCTAssertNotNil(app.getUIDImplementation);
[[FIRAuth auth] signOut:NULL];
XCTAssertNil(app.getUIDImplementation());
[self waitForSignIn];
XCTAssertEqualObjects(app.getUIDImplementation(), kLocalID);
}

#pragma mark - Server API Tests

/** @fn testFetchProvidersForEmailSuccess
Expand Down Expand Up @@ -2283,8 +2269,8 @@ - (void)mockSecureTokenResponseWithError:(nullable NSError *)error {
*/
- (void)enableAutoTokenRefresh {
XCTestExpectation *expectation = [self expectationWithDescription:@"autoTokenRefreshcallback"];
[[FIRAuth auth].app getTokenForcingRefresh:NO withCallback:^(NSString *_Nullable token,
NSError *_Nullable error) {
[[FIRAuth auth] getTokenForcingRefresh:NO withCallback:^(NSString *_Nullable token,
NSError *_Nullable error) {
[expectation fulfill];
}];
[self waitForExpectationsWithTimeout:kExpectationTimeout handler:nil];
Expand Down
63 changes: 0 additions & 63 deletions Example/Core/Tests/FIRAppTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -267,59 +267,6 @@ - (void)testErrorForSubspecConfigurationFailure {
XCTAssert([error.description containsString:@"Configuration failed for"]);
}

- (void)testGetTokenWithCallback {
[FIRApp configure];
FIRApp *app = [FIRApp defaultApp];

__block BOOL getTokenImplementationWasCalled = NO;
__block BOOL getTokenCallbackWasCalled = NO;
__block BOOL passedRefreshValue = NO;

[app getTokenForcingRefresh:YES
withCallback:^(NSString *_Nullable token, NSError *_Nullable error) {
getTokenCallbackWasCalled = YES;
}];

XCTAssert(getTokenCallbackWasCalled,
@"The callback should be invoked by the base implementation when no block for "
"'getTokenImplementation' has been specified.");

getTokenCallbackWasCalled = NO;

app.getTokenImplementation = ^(BOOL refresh, FIRTokenCallback callback) {
getTokenImplementationWasCalled = YES;
passedRefreshValue = refresh;
callback(nil, nil);
};
[app getTokenForcingRefresh:YES
withCallback:^(NSString *_Nullable token, NSError *_Nullable error) {
getTokenCallbackWasCalled = YES;
}];

XCTAssert(getTokenImplementationWasCalled,
@"The 'getTokenImplementation' block was never called.");
XCTAssert(passedRefreshValue,
@"The value for the 'refresh' parameter wasn't passed to the 'getTokenImplementation' "
"block correctly.");
XCTAssert(getTokenCallbackWasCalled,
@"The 'getTokenImplementation' should have invoked the callback. This could be an "
"error in this test, or the callback parameter may not have been passed to the "
"implementation correctly.");

getTokenImplementationWasCalled = NO;
getTokenCallbackWasCalled = NO;
passedRefreshValue = NO;

[app getTokenForcingRefresh:NO
withCallback:^(NSString *_Nullable token, NSError *_Nullable error) {
getTokenCallbackWasCalled = YES;
}];

XCTAssertFalse(passedRefreshValue,
@"The value for the 'refresh' parameter wasn't passed to the "
"'getTokenImplementation' block correctly.");
}

- (void)testOptionsLocking {
FIROptions *options =
[[FIROptions alloc] initWithGoogleAppID:kGoogleAppID GCMSenderID:kGCMSenderID];
Expand Down Expand Up @@ -754,16 +701,6 @@ - (void)testAnalyticsNotSetByGlobalDataCollectionSwitch {

#pragma mark - Internal Methods

// TODO: Remove this test once the `getUIDImplementation` block doesn't need to be set in Core.
- (void)testAuthGetUID {
[FIRApp configure];

[FIRApp defaultApp].getUIDImplementation = ^NSString * {
return @"highlander";
};
XCTAssertEqual([[FIRApp defaultApp] getUID], @"highlander");
}

- (void)testIsDefaultAppConfigured {
// Ensure it's false before anything is configured.
XCTAssertFalse([FIRApp isDefaultAppConfigured]);
Expand Down
22 changes: 2 additions & 20 deletions Firebase/Auth/Source/FIRAuth.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#import <UIKit/UIKit.h>
#endif

#import <FirebaseAuthInterop/FIRAuthInterop.h>
#import <FirebaseCore/FIRAppAssociationRegistration.h>
#import <FirebaseCore/FIRAppInternal.h>
#import <FirebaseCore/FIRComponent.h>
Expand Down Expand Up @@ -229,9 +228,9 @@ + (FIRActionCodeOperation)actionCodeOperationForRequestType:(NSString *)requestT
#pragma mark - FIRAuth

#if TARGET_OS_IOS
@interface FIRAuth () <FIRAuthAppDelegateHandler, FIRAuthInterop, FIRComponentRegistrant, FIRCoreConfigurable, FIRComponentLifecycleMaintainer>
@interface FIRAuth () <FIRAuthAppDelegateHandler, FIRComponentRegistrant, FIRCoreConfigurable, FIRComponentLifecycleMaintainer>
#else
@interface FIRAuth () <FIRAuthInterop, FIRComponentRegistrant, FIRCoreConfigurable, FIRComponentLifecycleMaintainer>
@interface FIRAuth () <FIRComponentRegistrant, FIRCoreConfigurable, FIRComponentLifecycleMaintainer>
#endif

/** @property firebaseAppId
Expand Down Expand Up @@ -344,23 +343,6 @@ - (instancetype)initWithApp:(FIRApp *)app {
self = [self initWithAPIKey:app.options.APIKey appName:app.name];
if (self) {
_app = app;
__weak FIRAuth *weakSelf = self;

// TODO: Remove this block once Firestore, Database, and Storage move to the new interop API.
app.getTokenImplementation = ^(BOOL forceRefresh, FIRTokenCallback callback) {
// In the meantime, redirect call to the interop method that provides this functionality.
__weak FIRAuth *weakSelf = self;
[weakSelf getTokenForcingRefresh:forceRefresh withCallback:callback];
};

// TODO: Remove this block once Firestore, Database, and Storage move to the new interop API.
app.getUIDImplementation = ^NSString *_Nullable() {
__block NSString *uid;
dispatch_sync(FIRAuthGlobalWorkQueue(), ^{
uid = [weakSelf getUserID];
});
return uid;
};
#if TARGET_OS_IOS
_authURLPresenter = [[FIRAuthURLPresenter alloc] init];
#endif
Expand Down
4 changes: 3 additions & 1 deletion Firebase/Auth/Source/FIRAuth_Internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#import "FIRAuth.h"

#import <FirebaseAuthInterop/FIRAuthInterop.h>

@class FIRAuthRequestConfiguration;

#if TARGET_OS_IOS
Expand All @@ -29,7 +31,7 @@

NS_ASSUME_NONNULL_BEGIN

@interface FIRAuth ()
@interface FIRAuth () <FIRAuthInterop>

/** @property requestConfiguration
@brief The configuration object comprising of paramters needed to make a request to Firebase
Expand Down
18 changes: 0 additions & 18 deletions Firebase/Core/FIRApp.m
Original file line number Diff line number Diff line change
Expand Up @@ -281,15 +281,6 @@ - (instancetype)initInstanceWithName:(NSString *)name options:(FIROptions *)opti
return self;
}

- (void)getTokenForcingRefresh:(BOOL)forceRefresh withCallback:(FIRTokenCallback)callback {
if (!_getTokenImplementation) {
callback(nil, nil);
return;
}

_getTokenImplementation(forceRefresh, callback);
}

- (BOOL)configureCore {
[self checkExpectedBundleID];
if (![self isAppIDValid]) {
Expand Down Expand Up @@ -538,15 +529,6 @@ - (void)checkExpectedBundleID {
}
}

// TODO: Remove once SDKs transition to Auth interop library.
- (nullable NSString *)getUID {
if (!_getUIDImplementation) {
FIRLogWarning(kFIRLoggerCore, @"I-COR000025", @"FIRAuth getUID implementation wasn't set.");
return nil;
}
return _getUIDImplementation();
}

#pragma mark - private - App ID Validation

/**
Expand Down
42 changes: 0 additions & 42 deletions Firebase/Core/Private/FIRAppInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,42 +109,13 @@ extern NSString *const FIRAuthStateDidChangeInternalNotificationAppKey;
*/
extern NSString *const FIRAuthStateDidChangeInternalNotificationUIDKey;

/** @typedef FIRTokenCallback
@brief The type of block which gets called when a token is ready.
*/
typedef void (^FIRTokenCallback)(NSString *_Nullable token, NSError *_Nullable error);

/** @typedef FIRAppGetTokenImplementation
@brief The type of block which can provide an implementation for the @c getTokenWithCallback:
method.
@param forceRefresh Forces the token to be refreshed.
@param callback The block which should be invoked when the async call completes.
*/
typedef void (^FIRAppGetTokenImplementation)(BOOL forceRefresh, FIRTokenCallback callback);

/** @typedef FIRAppGetUID
@brief The type of block which can provide an implementation for the @c getUID method.
*/
typedef NSString *_Nullable (^FIRAppGetUIDImplementation)(void);

@interface FIRApp ()

/**
* A flag indicating if this is the default app (has the default app name).
*/
@property(nonatomic, readonly) BOOL isDefaultApp;

/** @property getTokenImplementation
@brief Gets or sets the block to use for the implementation of
@c getTokenForcingRefresh:withCallback:
*/
@property(nonatomic, copy) FIRAppGetTokenImplementation getTokenImplementation;

/** @property getUIDImplementation
@brief Gets or sets the block to use for the implementation of @c getUID.
*/
@property(nonatomic, copy) FIRAppGetUIDImplementation getUIDImplementation;

/*
* The container of interop SDKs for this app.
*/
Expand Down Expand Up @@ -204,19 +175,6 @@ typedef NSString *_Nullable (^FIRAppGetUIDImplementation)(void);
*/
- (instancetype)initInstanceWithName:(NSString *)name options:(FIROptions *)options;

/** @fn getTokenForcingRefresh:withCallback:
@brief Retrieves the Firebase authentication token, possibly refreshing it.
@param forceRefresh Forces a token refresh. Useful if the token becomes invalid for some reason
other than an expiration.
@param callback The block to invoke when the token is available.
*/
- (void)getTokenForcingRefresh:(BOOL)forceRefresh withCallback:(FIRTokenCallback)callback;

/**
* Expose the UID of the current user for Firestore.
*/
- (nullable NSString *)getUID;

@end

NS_ASSUME_NONNULL_END