Repository navigation
[VwG] Add verification flow example to DaysUntilBirthday Sample App. #452
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
brnnmrls
merged 9 commits into
briannamorales/vwg-flow
from
briannamorales/verifyFlowExample
Jul 16, 2024
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
73ee9c8
Add verification flow to sample app.
brnnmrls 367437d
Fix indentation and remove development_team from project.pbxproj.
brnnmrls edcf985
Create `VerifiedAgeViewModel` to load and hold verification state.
brnnmrls b8696c1
Add back in PRODUCT_BUNDLE_IDENTIFIER.
brnnmrls b27c703
Revert spacing in AuthenticationViewModel
brnnmrls dd53e54
Fix swift integration test by adding Verify Flow files to DaysUntilBi…
brnnmrls d70d8a7
Fix doc comments and make a loader when necessary using `lazy var`.
brnnmrls 2b8047f
Request knowledge of user's verified age on button click each time an…
brnnmrls aef9ff7
Update method names + doc comments to indicate we verify the user's a…
brnnmrls 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
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
58 changes: 58 additions & 0 deletions
58
Samples/Swift/DaysUntilBirthday/Shared/Services/VerificationLoader.swift
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,58 @@ | ||
| /* | ||
| * Copyright 2024 Google LLC | ||
| * | ||
| * 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 Foundation | ||
| import GoogleSignIn | ||
|
|
||
| #if os(iOS) | ||
|
|
||
| /// An observable class for verifying via Google. | ||
| final class VerificationLoader: ObservableObject { | ||
| private var verifiedAgeViewModel: VerifiedAgeViewModel | ||
|
|
||
| /// Creates an instance of this loader. | ||
| /// - parameter verifiedAgeViewModel: The view model to use to set verification status on. | ||
| init(verifiedViewAgeModel: VerifiedAgeViewModel) { | ||
| self.verifiedAgeViewModel = verifiedViewAgeModel | ||
| } | ||
|
|
||
| /// Verifies the user's age is over 18 based upon the selected account. | ||
| /// - note: Successful calls to this method will set the `verificationState` property of the | ||
| /// `verifiedAgeViewModel` instance passed to the initializer. | ||
| func verifyUserAgeOver18() { | ||
| let accountDetails: [GIDVerifiableAccountDetail] = [ | ||
| GIDVerifiableAccountDetail(accountDetailType: .ageOver18) | ||
| ] | ||
|
|
||
| guard let rootViewController = UIApplication.shared.windows.first?.rootViewController else { | ||
| print("There is no root view controller!") | ||
| return | ||
| } | ||
|
|
||
| let verifyAccountDetail = GIDVerifyAccountDetail() | ||
| verifyAccountDetail.verifyAccountDetails(accountDetails, presenting: rootViewController) { | ||
| verifyResult, error in | ||
| guard let verifyResult else { | ||
| self.verifiedAgeViewModel.verificationState = .unverified | ||
| print("Error! \(String(describing: error))") | ||
| return | ||
| } | ||
| self.verifiedAgeViewModel.verificationState = .verified(verifyResult) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #endif |
53 changes: 53 additions & 0 deletions
53
Samples/Swift/DaysUntilBirthday/Shared/ViewModels/VerifiedAgeViewModel.swift
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,53 @@ | ||
| /* | ||
| * Copyright 2024 Google LLC | ||
| * | ||
| * 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 SwiftUI | ||
| import GoogleSignIn | ||
|
|
||
| #if os(iOS) | ||
|
|
||
| /// A class conforming to `ObservableObject` used to represent a user's verification status. | ||
| final class VerifiedAgeViewModel: ObservableObject { | ||
| /// The user's account verification status. | ||
| /// - note: This will publish updates when its value changes. | ||
| @Published var verificationState: VerificationState | ||
|
|
||
| private lazy var loader: VerificationLoader = { | ||
| return VerificationLoader(verifiedViewAgeModel: self) | ||
| }() | ||
|
|
||
| /// Creates an instance of this view model. | ||
| init() { | ||
| self.verificationState = .unverified | ||
| } | ||
|
|
||
| /// Verifies the user's age is over 18. | ||
| func verifyUserAgeOver18() { | ||
| loader.verifyUserAgeOver18() | ||
| } | ||
| } | ||
|
|
||
| extension VerifiedAgeViewModel { | ||
| /// An enumeration representing verified status. | ||
| enum VerificationState { | ||
| /// The user's account is verified and is the associated value of this case. | ||
| case verified(GIDVerifiedAccountDetailResult) | ||
| /// The user's account is not verified. | ||
| case unverified | ||
| } | ||
| } | ||
|
|
||
| #endif | ||
62 changes: 62 additions & 0 deletions
62
Samples/Swift/DaysUntilBirthday/Shared/Views/VerificationView.swift
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,62 @@ | ||
| /* | ||
| * Copyright 2024 Google LLC | ||
| * | ||
| * 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 SwiftUI | ||
| import GoogleSignIn | ||
|
|
||
| struct VerificationView: View { | ||
| @ObservedObject var verifiedAgeViewModel: VerifiedAgeViewModel | ||
|
|
||
| var body: some View { | ||
| switch verifiedAgeViewModel.verificationState { | ||
| case .verified(let result): | ||
| VStack(alignment:.leading) { | ||
| Text("List of result object properties:") | ||
| .font(.headline) | ||
|
|
||
| HStack(alignment: .top) { | ||
| Text("Access Token:") | ||
| Text(result.accessTokenString ?? "Not available") | ||
| } | ||
| HStack(alignment: .top) { | ||
| Text("Refresh Token:") | ||
| Text(result.refreshTokenString ?? "Not available") | ||
| } | ||
| HStack { | ||
| Text("Expiration:") | ||
| if let expirationDate = result.expirationDate { | ||
| Text(formatDateWithDateFormatter(expirationDate)) | ||
| } else { | ||
| Text("Not available") | ||
| } | ||
| } | ||
| Spacer() | ||
| } | ||
| .navigationTitle("Verified Account!") | ||
| case .unverified: | ||
| ProgressView() | ||
| .navigationTitle(NSLocalizedString("Unverified account", | ||
| comment: "Unverified account label")) | ||
| } | ||
| } | ||
|
|
||
| func formatDateWithDateFormatter(_ date: Date) -> String { | ||
| let dateFormatter = DateFormatter() | ||
| dateFormatter.dateStyle = .medium | ||
| dateFormatter.timeStyle = .short | ||
| return dateFormatter.string(from: date) | ||
| } | ||
| } |
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
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.