Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
bfc16c5
Create branch GIDGoogleUser-restructure to track PRs relating to GIDG…
Alex-4-Git Jun 30, 2022
58f62d5
Create class GIDUserAuth (#177)
Alex-4-Git Jul 10, 2022
3ba23d0
Replace GIDSignInCallback (#179)
Alex-4-Git Jul 16, 2022
b6c6b8b
Add GIDToken Class (#181)
Alex-4-Git Jul 18, 2022
e5958f8
Add the property `configuration` to `GIDGoogleUser` (#183)
Alex-4-Git Jul 25, 2022
ada3203
Replace GIDSignInCallback (#179)
Alex-4-Git Jul 16, 2022
5c8fa73
Add Three token properties in GIDGoogleUser API (#189)
Alex-4-Git Aug 11, 2022
c8060d3
Merge branch 'main' into GIDGoogleUser-restructure
Alex-4-Git Aug 31, 2022
3e54f09
Add unit test for `updateAuthState:` in GIDGoogleUserTest (#212)
Alex-4-Git Sep 19, 2022
c0706ec
Merge branch 'main' into GIDGoogleUser-restructure
Alex-4-Git Sep 19, 2022
89b3ed8
Use NSTimeIntervalSince1970 to replace timeIntervalSinceReferenceDate…
Alex-4-Git Sep 22, 2022
405dc51
Make tokens in GIDGoogleUser KVO-compliant (#222)
Alex-4-Git Sep 26, 2022
2c833ce
Use accessTokenExpiresIn to replace accessTokenExpireTime in tests (#…
Alex-4-Git Sep 26, 2022
64b35f8
Move the fetcher authorizer into GIDGoogleUser API (#230)
Alex-4-Git Oct 3, 2022
18c65c0
Add unit tests for GIDEMMSupport (#236)
Alex-4-Git Oct 10, 2022
e43bd7f
Move the method `doWithFreshTokens:` into GIDGoogleUserAPI (#234)
Alex-4-Git Oct 14, 2022
bb2b7d8
Merge branch 'main' into GIDGoogleUser-restructure
Alex-4-Git Oct 14, 2022
d6f42bc
Fix the signInSample app (#238)
Alex-4-Git Oct 19, 2022
114a0ac
Move the method `addScopes` into GIDGoogleUser API (#239)
Alex-4-Git Oct 28, 2022
8de36b5
Merge branch 'main' into GIDGoogleUser-restructure
Alex-4-Git Oct 28, 2022
828ea1f
Rename the GIDGoogleUser method `doWithFreshTokens:` (#242)
Alex-4-Git Nov 2, 2022
5ddc638
Merge branch 'main' into GIDGoogleUser-restructure
Alex-4-Git Nov 2, 2022
75c5c24
Correct indentations.
Alex-4-Git Nov 4, 2022
94eb7f2
Resolve comments.
Alex-4-Git Nov 10, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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 <TargetConditionals.h>

#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST

#ifdef SWIFT_PACKAGE
@import GTMAppAuth;
#else
#import <GTMAppAuth/GTMAppAuth.h>
#endif

NS_ASSUME_NONNULL_BEGIN

// A specialized GTMAppAuthFetcherAuthorization subclass with EMM support.
@interface GIDAppAuthFetcherAuthorizationWithEMMSupport : GTMAppAuthFetcherAuthorization

@end

NS_ASSUME_NONNULL_END

#endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST
129 changes: 129 additions & 0 deletions GoogleSignIn/Sources/GIDAppAuthFetcherAuthorizationWithEMMSupport.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/*
* 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 <TargetConditionals.h>

#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST

#import "GoogleSignIn/Sources/GIDAppAuthFetcherAuthorizationWithEMMSupport.h"

#import "GoogleSignIn/Sources/GIDEMMSupport.h"

#ifdef SWIFT_PACKAGE
@import AppAuth;
@import GTMAppAuth;
#else
#import <AppAuth/AppAuth.h>
#import <GTMAppAuth/GTMAppAuth.h>
#endif

NS_ASSUME_NONNULL_BEGIN

// The specialized GTMAppAuthFetcherAuthorization delegate that handles potential EMM error
// responses.
@interface GIDAppAuthFetcherAuthorizationEMMChainedDelegate : NSObject

// Initializes with chained delegate and selector.
- (instancetype)initWithDelegate:(id)delegate selector:(SEL)selector;

// The callback method for GTMAppAuthFetcherAuthorization to invoke.
- (void)authentication:(GTMAppAuthFetcherAuthorization *)auth
request:(NSMutableURLRequest *)request
finishedWithError:(nullable NSError *)error;

@end

@implementation GIDAppAuthFetcherAuthorizationEMMChainedDelegate {
// We use a weak reference here to match GTMAppAuthFetcherAuthorization.
__weak id _delegate;
SEL _selector;
// We need to maintain a reference to the chained delegate because GTMAppAuthFetcherAuthorization
// only keeps a weak reference.
GIDAppAuthFetcherAuthorizationEMMChainedDelegate *_retained_self;
}

- (instancetype)initWithDelegate:(id)delegate selector:(SEL)selector {
self = [super init];
if (self) {
_delegate = delegate;
_selector = selector;
_retained_self = self;
}
return self;
}

- (void)authentication:(GTMAppAuthFetcherAuthorization *)auth
request:(NSMutableURLRequest *)request
finishedWithError:(nullable NSError *)error {
[GIDEMMSupport handleTokenFetchEMMError:error completion:^(NSError *_Nullable error) {
if (!self->_delegate || !self->_selector) {
return;
}
NSMethodSignature *signature = [self->_delegate methodSignatureForSelector:self->_selector];
if (!signature) {
return;
}
id argument1 = auth;
id argument2 = request;
id argument3 = error;
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
[invocation setTarget:self->_delegate]; // index 0
[invocation setSelector:self->_selector]; // index 1
[invocation setArgument:&argument1 atIndex:2];
[invocation setArgument:&argument2 atIndex:3];
[invocation setArgument:&argument3 atIndex:4];
[invocation invoke];
}];
// Prepare to deallocate the chained delegate instance because the above block will retain the
// iVar references it uses.
_retained_self = nil;
}

@end

@implementation GIDAppAuthFetcherAuthorizationWithEMMSupport

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-implementations"
- (void)authorizeRequest:(nullable NSMutableURLRequest *)request
delegate:(id)delegate
didFinishSelector:(SEL)sel {
#pragma clang diagnostic pop
GIDAppAuthFetcherAuthorizationEMMChainedDelegate *chainedDelegate =
[[GIDAppAuthFetcherAuthorizationEMMChainedDelegate alloc] initWithDelegate:delegate
selector:sel];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[super authorizeRequest:request
delegate:chainedDelegate
didFinishSelector:@selector(authentication:request:finishedWithError:)];
#pragma clang diagnostic pop
}

- (void)authorizeRequest:(nullable NSMutableURLRequest *)request
completionHandler:(GTMAppAuthFetcherAuthorizationCompletion)handler {
[super authorizeRequest:request completionHandler:^(NSError *_Nullable error) {
[GIDEMMSupport handleTokenFetchEMMError:error completion:^(NSError *_Nullable error) {
handler(error);
}];
}];
}

@end

NS_ASSUME_NONNULL_END

#endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Google LLC
* 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.
Expand All @@ -14,12 +14,19 @@
* limitations under the License.
*/

#import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDAuthentication.h"
#import <Foundation/Foundation.h>

@interface GIDAuthentication (Testing)
@class OIDAuthState;

- (BOOL)isEqual:(id)object;
- (BOOL)isEqualToAuthentication:(GIDAuthentication *)other;
- (NSUInteger)hash;
NS_ASSUME_NONNULL_BEGIN

// Internal class for GIDGoogleUser NSCoding backward compatibility.
@interface GIDAuthentication : NSObject <NSSecureCoding>

@property(nonatomic) OIDAuthState* authState;

- (instancetype)initWithAuthState:(OIDAuthState *)authState;

@end

NS_ASSUME_NONNULL_END
Loading