瀏覽代碼

Merge branch 'briannamorales/vwg-flow' of https://github.com/google/GoogleSignIn-iOS into briannamorales/vwg-flow

brianna 2 年之前
父節點
當前提交
9a2d6b3f7c

+ 3 - 2
.gitignore

@@ -17,5 +17,6 @@ Pods/
 gen/
 Podfile.lock
 
-# Swift build
-.build/
+# Swift Build
+.build/
+Package.resolved

+ 40 - 0
GoogleSignIn/Sources/GIDVerifyAccountDetail/Implementations/GIDVerifiableAccountDetail.m

@@ -0,0 +1,40 @@
+/*
+ * 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 "GoogleSignIn/Sources/Public/GoogleSignIn/GIDVerifiableAccountDetail.h"
+
+NSString *const kAccountDetailTypeAgeOver18Scope = @"https://www.googleapis.com/auth/verified.age.over18.standard";
+
+@implementation GIDVerifiableAccountDetail
+
+- (instancetype)initWithAccountDetailType:(GIDAccountDetailType)accountDetailType {
+  self = [super init];
+  if (self) {
+    _accountDetailType = accountDetailType;
+  }
+  return self;
+}
+
+- (nullable NSString *)scope {
+  switch (self.accountDetailType) {
+    case GIDAccountDetailTypeAgeOver18:
+      return kAccountDetailTypeAgeOver18Scope;
+    default:
+      return nil;
+  }
+}
+
+@end

+ 20 - 0
GoogleSignIn/Sources/GIDVerifyAccountDetail/Implementations/GIDVerifiedAccountDetailResult.m

@@ -0,0 +1,20 @@
+/*
+ * 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 "GoogleSignIn/Sources/Public/GoogleSignIn/GIDVerifiedAccountDetailResult.h"
+
+@implementation GIDVerifiedAccountDetailResult
+@end

+ 52 - 0
GoogleSignIn/Sources/GIDVerifyAccountDetail/Implementations/GIDVerifyAccountDetail.m

@@ -0,0 +1,52 @@
+/*
+ * 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 "GoogleSignIn/Sources/Public/GoogleSignIn/GIDVerifyAccountDetail.h"
+
+#import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDVerifiableAccountDetail.h"
+#import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDVerifiedAccountDetailResult.h"
+
+@implementation GIDVerifyAccountDetail
+
+#if TARGET_OS_IOS || TARGET_OS_MACCATALYST
+
+- (void)verifyAccountDetails:(NSArray<GIDVerifiableAccountDetail *> *)accountDetails
+    presentingViewController:(UIViewController *)presentingViewController
+                  completion:(nullable void (^)(GIDVerifiedAccountDetailResult *_Nullable verifyResult,
+                                                NSError *_Nullable error))completion {
+    // TODO(#383): Implement this method.
+}
+
+- (void)verifyAccountDetails:(NSArray<GIDVerifiableAccountDetail *> *)accountDetails
+    presentingViewController:(UIViewController *)presentingViewController
+                        hint:(nullable NSString *)hint
+                  completion:(nullable void (^)(GIDVerifiedAccountDetailResult *_Nullable verifyResult,
+                                                NSError *_Nullable error))completion {
+    // TODO(#383): Implement this method.
+}
+
+- (void)verifyAccountDetails:(NSArray<GIDVerifiableAccountDetail *> *)accountDetails
+    presentingViewController:(UIViewController *)presentingViewController
+                        hint:(nullable NSString *)hint
+            additionalScopes:(nullable NSArray<NSString *> *)additionalScopes
+                  completion:(nullable void (^)(GIDVerifiedAccountDetailResult *_Nullable verifyResult,
+                                                NSError *_Nullable error))completion {
+    // TODO(#383): Implement this method.
+}
+
+#endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST
+
+@end

+ 50 - 0
GoogleSignIn/Sources/Public/GoogleSignIn/GIDVerifiableAccountDetail.h

@@ -0,0 +1,50 @@
+/*
+ * 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/Foundation.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+/// An enumeration defining the types of account details Google can verify.
+typedef NS_ENUM(NSInteger, GIDAccountDetailType) {
+  /// User account detail for age over 18.
+  GIDAccountDetailTypeAgeOver18,
+};
+
+/// String scope representing the account detail type for age over 18.
+extern NSString *const kAccountDetailTypeAgeOver18Scope;
+
+/// Helper object used to hold the enumeration representing a list of
+/// account details that Google can verify via GSI.
+@interface GIDVerifiableAccountDetail : NSObject
+
+/// The type of account detail that will be verified.
+@property(nonatomic, readonly) GIDAccountDetailType accountDetailType;
+
+/// Initializes a new GIDVerifiableAccountDetail object with the given
+/// account detail type.
+///
+/// @param accountDetailType The type of account detail that will be verified.
+- (instancetype)initWithAccountDetailType:(GIDAccountDetailType)accountDetailType;
+
+/// Retrieves the scope required to verify the account detail.
+///
+/// @return A string representing the scope required to verify the account detail.
+- (nullable NSString *)scope;
+
+@end
+
+NS_ASSUME_NONNULL_END

+ 22 - 0
GoogleSignIn/Sources/Public/GoogleSignIn/GIDVerifiedAccountDetailResult.h

@@ -0,0 +1,22 @@
+/*
+ * 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/Foundation.h>
+
+/// A helper object that contains the result of a verification flow.
+/// This will pass back the necessary tokens to the requesting party.
+@interface GIDVerifiedAccountDetailResult : NSObject
+@end

+ 92 - 0
GoogleSignIn/Sources/Public/GoogleSignIn/GIDVerifyAccountDetail.h

@@ -0,0 +1,92 @@
+/*
+ * 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/Foundation.h>
+#import <TargetConditionals.h>
+
+#if __has_include(<UIKit/UIKit.h>)
+#import <UIKit/UIKit.h>
+#elif __has_include(<AppKit/AppKit.h>)
+#import <AppKit/AppKit.h>
+#endif
+
+@class GIDVerifiableAccountDetail;
+@class GIDVerifiedAccountDetailResult;
+
+NS_ASSUME_NONNULL_BEGIN
+
+/// This class is used to verify a user's Google account details.
+@interface GIDVerifyAccountDetail : NSObject
+
+#if TARGET_OS_IOS || TARGET_OS_MACCATALYST
+
+/// Starts an interactive verification flow.
+///
+/// The completion will be called at the end of this process.  Any saved verification
+/// state will be replaced by the result of this flow.
+///
+/// @param accountDetails A list of verifiable account details.
+/// @param presentingViewController The view controller used to present `SFSafariViewController` on
+///     iOS 9 and 10 and to supply `presentationContextProvider` for `ASWebAuthenticationSession` on
+///     iOS 13+.
+/// @param completion The optional block called asynchronously on the main queue upon completion.
+- (void)verifyAccountDetails:(NSArray<GIDVerifiableAccountDetail *> *)accountDetails 
+    presentingViewController:(UIViewController *)presentingViewController 
+                  completion:(nullable void (^)(GIDVerifiedAccountDetailResult *_Nullable verifyResult, 
+                                                NSError *_Nullable error))completion;
+
+/// Starts an interactive verification flow using the provided hint.
+///
+/// The completion will be called at the end of this process.  Any saved verification
+/// state will be replaced by the result of this flow.
+///
+/// @param accountDetails A list of verifiable account details.
+/// @param presentingViewController The view controller used to present `SFSafariViewController` on
+///     iOS 9 and 10 and to supply `presentationContextProvider` for `ASWebAuthenticationSession` on
+///     iOS 13+.
+/// @param hint An optional hint for the authorization server, for example the user's ID or email
+///     address, to be prefilled if possible.
+/// @param completion The optional block called asynchronously on the main queue upon completion.
+- (void)verifyAccountDetails:(NSArray<GIDVerifiableAccountDetail *> *)accountDetails 
+    presentingViewController:(UIViewController *)presentingViewController 
+                        hint:(nullable NSString *)hint
+                  completion:(nullable void (^)(GIDVerifiedAccountDetailResult *_Nullable verifyResult, 
+                                                NSError *_Nullable error))completion;
+
+/// Starts an interactive verification flow using the provided hint and additional scopes.
+///
+/// The completion will be called at the end of this process.  Any saved verification
+/// state will be replaced by the result of this flow.
+///
+/// @param accountDetails A list of verifiable account details.
+/// @param presentingViewController The view controller used to present `SFSafariViewController` on
+///     iOS 9 and 10.
+/// @param hint An optional hint for the authorization server, for example the user's ID or email
+///     address, to be prefilled if possible.
+/// @param additionalScopes An optional array of scopes to request in addition to the basic profile scopes.
+/// @param completion The optional block called asynchronously on the main queue upon completion.
+- (void)verifyAccountDetails:(NSArray<GIDVerifiableAccountDetail *> *)accountDetails 
+    presentingViewController:(UIViewController *)presentingViewController 
+                        hint:(nullable NSString *)hint
+            additionalScopes:(nullable NSArray<NSString *> *)additionalScopes
+                  completion:(nullable void (^)(GIDVerifiedAccountDetailResult *_Nullable verifyResult, 
+                                                NSError *_Nullable error))completion;
+
+#endif
+
+@end
+
+NS_ASSUME_NONNULL_END

+ 3 - 0
GoogleSignIn/Sources/Public/GoogleSignIn/GoogleSignIn.h

@@ -21,6 +21,9 @@
 #import "GIDSignIn.h"
 #import "GIDToken.h"
 #import "GIDSignInResult.h"
+#import "GIDVerifyAccountDetail.h"
+#import "GIDVerifiableAccountDetail.h"
+#import "GIDVerifiedAccountDetailResult.h"
 #if TARGET_OS_IOS || TARGET_OS_MACCATALYST
 #import "GIDSignInButton.h"
 #endif

+ 29 - 0
GoogleSignIn/Tests/Unit/GIDVerifiableAccountDetailTest.m

@@ -0,0 +1,29 @@
+#import <XCTest/XCTest.h>
+
+#import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDVerifiableAccountDetail.h"
+
+@interface GIDVerifiableAccountDetailTests : XCTestCase
+@end
+
+@implementation GIDVerifiableAccountDetailTests
+
+- (void)testDesignatedInitializer {
+  GIDVerifiableAccountDetail *detail = [[GIDVerifiableAccountDetail alloc] initWithAccountDetailType:GIDAccountDetailTypeAgeOver18];
+  XCTAssertNotNil(detail);
+  XCTAssertEqual(detail.accountDetailType, GIDAccountDetailTypeAgeOver18);
+}
+
+- (void)testScopeRetrieval {
+  GIDVerifiableAccountDetail *detail = [[GIDVerifiableAccountDetail alloc] initWithAccountDetailType:GIDAccountDetailTypeAgeOver18];
+  NSString *retrievedScope = [detail scope];
+  XCTAssertEqualObjects(retrievedScope, kAccountDetailTypeAgeOver18Scope);
+}
+
+- (void)testScopeRetrieval_MissingScope {
+  NSInteger missingScope = 5;
+  GIDVerifiableAccountDetail *detail = [[GIDVerifiableAccountDetail alloc] initWithAccountDetailType:missingScope];
+  NSString *retrievedScope = [detail scope];
+  XCTAssertNil(retrievedScope);
+}
+
+@end