-
Notifications
You must be signed in to change notification settings - Fork 1.7k
MFA beta #4823
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
MFA beta #4823
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
f95b28f
Initial changes
renkelvin ae12a3e
Fix white space
renkelvin d586cd4
Add platform specific macro
renkelvin 8529900
Undo override
renkelvin 15d5336
Fix a test when email is unchanged
renkelvin a581b91
Fix warnings
renkelvin b7cc4ed
Fix pr issues
renkelvin d6d0b50
Fix build issue
renkelvin b688985
Fix build issue
renkelvin a6d98d0
Fix build issue
renkelvin d418295
Tmp disable quickstart tests
renkelvin eaacf48
Revert "Tmp disable quickstart tests"
renkelvin 6ec7dfa
Fix pr issues.
renkelvin 2082b26
Disable quickstart tests
renkelvin 912d948
Id->ID
renkelvin 7c0478b
Revert "Disable quickstart tests"
renkelvin e5a70dc
Add FIRActionCodeURL
renkelvin 8ae2529
Update FIRAuth.m
renkelvin 6add233
Fix pr issues
renkelvin b36b7ab
Fix pr issues
renkelvin 33f59b6
Fix pr issues
renkelvin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| /* | ||
| * Copyright 2019 Google | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import XCTest | ||
|
|
||
| let kNoSecondFactorUserEmail = "iosapitests+no_second_factor@gmail.com" | ||
| let kNoSecondFactorUserPassword = "aaaaaa" | ||
|
|
||
| let kPhoneSecondFactorPhoneNumber = "+16509999999" | ||
| let kPhoneSecondFactorVerificationCode = "123456" | ||
| let kPhoneSecondFactorDisplayName = "phone1" | ||
|
|
||
| let kOneSecondFactorUserEmail = "iosapitests+one_phone_second_factor@gmail.com" | ||
| let kOneSecondFactorUserPassword = "aaaaaa" | ||
renkelvin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| class PhoneMultiFactorTests: FIRAuthApiTestsBase { | ||
|
|
||
| func testEnrollUnenroll() { | ||
| let enrollExpectation = self.expectation(description: "Enroll phone multi factor finished.") | ||
| let unenrollExpectation = self.expectation(description: "Unenroll phone multi factor finished.") | ||
| Auth.auth().signIn(withEmail: kNoSecondFactorUserEmail, password: kNoSecondFactorUserPassword) { (result, error) in | ||
renkelvin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| XCTAssertNil(error, "User normal sign in failed. Error: \(error!.localizedDescription)") | ||
|
|
||
| // Enroll | ||
| guard let user = result?.user else { | ||
| XCTFail("No valid user after attempted sign-in.") | ||
| } | ||
| user.multiFactor.getSessionWithCompletion({ (session, error) in | ||
| XCTAssertNil(error, "Get multi factor session failed. Error: \(error!.localizedDescription)") | ||
| PhoneAuthProvider.provider().verifyPhoneNumber( | ||
| kPhoneSecondFactorPhoneNumber, | ||
| uiDelegate: nil, | ||
| multiFactorSession: session) { (verificationId, error) in | ||
| XCTAssertNil(error, "Verify phone number failed. Error: \(error!.localizedDescription)") | ||
| let credential = PhoneAuthProvider.provider().credential( | ||
| withVerificationID: verificationId!, | ||
| verificationCode: kPhoneSecondFactorVerificationCode) | ||
| let assertion = PhoneMultiFactorGenerator.assertion(with: credential); | ||
| user?.multiFactor.enroll(with: assertion, displayName: kPhoneSecondFactorDisplayName) { (error) in | ||
| XCTAssertNil(error, "Phone multi factor enroll failed. Error: \(error!.localizedDescription)") | ||
| XCTAssertEqual(Auth.auth().currentUser?.multiFactor.enrolledFactors.first?.displayName, kPhoneSecondFactorDisplayName) | ||
| enrollExpectation.fulfill() | ||
|
|
||
| // Unenroll | ||
| user = Auth.auth().currentUser | ||
| user?.multiFactor.unenroll(with: (user?.multiFactor.enrolledFactors.first)!, completion: { (error) in | ||
| XCTAssertNil(error, "Phone multi factor unenroll failed. Error: \(error!.localizedDescription)") | ||
| XCTAssertEqual(Auth.auth().currentUser?.multiFactor.enrolledFactors.count, 0) | ||
| unenrollExpectation.fulfill() | ||
| }) | ||
| } | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| self.waitForExpectations(timeout: 30) { error in | ||
| XCTAssertNil(error, "Failed to wait for enroll and unenroll phone multi factor finished. Error: \(error!.localizedDescription)") | ||
| } | ||
| } | ||
|
|
||
| func testSignInWithSecondFactor() { | ||
| let signInExpectation = self.expectation(description: "Sign in with phone multi factor finished.") | ||
| Auth.auth().signIn(withEmail: kOneSecondFactorUserEmail, password: kOneSecondFactorUserPassword) { (result, error) in | ||
| // SignIn | ||
| guard let error = error, error.code == AuthErrorCode.secondFactorRequired.rawValue else { | ||
| XCTFail("User sign in returns wrong error. Error: \(error!.localizedDescription)") | ||
| } | ||
| let resolver = error.userInfo["FIRAuthErrorUserInfoMultiFactorResolverKey"] as! MultiFactorResolver | ||
| let hint = resolver.hints.first as! PhoneMultiFactorInfo | ||
| PhoneAuthProvider.provider().verifyPhoneNumber( | ||
| with: hint, | ||
| uiDelegate: nil, | ||
| multiFactorSession: resolver.session) { (verificationId, error) in | ||
| XCTAssertNil(error, "Failed to verify phone number. Error: \(error!.localizedDescription)") | ||
| let credential = PhoneAuthProvider.provider().credential( | ||
| withVerificationID: verificationId!, | ||
| verificationCode: kPhoneSecondFactorVerificationCode) | ||
| let assertion = PhoneMultiFactorGenerator.assertion(with: credential); | ||
| resolver.resolveSignIn(with: assertion) { (authResult, error) in | ||
| XCTAssertNil(error, "Failed to sign in with phone multi factor. Error: \(error!.localizedDescription)") | ||
| signInExpectation.fulfill() | ||
| } | ||
| } | ||
| } | ||
|
|
||
| self.waitForExpectations(timeout: 300) { error in | ||
| XCTAssertNil(error, "Failed to wait for enroll and unenroll phone multi factor finished. Error: \(error!.localizedDescription)") | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.