Skip to content

Commit 2763167

Browse files
committed
Merge branch 'GIDGoogleUser-restructure' into pin-renameDoWithFreshToken
2 parents e957ca7 + 8de36b5 commit 2763167

File tree

12 files changed

+198
-90
lines changed

12 files changed

+198
-90
lines changed

.github/workflows/builds.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
os: [macos-11, macos-12]
1414

1515
steps:
16-
- uses: actions/checkout@v2
16+
- uses: actions/checkout@v3
1717
- name: Archive for iOS
1818
run: |
1919
xcodebuild \

.github/workflows/integration_tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
working-directory: Samples/Swift/DaysUntilBirthday
1919
steps:
2020
- name: Checkout
21-
uses: actions/checkout@v2
21+
uses: actions/checkout@v3
2222
- name: Build test target for Google Sign-in button for Swift
2323
run: |
2424
xcodebuild \

.github/workflows/tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
- podspec: GoogleSignInSwiftSupport.podspec
2929
includePodspecFlag: "--include-podspecs='GoogleSignIn.podspec'"
3030
steps:
31-
- uses: actions/checkout@v2
31+
- uses: actions/checkout@v3
3232
- name: Update Bundler
3333
run: bundle update --bundler
3434
- name: Install Ruby gems with Bundler
@@ -51,7 +51,7 @@ jobs:
5151
- sdk: 'iphonesimulator'
5252
destination: '"platform=iOS Simulator,name=iPhone 11"'
5353
steps:
54-
- uses: actions/checkout@v2
54+
- uses: actions/checkout@v3
5555
- name: Build unit test target
5656
run: |
5757
xcodebuild \

GoogleSignIn/Sources/GIDGoogleUser.m

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#import "GoogleSignIn/Sources/GIDGoogleUser_Private.h"
1818

1919
#import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDConfiguration.h"
20+
#import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDSignIn.h"
2021

2122
#import "GoogleSignIn/Sources/GIDAppAuthFetcherAuthorizationWithEMMSupport.h"
2223
#import "GoogleSignIn/Sources/GIDAuthentication.h"
@@ -182,30 +183,35 @@ - (OIDAuthState *) authState{
182183
return ((GTMAppAuthFetcherAuthorization *)self.fetcherAuthorizer).authState;
183184
}
184185

185-
#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST
186-
187186
- (void)addScopes:(NSArray<NSString *> *)scopes
187+
#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST
188188
presentingViewController:(UIViewController *)presentingViewController
189+
#elif TARGET_OS_OSX || TARGET_OS_MACCATALYST
190+
presentingWindow:(NSWindow *)presentingWindow
191+
#endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST
189192
completion:(nullable void (^)(GIDUserAuth *_Nullable userAuth,
190193
NSError *_Nullable error))completion {
194+
if (self != GIDSignIn.sharedInstance.currentUser) {
195+
NSError *error = [NSError errorWithDomain:kGIDSignInErrorDomain
196+
code:kGIDSignInErrorCodeMismatchWithCurrentUser
197+
userInfo:nil];
198+
if (completion) {
199+
dispatch_async(dispatch_get_main_queue(), ^{
200+
completion(nil, error);
201+
});
202+
}
203+
return;
204+
}
205+
191206
[GIDSignIn.sharedInstance addScopes:scopes
207+
#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST
192208
presentingViewController:presentingViewController
193-
completion:completion];
194-
}
195-
196209
#elif TARGET_OS_OSX || TARGET_OS_MACCATALYST
197-
198-
- (void)addScopes:(NSArray<NSString *> *)scopes
199-
presentingWindow:(NSWindow *)presentingWindow
200-
completion:(nullable void (^)(GIDUserAuth *_Nullable userAuth,
201-
NSError *_Nullable error))completion {
202-
[GIDSignIn.sharedInstance addScopes:scopes
203210
presentingWindow:presentingWindow
211+
#endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST
204212
completion:completion];
205213
}
206214

207-
#endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST
208-
209215
#pragma mark - Private Methods
210216

211217
#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST

