Skip to content

Commit f4dedcf

Browse files
authored
Remove requirement of a current user in the VwG flow. (#512)
1 parent 61d3c78 commit f4dedcf

File tree

4 files changed

+152
-23
lines changed

4 files changed

+152
-23
lines changed

GoogleSignIn/Sources/GIDVerifyAccountDetail/Implementations/GIDVerifyAccountDetail.m

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,6 @@ - (void)verifyAccountDetailsInteractivelyWithOptions:(GIDSignInInternalOptions *
149149
return;
150150
}
151151

152-
[self assertValidCurrentUser];
153-
154152
// Explicitly throw exception for missing client ID here. This must come before
155153
// scheme check because schemes rely on reverse client IDs.
156154
[self assertValidParameters:options];
@@ -231,15 +229,6 @@ - (void)processAuthorizationResponse:(OIDAuthorizationResponse *)authorizationRe
231229

232230
#pragma mark - Helpers
233231

234-
// Assert that a current user exists.
235-
- (void)assertValidCurrentUser {
236-
if (!GIDSignIn.sharedInstance.currentUser) {
237-
// NOLINTNEXTLINE(google-objc-avoid-throwing-exception)
238-
[NSException raise:NSInvalidArgumentException
239-
format:@"|currentUser| must be set to verify."];
240-
}
241-
}
242-
243232
// Asserts the parameters being valid.
244233
- (void)assertValidParameters:(GIDSignInInternalOptions *)options {
245234
if (![options.configuration.clientID length]) {

Samples/Swift/DaysUntilBirthday/DaysUntilBirthdayUITests(iOS)/DaysUntilBirthdayUITests_iOS.swift

Lines changed: 116 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ class DaysUntilBirthdayUITests_iOS: XCTestCase {
2323
"Would you like to save this password to use with apps and websites?"
2424
private let signInDisclaimerHeaderText =
2525
"Sign in to Days Until Birthday"
26+
private let accessHeaderText = "Days Until Birthday wants access to your Google Account"
2627
private let additionalAccessHeaderText = "Days Until Birthday wants additional access to your Google Account"
2728
private let appTrustWarningText = "Make sure you trust Days Until Birthday"
2829
private let chooseAnAccountHeaderText = "Choose an account"
30+
private let consentRequestHeaderText = "Share some info with Days Until Birthday"
2931
private let notNowText = "Not Now"
3032
private let timeout: TimeInterval = 30
3133

@@ -68,6 +70,27 @@ class DaysUntilBirthdayUITests_iOS: XCTestCase {
6870
return XCTFail("Signing out should return user to sign in view")
6971
}
7072
}
73+
74+
func testFetchVerificationSignalAndDisconnect() {
75+
sampleApp.launch()
76+
77+
XCTAssertTrue(navigateToVerifyMyAge())
78+
XCTAssertTrue(displayVerificationSignal())
79+
80+
guard sampleApp
81+
.navigationBars
82+
.buttons["Sign-in with Google"]
83+
.waitForExistence(timeout: timeout) else {
84+
return XCTFail("Failed to show navigation button back to Sign In View")
85+
}
86+
sampleApp.navigationBars.buttons["Sign-in with Google"].tap()
87+
88+
guard sampleApp
89+
.buttons["GoogleSignInButton"]
90+
.waitForExistence(timeout: timeout) else {
91+
return XCTFail("Failed to return user to sign in view")
92+
}
93+
}
7194
}
7295

7396
extension DaysUntilBirthdayUITests_iOS {
@@ -262,10 +285,90 @@ extension DaysUntilBirthdayUITests_iOS {
262285
return true
263286
}
264287

288+
/// Navigates to the verification view from the user profile view.
289+
/// - returns: `true` if the navigation was performed successfully.
290+
/// - note: This method will attempt to find a pop up asking for permission to
291+
/// sign in with Google.
292+
func navigateToVerifyMyAge() -> Bool {
293+
guard sampleApp.buttons["Verify"]
294+
.waitForExistence(timeout: timeout) else {
295+
XCTFail("Failed to find button navigating to verify my age view")
296+
return false
297+
}
298+
sampleApp.buttons["Verify"].tap()
299+
300+
if springboardApp
301+
.staticTexts[signInStaticText]
302+
.waitForExistence(timeout: timeout) {
303+
guard springboardApp
304+
.buttons["Continue"]
305+
.waitForExistence(timeout: timeout) else {
306+
XCTFail("Failed to find 'Continue' button")
307+
return false
308+
}
309+
springboardApp.buttons["Continue"].tap()
310+
311+
if sampleApp
312+
.staticTexts[Credential.email.rawValue]
313+
.waitForExistence(timeout: timeout) {
314+
XCTAssertTrue(useExistingSignIn())
315+
} else {
316+
XCTAssertTrue(signInForTheFirstTime())
317+
}
318+
319+
handleConsentRequestIfNeeded()
320+
}
321+
322+
guard sampleApp.staticTexts["Verified Account!"]
323+
.waitForExistence(timeout: timeout) else {
324+
XCTFail("Failed to show age verification view")
325+
return false
326+
}
327+
328+
guard sampleApp.staticTexts["Access Token:"]
329+
.waitForExistence(timeout: timeout) else {
330+
XCTFail("Access Token element did not appear")
331+
return false
332+
}
333+
334+
return true
335+
}
336+
337+
/// Displays a sheet over the Verification view with the fetched verification signal..
338+
/// - returns: `true` if the display was performed successfully.
339+
func displayVerificationSignal() -> Bool {
340+
guard sampleApp.buttons["Fetch Age Verification Signal"]
341+
.waitForExistence(timeout: timeout) else {
342+
XCTFail("Failed to find button to refresh access token")
343+
return false
344+
}
345+
sampleApp.buttons["Fetch Age Verification Signal"].tap()
346+
347+
guard sampleApp.staticTexts["User is verified over 18!"]
348+
.waitForExistence(timeout: timeout) else {
349+
XCTFail("Failed to show age verification signal view")
350+
return false
351+
}
352+
353+
guard sampleApp
354+
.navigationBars
355+
.buttons["Close"]
356+
.waitForExistence(timeout: timeout) else {
357+
XCTFail("Failed to show close button back to age signal view")
358+
return false
359+
}
360+
sampleApp.navigationBars.buttons["Close"].tap()
361+
362+
return true
363+
}
364+
265365
/// Proceeds through the view with header "Days Until Birthday wants additional access to your Google Account" if needed.
266366
func handleAccessRequestIfNeeded() {
267-
let currentlyShowingAdditionalAccessRequest = sampleApp.staticTexts[additionalAccessHeaderText]
268-
.waitForExistence(timeout: timeout) && sampleApp.staticTexts[appTrustWarningText]
367+
let currentlyShowingAdditionalAccessHeaderText =
368+
sampleApp.staticTexts[additionalAccessHeaderText].waitForExistence(timeout: timeout) ||
369+
sampleApp.staticTexts[accessHeaderText].waitForExistence(timeout: timeout)
370+
let currentlyShowingAdditionalAccessRequest =
371+
currentlyShowingAdditionalAccessHeaderText && sampleApp.staticTexts[appTrustWarningText]
269372
.waitForExistence(timeout: timeout) &&
270373
sampleApp.buttons["Continue"]
271374
.waitForExistence(timeout: timeout)
@@ -275,6 +378,17 @@ extension DaysUntilBirthdayUITests_iOS {
275378
}
276379
}
277380

381+
/// Proceeds through the view with header "Share some info with Days Until Birthday" if needed.
382+
func handleConsentRequestIfNeeded() {
383+
let currentlyShowingConsentRequest =
384+
sampleApp.staticTexts[consentRequestHeaderText].waitForExistence(timeout: timeout)
385+
&& sampleApp.buttons["Agree"].waitForExistence(timeout: timeout)
386+
387+
if currentlyShowingConsentRequest {
388+
sampleApp.buttons["Agree"].tap()
389+
}
390+
}
391+
278392
/// Proceeds through the sign-in disclaimer view if needed.
279393
func handleSignInDisclaimerIfNeeded() {
280394
let currentlyShowingSignInDisclaimer = sampleApp.staticTexts[signInDisclaimerHeaderText]

Samples/Swift/DaysUntilBirthday/Shared/Views/SignInView.swift

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ import GoogleSignInSwift
1919

2020
struct SignInView: View {
2121
@EnvironmentObject var authViewModel: AuthenticationViewModel
22+
#if os(iOS)
23+
@State var verificationflowInitiated = false
24+
@StateObject var verifiedAgeViewModel = VerifiedAgeViewModel()
25+
#endif
2226
@ObservedObject var vm = GoogleSignInButtonViewModel()
2327

2428
var body: some View {
@@ -69,6 +73,38 @@ struct SignInView: View {
6973
#endif
7074
}
7175
}
76+
HStack {
77+
VStack {
78+
#if os(iOS)
79+
Text("Verify your Age")
80+
.font(.title)
81+
.fontWeight(.semibold)
82+
.frame(maxWidth: .infinity, alignment: .leading)
83+
.padding()
84+
Button(action: {
85+
verifiedAgeViewModel.verifyUserAgeOver18()
86+
verificationflowInitiated = true
87+
}) {
88+
Text("Verify")
89+
.font(.headline)
90+
.foregroundColor(.gray)
91+
.padding()
92+
.frame(maxWidth: .infinity, alignment: .leading)
93+
.background(Color.white)
94+
.overlay(
95+
RoundedRectangle(cornerRadius: 2)
96+
.stroke(Color.gray.opacity(0.3), lineWidth: 1))
97+
.shadow(color: Color.black.opacity(0.1), radius: 3, x: 0, y: 2)
98+
}
99+
.padding(.horizontal)
100+
NavigationLink(isActive: $verificationflowInitiated) {
101+
VerificationView(verifiedAgeViewModel: verifiedAgeViewModel)
102+
} label: {
103+
EmptyView()
104+
}
105+
#endif
106+
}
107+
}
72108
Spacer()
73109
}
74110
}

Samples/Swift/DaysUntilBirthday/iOS/UserProfileView.swift

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ import GoogleSignIn
1919

2020
struct UserProfileView: View {
2121
@EnvironmentObject var authViewModel: AuthenticationViewModel
22-
#if os(iOS)
23-
@StateObject var verifiedAgeViewModel = VerifiedAgeViewModel()
24-
#endif
2522
@StateObject var birthdayViewModel = BirthdayViewModel()
2623
private var user: GIDGoogleUser? {
2724
return GIDSignIn.sharedInstance.currentUser
@@ -53,13 +50,6 @@ struct UserProfileView: View {
5350
return
5451
}
5552
})
56-
#if os(iOS)
57-
NavigationLink(NSLocalizedString("Verify My Age", comment: "Verify Age"),
58-
destination: VerificationView(verifiedAgeViewModel: verifiedAgeViewModel)
59-
.onAppear {
60-
verifiedAgeViewModel.verifyUserAgeOver18()
61-
})
62-
#endif
6353
Spacer()
6454
}
6555
.toolbar {

0 commit comments

Comments
 (0)