aboutsummaryrefslogtreecommitdiffhomepage
path: root/Example
diff options
context:
space:
mode:
authorGravatar Zsika Phillip <protocol86@users.noreply.github.com>2018-04-25 06:49:59 -0700
committerGravatar Paul Beusterien <paulbeusterien@google.com>2018-04-25 06:49:59 -0700
commit0ae7d902d724be67d77d5dab1ad698a6ab4e3dfc (patch)
tree6082b2e32e07fa94858a6582820b5d8e38baff8d /Example
parent260557691fae8ba34e262f480c632ab63b5133ee (diff)
First pass of Auth breaking changes (#1123)
Diffstat (limited to 'Example')
-rw-r--r--Example/Auth/Sample/MainViewController.m64
-rw-r--r--Example/Auth/Tests/FIRAuthTests.m75
-rw-r--r--Example/Auth/Tests/FIRUserTests.m9
3 files changed, 84 insertions, 64 deletions
diff --git a/Example/Auth/Sample/MainViewController.m b/Example/Auth/Sample/MainViewController.m
index d4915cd..4c9ec13 100644
--- a/Example/Auth/Sample/MainViewController.m
+++ b/Example/Auth/Sample/MainViewController.m
@@ -143,7 +143,7 @@ static NSString *const kSignInEmailPasswordButtonText = @"Sign in with Email/Pas
@brief The text of the "Email/Password SignIn (AuthDataResult)" button.
*/
static NSString *const kSignInEmailPasswordAuthDataResultButtonText =
- @"Sign in with Email/Password (AuthDataReult)";
+ @"Sign in with Email/Password (Deprecated)";
/** @var kSignInWithCustomTokenButtonText
@brief The text of the "Sign In (BYOAuth)" button.
@@ -154,7 +154,7 @@ static NSString *const kSignInWithCustomTokenButtonText = @"Sign In (BYOAuth)";
@brief The text of the "Sign In with Custom Token (Auth Result)" button.
*/
static NSString *const kSignInWithCustomAuthResultTokenButtonText = @"Sign In with Custom Token"
- " (Auth Result)";
+ " (Deprecated)";
/** @var kSignInAnonymouslyButtonText
@brief The text of the "Sign In Anonymously" button.
@@ -165,7 +165,7 @@ static NSString *const kSignInAnonymouslyButtonText = @"Sign In Anonymously";
@brief The text of the "Sign In Anonymously (AuthDataResult)" button.
*/
static NSString *const kSignInAnonymouslyWithAuthResultButtonText =
- @"Sign In Anonymously (AuthDataResult)";
+ @"Sign In Anonymously (Deprecated)";
/** @var kSignedInAlertTitle
@brief The text of the "Sign In Succeeded" alert.
@@ -1226,11 +1226,13 @@ static NSDictionary<NSString *, NSString *> *parseURL(NSString *urlString) {
return;
}
[auth signOut:NULL];
- [self signInAnonymouslyWithCallback:^(FIRUser *_Nullable user, NSError *_Nullable error) {
- if (user) {
- NSString *anonymousUID = user.uid;
- [self signInAnonymouslyWithCallback:^(FIRUser *_Nullable user, NSError *_Nullable error) {
- if (![user.uid isEqual:anonymousUID]) {
+ [self signInAnonymouslyWithCallback:^(FIRAuthDataResult *_Nullable result,
+ NSError *_Nullable error) {
+ if (result.user) {
+ NSString *anonymousUID = result.user.uid;
+ [self signInAnonymouslyWithCallback:^(FIRAuthDataResult *_Nullable user,
+ NSError *_Nullable error) {
+ if (![result.user.uid isEqual:anonymousUID]) {
[self logFailedTest:@"Consecutive anonymous sign-ins should yeild the same User ID"];
return;
}
@@ -1244,13 +1246,13 @@ static NSDictionary<NSString *, NSString *> *parseURL(NSString *urlString) {
@brief Performs anonymous sign in and then executes callback.
@param callback The callback to be executed.
*/
-- (void)signInAnonymouslyWithCallback:(nullable FIRAuthResultCallback)callback {
+- (void)signInAnonymouslyWithCallback:(nullable FIRAuthDataResultCallback)callback {
FIRAuth *auth = [AppManager auth];
if (!auth) {
[self logFailedTest:@"Could not obtain auth object."];
return;
}
- [auth signInAnonymouslyWithCompletion:^(FIRUser *_Nullable user,
+ [auth signInAnonymouslyWithCompletion:^(FIRAuthDataResult *_Nullable result,
NSError *_Nullable error) {
if (error) {
[self logFailure:@"sign-in anonymously failed" error:error];
@@ -1259,7 +1261,7 @@ static NSDictionary<NSString *, NSString *> *parseURL(NSString *urlString) {
}
[self logSuccess:@"sign-in anonymously succeeded."];
if (callback) {
- callback(user, nil);
+ callback(result, nil);
}
}];
}
@@ -1275,9 +1277,10 @@ static NSDictionary<NSString *, NSString *> *parseURL(NSString *urlString) {
return;
}
[auth signOut:NULL];
- [self signInAnonymouslyWithCallback:^(FIRUser *_Nullable user, NSError *_Nullable error) {
- if (user) {
- NSString *anonymousUID = user.uid;
+ [self signInAnonymouslyWithCallback:^(FIRAuthDataResult *_Nullable result,
+ NSError *_Nullable error) {
+ if (result.user) {
+ NSString *anonymousUID = result.user.uid;
[self showMessagePromptWithTitle:@"Sign In Instructions"
message:kUnlinkAccountMessagePrompt
showCancelButton:NO
@@ -1287,7 +1290,8 @@ static NSDictionary<NSString *, NSString *> *parseURL(NSString *urlString) {
callback:^(FIRAuthCredential *credential,
NSError *error) {
if (credential) {
- [user linkWithCredential:credential completion:^(FIRUser *user, NSError *error) {
+ [result.user linkWithCredential:credential completion:^(FIRUser *user,
+ NSError *error) {
if (error) {
[self logFailure:@"link auth provider failed" error:error];
[self logFailedTest:@"Account needs to be linked to complete the test."];
@@ -1346,7 +1350,7 @@ static NSDictionary<NSString *, NSString *> *parseURL(NSString *urlString) {
}
FIRAuth *auth = [AppManager auth];
[auth signInWithCustomToken:customToken
- completion:^(FIRUser *_Nullable user, NSError *_Nullable error) {
+ completion:^(FIRAuthDataResult *_Nullable result, NSError *_Nullable error) {
if (error) {
[self logFailure:@"sign-in with custom token failed" error:error];
[self logFailedTest:@"A fresh custom token should succeed in signing-in."];
@@ -1364,7 +1368,8 @@ static NSDictionary<NSString *, NSString *> *parseURL(NSString *urlString) {
[self logSuccess:@"refresh token succeeded."];
[auth signOut:NULL];
[auth signInWithCustomToken:expiredCustomToken
- completion:^(FIRUser *_Nullable user, NSError *_Nullable error) {
+ completion:^(FIRAuthDataResult *_Nullable result,
+ NSError *_Nullable error) {
if (!error) {
[self logSuccess:@"sign-in with custom token succeeded."];
[self logFailedTest:@"sign-in with an expired custom token should NOT succeed."];
@@ -1372,7 +1377,7 @@ static NSDictionary<NSString *, NSString *> *parseURL(NSString *urlString) {
}
[self logFailure:@"sign-in with custom token failed" error:error];
[auth signInWithCustomToken:kInvalidCustomToken
- completion:^(FIRUser *_Nullable user,
+ completion:^(FIRAuthDataResult *_Nullable result,
NSError *_Nullable error) {
if (!error) {
[self logSuccess:@"sign-in with custom token succeeded."];
@@ -1405,7 +1410,8 @@ static NSDictionary<NSString *, NSString *> *parseURL(NSString *urlString) {
return;
}
[[AppManager auth] signInWithCustomToken:customToken
- completion:^(FIRUser *_Nullable user, NSError *_Nullable error) {
+ completion:^(FIRAuthDataResult *_Nullable user,
+ NSError *_Nullable error) {
if (error) {
[self logFailure:@"sign-in with custom token failed" error:error];
[self logFailedTest:@"A fresh custom token should succeed in signing-in."];
@@ -1435,7 +1441,8 @@ static NSDictionary<NSString *, NSString *> *parseURL(NSString *urlString) {
return;
}
[[AppManager auth] signInWithCustomToken:customToken
- completion:^(FIRUser *_Nullable user, NSError *_Nullable error) {
+ completion:^(FIRAuthDataResult *_Nullable result,
+ NSError *_Nullable error) {
if (error) {
[self logFailure:@"sign-in with custom token failed" error:error];
[self logFailedTest:@"A fresh custom token should succeed in signing-in."];
@@ -1683,7 +1690,7 @@ static NSDictionary<NSString *, NSString *> *parseURL(NSString *urlString) {
@brief Invoked when "Sign in with Google" row is pressed.
*/
- (void)signInGoogle {
- [self signinWithProvider:[AuthProviders google] retrieveData:NO];
+ [self signinWithProvider:[AuthProviders google] retrieveData:YES];
}
/** @fn signInGoogleAndRetrieveData
@@ -1697,7 +1704,7 @@ static NSDictionary<NSString *, NSString *> *parseURL(NSString *urlString) {
@brief Invoked when "Sign in with Facebook" row is pressed.
*/
- (void)signInFacebook {
- [self signinWithProvider:[AuthProviders facebook] retrieveData:NO];
+ [self signinWithProvider:[AuthProviders facebook] retrieveData:YES];
}
/** @fn signInFacebookAndRetrieveData
@@ -3149,12 +3156,13 @@ static NSDictionary<NSString *, NSString *> *parseURL(NSString *urlString) {
@brief Signs in as an anonymous user.
*/
- (void)signInAnonymously {
- [[AppManager auth] signInAnonymouslyWithCompletion:^(FIRUser *_Nullable user,
+ [[AppManager auth] signInAnonymouslyWithCompletion:^(FIRAuthDataResult *_Nullable result,
NSError *_Nullable error) {
if (error) {
[self logFailure:@"sign-in anonymously failed" error:error];
} else {
[self logSuccess:@"sign-in anonymously succeeded."];
+ [self log:[NSString stringWithFormat:@"User ID : %@", result.user.uid]];
}
[self showTypicalUIForUserUpdateResultsWithTitle:kSignInAnonymouslyButtonText error:error];
}];
@@ -3190,8 +3198,9 @@ static NSDictionary<NSString *, NSString *> *parseURL(NSString *urlString) {
FIRAuthCredential *credential =
[FIROAuthProvider credentialWithProviderID:FIRGitHubAuthProviderID accessToken:accessToken];
if (credential) {
- [[AppManager auth] signInWithCredential:credential completion:^(FIRUser *_Nullable user,
- NSError *_Nullable error) {
+ [[AppManager auth] signInWithCredential:credential
+ completion:^(FIRUser *_Nullable result,
+ NSError *_Nullable error) {
if (error) {
[self logFailure:@"sign-in with provider failed" error:error];
} else {
@@ -3338,7 +3347,8 @@ static NSDictionary<NSString *, NSString *> *parseURL(NSString *urlString) {
- (void)doSignInWithCustomToken:(NSString *_Nullable)userEnteredTokenText {
[[AppManager auth] signInWithCustomToken:userEnteredTokenText
- completion:^(FIRUser *_Nullable user, NSError *_Nullable error) {
+ completion:^(FIRAuthDataResult *_Nullable result,
+ NSError *_Nullable error) {
if (error) {
[self logFailure:@"sign-in with custom token failed" error:error];
[self showMessagePromptWithTitle:kSignInErrorAlertTitle
@@ -3349,7 +3359,7 @@ static NSDictionary<NSString *, NSString *> *parseURL(NSString *urlString) {
}
[self logSuccess:@"sign-in with custom token succeeded."];
[self showMessagePromptWithTitle:kSignedInAlertTitle
- message:user.displayName
+ message:result.user.displayName
showCancelButton:NO
completion:nil];
}];
diff --git a/Example/Auth/Tests/FIRAuthTests.m b/Example/Auth/Tests/FIRAuthTests.m
index 47a430b..d238057 100644
--- a/Example/Auth/Tests/FIRAuthTests.m
+++ b/Example/Auth/Tests/FIRAuthTests.m
@@ -712,10 +712,10 @@ static const NSTimeInterval kWaitInterval = .5;
[[FIRAuth auth] signOut:NULL];
[[FIRAuth auth] signInWithEmail:kEmail
password:kFakePassword
- completion:^(FIRUser *_Nullable user,
+ completion:^(FIRAuthDataResult *_Nullable result,
NSError *_Nullable error) {
XCTAssertTrue([NSThread isMainThread]);
- [self assertUser:user];
+ [self assertUser:result.user];
XCTAssertNil(error);
[expectation fulfill];
}];
@@ -734,10 +734,10 @@ static const NSTimeInterval kWaitInterval = .5;
[[FIRAuth auth] signOut:NULL];
[[FIRAuth auth] signInWithEmail:kEmail
password:kFakePassword
- completion:^(FIRUser *_Nullable user,
+ completion:^(FIRAuthDataResult *_Nullable result,
NSError *_Nullable error) {
XCTAssertTrue([NSThread isMainThread]);
- XCTAssertNil(user);
+ XCTAssertNil(result.user);
XCTAssertEqual(error.code, FIRAuthErrorCodeWrongPassword);
XCTAssertNotNil(error.userInfo[NSLocalizedDescriptionKey]);
[expectation fulfill];
@@ -1071,8 +1071,9 @@ static const NSTimeInterval kWaitInterval = .5;
[[FIRAuth auth] signOut:NULL];
FIRAuthCredential *emailCredential =
[FIREmailAuthProvider credentialWithEmail:kEmail link:kFakeEmailSignInlink];
- [[FIRAuth auth] signInWithCredential:emailCredential completion:^(FIRUser *_Nullable user,
- NSError *_Nullable error) {
+ [[FIRAuth auth] signInWithCredential:emailCredential
+ completion:^(FIRUser *_Nullable user,
+ NSError *_Nullable error) {
XCTAssertTrue([NSThread isMainThread]);
XCTAssertNil(user);
XCTAssertEqual(error.code, FIRAuthErrorCodeUserDisabled);
@@ -1107,8 +1108,9 @@ static const NSTimeInterval kWaitInterval = .5;
[[FIRAuth auth] signOut:NULL];
FIRAuthCredential *emailCredential =
[FIREmailAuthProvider credentialWithEmail:kEmail password:kFakePassword];
- [[FIRAuth auth] signInWithCredential:emailCredential completion:^(FIRUser *_Nullable user,
- NSError *_Nullable error) {
+ [[FIRAuth auth] signInWithCredential:emailCredential
+ completion:^(FIRUser *_Nullable user,
+ NSError *_Nullable error) {
XCTAssertTrue([NSThread isMainThread]);
[self assertUser:user];
XCTAssertNil(error);
@@ -1145,8 +1147,9 @@ static const NSTimeInterval kWaitInterval = .5;
FIRAuthCredential *emailCredential =
[FIREmailPasswordAuthProvider credentialWithEmail:kEmail password:kFakePassword];
#pragma clang diagnostic pop
- [[FIRAuth auth] signInWithCredential:emailCredential completion:^(FIRUser *_Nullable user,
- NSError *_Nullable error) {
+ [[FIRAuth auth] signInWithCredential:emailCredential
+ completion:^(FIRUser *_Nullable user,
+ NSError *_Nullable error) {
XCTAssertTrue([NSThread isMainThread]);
[self assertUser:user];
XCTAssertNil(error);
@@ -1168,8 +1171,9 @@ static const NSTimeInterval kWaitInterval = .5;
[[FIRAuth auth] signOut:NULL];
FIRAuthCredential *emailCredential =
[FIREmailAuthProvider credentialWithEmail:kEmail password:kFakePassword];
- [[FIRAuth auth] signInWithCredential:emailCredential completion:^(FIRUser *_Nullable user,
- NSError *_Nullable error) {
+ [[FIRAuth auth] signInWithCredential:emailCredential
+ completion:^(FIRUser *_Nullable user,
+ NSError *_Nullable error) {
XCTAssertTrue([NSThread isMainThread]);
XCTAssertNil(user);
XCTAssertEqual(error.code, FIRAuthErrorCodeUserDisabled);
@@ -1193,8 +1197,8 @@ static const NSTimeInterval kWaitInterval = .5;
[[FIRAuth auth] signOut:NULL];
FIRAuthCredential *emailCredential =
[FIREmailAuthProvider credentialWithEmail:kEmail password:emptyString];
- [[FIRAuth auth] signInWithCredential:emailCredential completion:^(FIRUser *_Nullable user,
- NSError *_Nullable error) {
+ [[FIRAuth auth] signInWithCredential:emailCredential
+ completion:^(FIRUser *_Nullable user, NSError *_Nullable error) {
XCTAssertTrue([NSThread isMainThread]);
XCTAssertEqual(error.code, FIRAuthErrorCodeWrongPassword);
[expectation fulfill];
@@ -1228,8 +1232,9 @@ static const NSTimeInterval kWaitInterval = .5;
[[FIRAuth auth] signOut:NULL];
FIRAuthCredential *googleCredential =
[FIRGoogleAuthProvider credentialWithIDToken:kGoogleIDToken accessToken:kGoogleAccessToken];
- [[FIRAuth auth] signInWithCredential:googleCredential completion:^(FIRUser *_Nullable user,
- NSError *_Nullable error) {
+ [[FIRAuth auth] signInWithCredential:googleCredential
+ completion:^(FIRUser *_Nullable user,
+ NSError *_Nullable error) {
XCTAssertTrue([NSThread isMainThread]);
XCTAssertEqual(error.code, FIRAuthErrorCodeAccountExistsWithDifferentCredential);
XCTAssertEqualObjects(error.userInfo[FIRAuthErrorUserInfoEmailKey], kEmail);
@@ -1267,8 +1272,9 @@ static const NSTimeInterval kWaitInterval = .5;
[[FIRAuth auth] signOut:NULL];
FIRAuthCredential *googleCredential =
[FIRGoogleAuthProvider credentialWithIDToken:kGoogleIDToken accessToken:kGoogleAccessToken];
- [[FIRAuth auth] signInWithCredential:googleCredential completion:^(FIRUser *_Nullable user,
- NSError *_Nullable error) {
+ [[FIRAuth auth] signInWithCredential:googleCredential
+ completion:^(FIRUser *_Nullable user,
+ NSError *_Nullable error) {
XCTAssertTrue([NSThread isMainThread]);
[self assertUserGoogle:user];
XCTAssertNil(error);
@@ -1336,8 +1342,9 @@ static const NSTimeInterval kWaitInterval = .5;
[[FIRAuth auth] signOut:NULL];
FIRAuthCredential *googleCredential =
[FIRGoogleAuthProvider credentialWithIDToken:kGoogleIDToken accessToken:kGoogleAccessToken];
- [[FIRAuth auth] signInWithCredential:googleCredential completion:^(FIRUser *_Nullable user,
- NSError *_Nullable error) {
+ [[FIRAuth auth] signInWithCredential:googleCredential
+ completion:^(FIRUser *_Nullable user,
+ NSError *_Nullable error) {
XCTAssertTrue([NSThread isMainThread]);
XCTAssertNil(user);
XCTAssertEqual(error.code, FIRAuthErrorCodeEmailAlreadyInUse);
@@ -1369,10 +1376,10 @@ static const NSTimeInterval kWaitInterval = .5;
[self expectGetAccountInfoAnonymous];
XCTestExpectation *expectation = [self expectationWithDescription:@"callback"];
[[FIRAuth auth] signOut:NULL];
- [[FIRAuth auth] signInAnonymouslyWithCompletion:^(FIRUser *_Nullable user,
+ [[FIRAuth auth] signInAnonymouslyWithCompletion:^(FIRAuthDataResult *_Nullable result,
NSError *_Nullable error) {
XCTAssertTrue([NSThread isMainThread]);
- [self assertUserAnonymous:user];
+ [self assertUserAnonymous:result.user];
XCTAssertNil(error);
[expectation fulfill];
}];
@@ -1389,10 +1396,10 @@ static const NSTimeInterval kWaitInterval = .5;
.andDispatchError2([FIRAuthErrorUtils operationNotAllowedErrorWithMessage:nil]);
XCTestExpectation *expectation = [self expectationWithDescription:@"callback"];
[[FIRAuth auth] signOut:NULL];
- [[FIRAuth auth] signInAnonymouslyWithCompletion:^(FIRUser *_Nullable user,
+ [[FIRAuth auth] signInAnonymouslyWithCompletion:^(FIRAuthDataResult *_Nullable result,
NSError *_Nullable error) {
XCTAssertTrue([NSThread isMainThread]);
- XCTAssertNil(user);
+ XCTAssertNil(result.user);
XCTAssertEqual(error.code, FIRAuthErrorCodeOperationNotAllowed);
XCTAssertNotNil(error.userInfo[NSLocalizedDescriptionKey]);
[expectation fulfill];
@@ -1474,10 +1481,10 @@ static const NSTimeInterval kWaitInterval = .5;
[self expectGetAccountInfo];
XCTestExpectation *expectation = [self expectationWithDescription:@"callback"];
[[FIRAuth auth] signOut:NULL];
- [[FIRAuth auth] signInWithCustomToken:kCustomToken completion:^(FIRUser *_Nullable user,
+ [[FIRAuth auth] signInWithCustomToken:kCustomToken completion:^(FIRAuthDataResult *_Nullable result,
NSError *_Nullable error) {
XCTAssertTrue([NSThread isMainThread]);
- [self assertUser:user];
+ [self assertUser:result.user];
XCTAssertNil(error);
[expectation fulfill];
}];
@@ -1494,10 +1501,11 @@ static const NSTimeInterval kWaitInterval = .5;
.andDispatchError2([FIRAuthErrorUtils invalidCustomTokenErrorWithMessage:nil]);
XCTestExpectation *expectation = [self expectationWithDescription:@"callback"];
[[FIRAuth auth] signOut:NULL];
- [[FIRAuth auth] signInWithCustomToken:kCustomToken completion:^(FIRUser *_Nullable user,
- NSError *_Nullable error) {
+ [[FIRAuth auth] signInWithCustomToken:kCustomToken
+ completion:^(FIRAuthDataResult *_Nullable result,
+ NSError *_Nullable error) {
XCTAssertTrue([NSThread isMainThread]);
- XCTAssertNil(user);
+ XCTAssertNil(result.user);
XCTAssertEqual(error.code, FIRAuthErrorCodeInvalidCustomToken);
XCTAssertNotNil(error.userInfo[NSLocalizedDescriptionKey]);
[expectation fulfill];
@@ -2434,13 +2442,14 @@ static const NSTimeInterval kWaitInterval = .5;
});
[self expectGetAccountInfoWithAccessToken:accessToken];
XCTestExpectation *expectation = [self expectationWithDescription:@"callback"];
- [[FIRAuth auth] signInWithEmail:kEmail password:kFakePassword completion:^(FIRUser *_Nullable user,
- NSError *_Nullable error) {
+ [[FIRAuth auth] signInWithEmail:kEmail
+ password:kFakePassword
+ completion:^(FIRAuthDataResult *_Nullable result, NSError *_Nullable error) {
- user.requestConfiguration = [[FIRAuthRequestConfiguration alloc] initWithAPIKey:APIKey];
+ result.user.requestConfiguration = [[FIRAuthRequestConfiguration alloc] initWithAPIKey:APIKey];
[expectation fulfill];
if (completion) {
- completion(user, error);
+ completion(result.user, error);
}
}];
[self waitForExpectationsWithTimeout:kExpectationTimeout handler:nil];
diff --git a/Example/Auth/Tests/FIRUserTests.m b/Example/Auth/Tests/FIRUserTests.m
index a27304c..7a6c165 100644
--- a/Example/Auth/Tests/FIRUserTests.m
+++ b/Example/Auth/Tests/FIRUserTests.m
@@ -2244,11 +2244,12 @@ static const NSTimeInterval kExpectationTimeout = 2;
});
[self expectGetAccountInfoWithMockUserInfoResponse:mockUserInfoResponse];
[[FIRAuth auth] signOut:NULL];
- [[FIRAuth auth] signInWithEmail:kEmail password:kFakePassword completion:^(FIRUser *_Nullable user,
- NSError *_Nullable error) {
- XCTAssertNotNil(user);
+ [[FIRAuth auth] signInWithEmail:kEmail
+ password:kFakePassword
+ completion:^(FIRAuthDataResult *_Nullable result, NSError *_Nullable error) {
+ XCTAssertNotNil(result.user);
XCTAssertNil(error);
- completion(user);
+ completion(result.user);
}];
}