GoogleSignIn/Sources/GIDSignIn.m

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -265,20 +265,6 @@ - (void)signInWithPresentingViewController:(UIViewController *)presentingViewCon
265265
- (void)addScopes:(NSArray<NSString *> *)scopes
266266
presentingViewController:(UIViewController *)presentingViewController
267267
completion:(nullable GIDUserAuthCompletion)completion {
268-
// A currentUser must be available in order to complete this flow.
269-
if (!self.currentUser) {
270-
// No currentUser is set, notify callback of failure.
271-
NSError *error = [NSError errorWithDomain:kGIDSignInErrorDomain
272-
code:kGIDSignInErrorCodeNoCurrentUser
273-
userInfo:nil];
274-
if (completion) {
275-
dispatch_async(dispatch_get_main_queue(), ^{
276-
completion(nil, error);
277-
});
278-
}
279-
return;
280-
}
281-
282268
GIDConfiguration *configuration = self.currentUser.configuration;
283269
GIDSignInInternalOptions *options =
284270
[GIDSignInInternalOptions defaultOptionsWithConfiguration:configuration
@@ -350,20 +336,6 @@ - (void)signInWithPresentingWindow:(NSWindow *)presentingWindow
350336
- (void)addScopes:(NSArray<NSString *> *)scopes
351337
presentingWindow:(NSWindow *)presentingWindow
352338
completion:(nullable GIDUserAuthCompletion)completion {
353-
// A currentUser must be available in order to complete this flow.
354-
if (!self.currentUser) {
355-
// No currentUser is set, notify callback of failure.
356-
NSError *error = [NSError errorWithDomain:kGIDSignInErrorDomain
357-
code:kGIDSignInErrorCodeNoCurrentUser
358-
userInfo:nil];
359-
if (completion) {
360-
dispatch_async(dispatch_get_main_queue(), ^{
361-
completion(nil, error);
362-
});
363-
}
364-
return;
365-
}
366-
367339
GIDConfiguration *configuration = self.currentUser.configuration;
368340
GIDSignInInternalOptions *options =
369341
[GIDSignInInternalOptions defaultOptionsWithConfiguration:configuration

GoogleSignIn/Sources/GIDSignIn_Private.h

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -29,42 +29,43 @@ NS_ASSUME_NONNULL_BEGIN
2929
@class GIDGoogleUser;
3030
@class GIDSignInInternalOptions;
3131

32-
// Represents a completion block that takes a `GIDUserAuth` on success or an error if the operation
33-
// was unsuccessful.
32+
/// Represents a completion block that takes a `GIDUserAuth` on success or an error if the operation
33+
/// was unsuccessful.
3434
typedef void (^GIDUserAuthCompletion)(GIDUserAuth *_Nullable userAuth, NSError *_Nullable error);
3535

3636
// Private |GIDSignIn| methods that are used internally in this SDK and other Google SDKs.
3737
@interface GIDSignIn ()
3838

39-
// Redeclare |currentUser| as readwrite for internal use.
39+
/// Redeclare |currentUser| as readwrite for internal use.
4040
@property(nonatomic, readwrite, nullable) GIDGoogleUser *currentUser;
4141

42-
// Private initializer for |GIDSignIn|.
42+
/// Private initializer for |GIDSignIn|.
4343
- (instancetype)initPrivate;
4444

45-
// Authenticates with extra options.
45+
/// Authenticates with extra options.
4646
- (void)signInWithOptions:(GIDSignInInternalOptions *)options;
4747

48-
// Restores a previously authenticated user from the keychain synchronously without refreshing
49-
// the access token or making a userinfo request. The currentUser.profile will be nil unless
50-
// the profile data can be extracted from the ID token.
51-
//
52-
// @return NO if there is no user restored from the keychain.
48+
/// Restores a previously authenticated user from the keychain synchronously without refreshing
49+
/// the access token or making a userinfo request.
50+
///
51+
/// The currentUser.profile will be nil unless the profile data can be extracted from the ID token.
52+
///
53+
/// @return NO if there is no user restored from the keychain.
5354
- (BOOL)restorePreviousSignInNoRefresh;
5455

5556
#if TARGET_OS_IOS || TARGET_OS_MACCATALYST
5657

57-
// Starts an interactive consent flow on iOS to add scopes to the current user's grants.
58-
//
59-
// The completion will be called at the end of this process. If successful, a new `GIDGoogleUser`
60-
// instance will be returned reflecting the new scopes and saved sign-in state will be updated.
61-
//
62-
// @param scopes The scopes to ask the user to consent to.
63-
// @param presentingViewController The view controller used to present `SFSafariViewContoller` on
64-
// iOS 9 and 10 and to supply `presentationContextProvider` for `ASWebAuthenticationSession` on
65-
// iOS 13+.
66-
// @param completion The block that is called on completion. This block will be called asynchronously
67-
// on the main queue.
58+
/// Starts an interactive consent flow on iOS to add scopes to the current user's grants.
59+
///
60+
/// The completion will be called at the end of this process. If successful, a `GIDUserAuth`
61+
/// instance will be returned reflecting the new scopes and saved sign-in state will be updated.
62+
///
63+
/// @param scopes The scopes to ask the user to consent to.
64+
/// @param presentingViewController The view controller used to present `SFSafariViewContoller` on
65+
/// iOS 9 and 10 and to supply `presentationContextProvider` for `ASWebAuthenticationSession` on
66+
/// iOS 13+.
67+
/// @param completion The block that is called on completion. This block will be called asynchronously
68+
/// on the main queue.
6869
- (void)addScopes:(NSArray<NSString *> *)scopes
6970
presentingViewController:(UIViewController *)presentingViewController
7071
completion:(nullable void (^)(GIDUserAuth *_Nullable userAuth,
@@ -73,19 +74,20 @@ typedef void (^GIDUserAuthCompletion)(GIDUserAuth *_Nullable userAuth, NSError *
7374

7475
#elif TARGET_OS_OSX
7576

76-
// Starts an interactive consent flow on macOS to add scopes to the current user's grants
77-
//
78-
// The completion will be called at the end of this process. If successful, a new `GIDGoogleUser`
79-
// instance will be returned reflecting the new scopes and saved sign-in state will be updated.
80-
//
81-
// @param scopes An array of scopes to ask the user to consent to.
82-
// @param presentingWindow The window used to supply `presentationContextProvider` for `ASWebAuthenticationSession`.
83-
// @param completion The block that is called on completion. This block will be called asynchronously
84-
// on the main queue.
77+
/// Starts an interactive consent flow on macOS to add scopes to the current user's grants.
78+
///
79+
/// The completion will be called at the end of this process. If successful, a `GIDUserAuth`
80+
/// instance will be returned reflecting the new scopes and saved sign-in state will be updated.
81+
///
82+
/// @param scopes An array of scopes to ask the user to consent to.
83+
/// @param presentingWindow The window used to supply `presentationContextProvider` for
84+
/// `ASWebAuthenticationSession`.
85+
/// @param completion The block that is called on completion. This block will be called asynchronously
86+
/// on the main queue.
8587
- (void)addScopes:(NSArray<NSString *> *)scopes
8688
presentingWindow:(NSWindow *)presentingWindow
8789
completion:(nullable void (^)(GIDUserAuth *_Nullable userAuth,
88-
NSError *_Nullable error))completion;
90+
NSError *_Nullable error))completion;
8991

9092
#endif
9193

GoogleSignIn/Sources/Public/GoogleSignIn/GIDGoogleUser.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,43 @@ NS_ASSUME_NONNULL_BEGIN
116116

117117
#endif
118118

119+
#if TARGET_OS_IOS || TARGET_OS_MACCATALYST
120+
121+
/// Starts an interactive consent flow on iOS to add scopes to the user's grants.
122+
///
123+
/// The completion will be called at the end of this process. If successful, a `GIDUserAuth`
124+
/// instance will be returned reflecting the new scopes and saved sign-in state will be updated.
125+
///
126+
/// @param scopes The scopes to ask the user to consent to.
127+
/// @param presentingViewController The view controller used to present `SFSafariViewContoller` on
128+
/// iOS 9 and 10 and to supply `presentationContextProvider` for `ASWebAuthenticationSession` on
129+
/// iOS 13+.
130+
/// @param completion The block that is called on completion. This block will be called asynchronously
131+
/// on the main queue.
132+
- (void)addScopes:(NSArray<NSString *> *)scopes
133+
presentingViewController:(UIViewController *)presentingViewController
134+
completion:(nullable void (^)(GIDUserAuth *_Nullable userAuth,
135+
NSError *_Nullable error))completion
136+
NS_EXTENSION_UNAVAILABLE("The add scopes flow is not supported in App Extensions.");
137+
138+
#elif TARGET_OS_OSX
139+
140+
/// Starts an interactive consent flow on macOS to add scopes to the user's grants.
141+
///
142+
/// The completion will be called at the end of this process. If successful, a `GIDUserAuth`
143+
/// instance will be returned reflecting the new scopes and saved sign-in state will be updated.
144+
///
145+
/// @param scopes An array of scopes to ask the user to consent to.
146+
/// @param presentingWindow The window used to supply `presentationContextProvider` for `ASWebAuthenticationSession`.
147+
/// @param completion The block that is called on completion. This block will be called asynchronously
148+
/// on the main queue.
149+
- (void)addScopes:(NSArray<NSString *> *)scopes
150+
presentingWindow:(NSWindow *)presentingWindow
151+
completion:(nullable void (^)(GIDUserAuth *_Nullable userAuth,
152+
NSError *_Nullable error))completion;
153+
154+
#endif
155+
119156
@end
120157

121158
NS_ASSUME_NONNULL_END

GoogleSignIn/Sources/Public/GoogleSignIn/GIDSignIn.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ typedef NS_ERROR_ENUM(kGIDSignInErrorDomain, GIDSignInErrorCode) {
4545
kGIDSignInErrorCodeCanceled = -5,
4646
/// Indicates an Enterprise Mobility Management related error has occurred.
4747
kGIDSignInErrorCodeEMM = -6,
48-
/// Indicates there is no `currentUser`.
49-
kGIDSignInErrorCodeNoCurrentUser = -7,
5048
/// Indicates the requested scopes have already been granted to the `currentUser`.
5149
kGIDSignInErrorCodeScopesAlreadyGranted = -8,
50+
/// Indicates there is an operation on a previous user.
51+
kGIDSignInErrorCodeMismatchWithCurrentUser = -9,
5252
};
5353

5454
/// Represents a completion block that takes an error if the operation was unsuccessful.

0 commit comments

Comments
 (0)