GIDSignInPreferences.m 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // Copyright 2021 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/GIDSignInPreferences.h"
  15. NS_ASSUME_NONNULL_BEGIN
  16. static NSString *const kLSOServer = @"accounts.google.com";
  17. static NSString *const kTokenServer = @"oauth2.googleapis.com";
  18. static NSString *const kUserInfoServer = @"www.googleapis.com";
  19. // The name of the query parameter used for logging the SDK version.
  20. NSString *const kSDKVersionLoggingParameter = @"gpsdk";
  21. // The name of the query parameter used for logging the Apple execution environment.
  22. NSString *const kEnvironmentLoggingParameter = @"gidenv";
  23. // Supported Apple execution environments
  24. static NSString *const kAppleEnvironmentUnknown = @"unknown";
  25. static NSString *const kAppleEnvironmentIOS = @"ios";
  26. static NSString *const kAppleEnvironmentIOSSimulator = @"ios-sim";
  27. static NSString *const kAppleEnvironmentMacOS = @"macos";
  28. static NSString *const kAppleEnvironmentMacOSIOSOnMac = @"macos-ios";
  29. static NSString *const kAppleEnvironmentMacOSMacCatalyst = @"macos-cat";
  30. #ifndef GID_SDK_VERSION
  31. #error "GID_SDK_VERSION is not defined: add -DGID_SDK_VERSION=x.x.x to the build invocation."
  32. #endif
  33. // Because macro expansions aren't performed on a token following the # preprocessor operator, we
  34. // wrap STR_EXPAND(x) with the STR(x) to produce a quoted string representation of a macro.
  35. // https://www.guyrutenberg.com/2008/12/20/expanding-macros-into-string-constants-in-c/
  36. #define STR(x) STR_EXPAND(x)
  37. #define STR_EXPAND(x) #x
  38. // The prefixed sdk version string to differentiate gid version values used with the legacy gpsdk
  39. // logging key.
  40. NSString* GIDVersion(void) {
  41. return [NSString stringWithFormat:@"gid-%@", @STR(GID_SDK_VERSION)];
  42. }
  43. // Get the current Apple execution environment.
  44. NSString* GIDEnvironment(void) {
  45. NSString *appleEnvironment = kAppleEnvironmentUnknown;
  46. #if TARGET_OS_MACCATALYST
  47. appleEnvironment = kAppleEnvironmentMacOSMacCatalyst;
  48. #elif TARGET_OS_IOS
  49. #if TARGET_OS_SIMULATOR
  50. appleEnvironment = kAppleEnvironmentIOSSimulator;
  51. #else // TARGET_OS_SIMULATOR
  52. #if defined(__IPHONE_14_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_14_0
  53. if (@available(iOS 14.0, *)) {
  54. if ([NSProcessInfo.processInfo respondsToSelector:@selector(isiOSAppOnMac)]) {
  55. appleEnvironment = NSProcessInfo.processInfo.iOSAppOnMac ? kAppleEnvironmentMacOSIOSOnMac :
  56. kAppleEnvironmentIOS;
  57. } else {
  58. appleEnvironment = kAppleEnvironmentIOS;
  59. }
  60. }
  61. #else // defined(__IPHONE_14_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_14_0
  62. appleEnvironment = kAppleEnvironmentIOS;
  63. #endif // defined(__IPHONE_14_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_14_0
  64. #endif // TARGET_OS_SIMULATOR
  65. #elif TARGET_OS_OSX
  66. appleEnvironment = kAppleEnvironmentMacOS;
  67. #endif // TARGET_OS_MACCATALYST
  68. return appleEnvironment;
  69. }
  70. @implementation GIDSignInPreferences
  71. + (NSString *)googleAuthorizationServer {
  72. return kLSOServer;
  73. }
  74. + (NSString *)googleTokenServer {
  75. return kTokenServer;
  76. }
  77. + (NSString *)googleUserInfoServer {
  78. return kUserInfoServer;
  79. }
  80. @end
  81. NS_ASSUME_NONNULL_END