|
20 | 20 | #import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDGoogleUser.h" |
21 | 21 | #import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDProfileData.h" |
22 | 22 | #import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDSignInResult.h" |
| 23 | +#import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDVerifiableAccountDetail.h" |
| 24 | +#import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDVerifyAccountDetail.h" |
23 | 25 |
|
24 | 26 | #import "GoogleSignIn/Sources/GIDAuthorizationResponse/GIDAuthorizationResponseHelper.h" |
25 | 27 | #import "GoogleSignIn/Sources/GIDAuthorizationResponse/Implementations/GIDAuthorizationResponseHandler.h" |
26 | 28 |
|
27 | 29 | #import "GoogleSignIn/Sources/GIDAuthFlow.h" |
28 | 30 | #import "GoogleSignIn/Sources/GIDEMMSupport.h" |
| 31 | +#import "GoogleSignIn/Sources/GIDRestrictedScopesRegistry.h" |
29 | 32 | #import "GoogleSignIn/Sources/GIDSignInConstants.h" |
30 | 33 | #import "GoogleSignIn/Sources/GIDSignInInternalOptions.h" |
31 | 34 | #import "GoogleSignIn/Sources/GIDSignInPreferences.h" |
@@ -142,6 +145,8 @@ @implementation GIDSignIn { |
142 | 145 | GIDTimedLoader *_timedLoader; |
143 | 146 | // Flag indicating developer's intent to use App Check. |
144 | 147 | BOOL _configureAppCheckCalled; |
| 148 | + // The class used to manage restricted scopes and their associated handling classes. |
| 149 | + GIDRestrictedScopesRegistry *_registry; |
145 | 150 | #endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST |
146 | 151 | } |
147 | 152 |
|
@@ -256,6 +261,10 @@ - (void)addScopes:(NSArray<NSString *> *)scopes |
256 | 261 | loginHint:self.currentUser.profile.email |
257 | 262 | addScopesFlow:YES |
258 | 263 | completion:completion]; |
| 264 | +#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST |
| 265 | + // Explicitly throw an exception for invalid or restricted scopes in the request. |
| 266 | + [self assertValidScopes:scopes]; |
| 267 | +#endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST |
259 | 268 |
|
260 | 269 | NSSet<NSString *> *requestedScopes = [NSSet setWithArray:scopes]; |
261 | 270 | NSMutableSet<NSString *> *grantedScopes = |
@@ -499,6 +508,7 @@ - (instancetype)initWithKeychainStore:(GTMKeychainStore *)keychainStore { |
499 | 508 | callbackPath:kBrowserCallbackPath |
500 | 509 | keychainName:kGTMAppAuthKeychainName |
501 | 510 | isFreshInstall:isFreshInstall]; |
| 511 | + _registry = [[GIDRestrictedScopesRegistry alloc] init]; |
502 | 512 | #endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST |
503 | 513 | } |
504 | 514 | return self; |
@@ -989,6 +999,27 @@ - (void)assertValidPresentingViewController { |
989 | 999 | } |
990 | 1000 | } |
991 | 1001 |
|
| 1002 | +#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST |
| 1003 | +- (void)assertValidScopes:(NSArray<NSString *> *)scopes { |
| 1004 | + NSDictionary<NSString *, Class> *restrictedScopesMapping = |
| 1005 | + [_registry restrictedScopesToClassMappingInSet:[NSSet setWithArray:scopes]]; |
| 1006 | + |
| 1007 | + if (restrictedScopesMapping.count > 0) { |
| 1008 | + NSMutableString *errorMessage = |
| 1009 | + [NSMutableString stringWithString:@"The following scopes are not supported in the 'addScopes' flow. " |
| 1010 | + "Please use the appropriate classes to handle these:\n"]; |
| 1011 | + [restrictedScopesMapping enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull restrictedScope, |
| 1012 | + Class _Nonnull handlingClass, |
| 1013 | + BOOL * _Nonnull stop) { |
| 1014 | + [errorMessage appendFormat:@"%@ -> %@\n", restrictedScope, NSStringFromClass(handlingClass)]; |
| 1015 | + }]; |
| 1016 | + // NOLINTNEXTLINE(google-objc-avoid-throwing-exception) |
| 1017 | + [NSException raise:NSInvalidArgumentException |
| 1018 | + format:@"%@", errorMessage]; |
| 1019 | + } |
| 1020 | +} |
| 1021 | +#endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST |
| 1022 | + |
992 | 1023 | // Checks whether or not this is the first time the app runs. |
993 | 1024 | - (BOOL)isFreshInstall { |
994 | 1025 | NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; |
|
0 commit comments