GIDRestrictedScopesRegistry.m 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright 2024 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #import "GoogleSignIn/Sources/GIDRestrictedScopesRegistry.h"
  15. #import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDVerifiableAccountDetail.h"
  16. #import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDVerifyAccountDetail.h"
  17. #if TARGET_OS_IOS && !TARGET_OS_MACCATALYST
  18. @implementation GIDRestrictedScopesRegistry
  19. - (instancetype)init {
  20. self = [super init];
  21. if (self) {
  22. _restrictedScopes = [NSSet setWithObjects:kAccountDetailTypeAgeOver18Scope, nil];
  23. _scopeToClassMapping = @{
  24. kAccountDetailTypeAgeOver18Scope: [GIDVerifyAccountDetail class],
  25. };
  26. }
  27. return self;
  28. }
  29. - (BOOL)isScopeRestricted:(NSString *)scope {
  30. return [self.restrictedScopes containsObject:scope];
  31. }
  32. - (NSDictionary<NSString *, Class> *)restrictedScopesToClassMappingInSet:(NSSet<NSString *> *)scopes {
  33. NSMutableDictionary<NSString *, Class> *mapping = [NSMutableDictionary dictionary];
  34. for (NSString *scope in scopes) {
  35. if ([self isScopeRestricted:scope]) {
  36. Class handlingClass = self.scopeToClassMapping[scope];
  37. mapping[scope] = handlingClass;
  38. }
  39. }
  40. return [mapping copy];
  41. }
  42. @end
  43. #endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST