Explorar o código

Add GIDKeychainHandler implementation

pinlu %!s(int64=3) %!d(string=hai) anos
pai
achega
efbc2e3b46

+ 25 - 0
GoogleSignIn/Sources/GIDKeychainHandlling/GIDKeychainHandler.h

@@ -1 +1,26 @@
+/*
+ * Copyright 2022 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 
+#import <Foundation/Foundation.h>
+
+#import "GoogleSignIn/Sources/GIDKeychainHandlling/GIDKeychainHandlling.h"
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface GIDKeychainHandler : NSObject<GIDKeychainHandlling>
+@end
+
+NS_ASSUME_NONNULL_END

+ 40 - 0
GoogleSignIn/Sources/GIDKeychainHandlling/GIDKeychainHandler.m

@@ -1 +1,41 @@
+#import "GoogleSignIn/Sources/GIDKeychainHandlling/GIDKeychainHandler.h"
 
+#ifdef SWIFT_PACKAGE
+@import AppAuth;
+@import GTMAppAuth;
+#else
+#import <AppAuth/AppAuth.h>
+#import <GTMAppAuth/GTMAppAuth.h>
+#endif
+
+// Keychain constants for saving state in the authentication flow.
+static NSString *const kGTMAppAuthKeychainName = @"auth";
+
+NS_ASSUME_NONNULL_BEGIN
+
+@implementation GIDKeychainHandler
+
+
+- (OIDAuthState *)loadAuthState {
+  GTMAppAuthFetcherAuthorization *authorization =
+      [GTMAppAuthFetcherAuthorization authorizationFromKeychainForName:kGTMAppAuthKeychainName
+                                             useDataProtectionKeychain:YES];
+  return authorization.authState;
+}
+
+- (BOOL)saveAuthState:(OIDAuthState *)authState {
+  GTMAppAuthFetcherAuthorization *authorization =
+      [[GTMAppAuthFetcherAuthorization alloc] initWithAuthState:authState];
+  return [GTMAppAuthFetcherAuthorization saveAuthorization:authorization
+                                         toKeychainForName:kGTMAppAuthKeychainName
+                                 useDataProtectionKeychain:YES];
+}
+
+- (void)removeAllKeychainEntries {
+  [GTMAppAuthFetcherAuthorization removeAuthorizationFromKeychainForName:kGTMAppAuthKeychainName
+                                               useDataProtectionKeychain:YES];
+}
+
+@end
+
+NS_ASSUME_NONNULL_END

+ 4 - 0
GoogleSignIn/Sources/GIDKeychainHandlling/GIDKeychainHandlling.h

@@ -18,6 +18,8 @@
 
 @class OIDAuthState;
 
+NS_ASSUME_NONNULL_BEGIN
+
 @protocol GIDKeychainHandlling <NSObject>
 
 - (OIDAuthState *)loadAuthState;
@@ -27,3 +29,5 @@
 - (void)removeAllKeychainEntries;
 
 @end
+
+NS_ASSUME_NONNULL_END