GIDKeychainHandler.m 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #import "GoogleSignIn/Sources/GIDKeychainHandler/Implementations/GIDKeychainHandler.h"
  2. #ifdef SWIFT_PACKAGE
  3. @import AppAuth;
  4. @import GTMAppAuth;
  5. #else
  6. #import <AppAuth/AppAuth.h>
  7. #import <GTMAppAuth/GTMAppAuth.h>
  8. #endif
  9. static NSString *const kGTMAppAuthKeychainName = @"auth";
  10. NS_ASSUME_NONNULL_BEGIN
  11. @implementation GIDKeychainHandler
  12. - (nullable OIDAuthState *)loadAuthState {
  13. GTMAppAuthFetcherAuthorization *authorization =
  14. [GTMAppAuthFetcherAuthorization authorizationFromKeychainForName:kGTMAppAuthKeychainName
  15. useDataProtectionKeychain:YES];
  16. return authorization.authState;
  17. }
  18. - (BOOL)saveAuthState:(OIDAuthState *)authState {
  19. GTMAppAuthFetcherAuthorization *authorization =
  20. [[GTMAppAuthFetcherAuthorization alloc] initWithAuthState:authState];
  21. return [GTMAppAuthFetcherAuthorization saveAuthorization:authorization
  22. toKeychainForName:kGTMAppAuthKeychainName
  23. useDataProtectionKeychain:YES];
  24. }
  25. - (void)removeAllKeychainEntries {
  26. [GTMAppAuthFetcherAuthorization removeAuthorizationFromKeychainForName:kGTMAppAuthKeychainName
  27. useDataProtectionKeychain:YES];
  28. }
  29. @end
  30. NS_ASSUME_NONNULL_END