FIRURLSchemeUtil.m 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2017 Google
  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 "Private/FIRURLSchemeUtil.h"
  15. #import "Private/FIRLogger.h"
  16. /**
  17. * Regular expression to match the URL scheme for Google sign-in.
  18. */
  19. static NSString *const kFIRGoogleSignInURLSchemePattern =
  20. @"^com\\.googleusercontent\\.apps\\.\\d+-\\w+$";
  21. BOOL fir_areURLSchemesValidForGoogleSignIn(NSArray *urlSchemes) {
  22. BOOL hasReversedClientID = NO;
  23. for (NSString *urlScheme in urlSchemes) {
  24. if (!hasReversedClientID) {
  25. NSRange range = [urlScheme rangeOfString:kFIRGoogleSignInURLSchemePattern
  26. options:NSRegularExpressionSearch];
  27. if (range.location != NSNotFound) {
  28. hasReversedClientID = YES;
  29. }
  30. }
  31. }
  32. if (hasReversedClientID) {
  33. return YES;
  34. }
  35. if (!hasReversedClientID) {
  36. FIRLogInfo(kFIRLoggerCore, @"I-COR000021",
  37. @"A reversed client ID should be added as a URL "
  38. @"scheme to enable Google sign-in.");
  39. }
  40. return NO;
  41. }