Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start the incremental authorization flow by creating OIDAuthorizationRequest. #406

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
54df794
Create method verifyAccountDetailsInteractivelyWithOptions.
brnnmrls Apr 17, 2024
5896985
Move configuration creation methods to GIDConfiguration from GIDSignIn.
brnnmrls Apr 18, 2024
94a4175
Implement default options creation methods.
brnnmrls Apr 18, 2024
4c2a643
Options validation.
brnnmrls Apr 18, 2024
78e175d
Add config initializers.
brnnmrls Apr 25, 2024
731d3a8
Merge branch 'briannamorales/vwg-flow' into briannamorales/optionsVal…
brnnmrls Apr 25, 2024
a5b9a61
Fix spacing.
brnnmrls Apr 25, 2024
d70400a
Add import to use GIDAccountDetailTypeAgeOver18.
brnnmrls Apr 25, 2024
f858d20
Import GIDConfiguration to test file.
brnnmrls Apr 25, 2024
4a97c00
Create OIDAuthorizationRequest.
brnnmrls Apr 29, 2024
c4d0a16
Add tests for config initializers.
brnnmrls Apr 30, 2024
e04a1ea
Add in initializer with config tests.
brnnmrls May 1, 2024
93fb453
Make used variables properties.
brnnmrls May 2, 2024
8441f85
Merge branch 'briannamorales/optionsValidation' into briannamorales/p…
brnnmrls May 2, 2024
066fa07
Add TODO for request/response handling tests.
brnnmrls May 2, 2024
dc6560b
Exclude MacOS for `GIDEMMSupport` use.
brnnmrls May 3, 2024
fa7845c
Silence unused 'request' variable for now until response is implemented.
brnnmrls May 3, 2024
8bfd659
Add tests for config initializer and current user exception.
brnnmrls May 7, 2024
9376a4b
Create fake main bundle initializer and modify tests.
brnnmrls May 8, 2024
4cebc05
Remove Emm flow support and move GIDSignIn strings to avoid repeated …
brnnmrls May 8, 2024
51c5a36
Unblock testing in GIDVerifyAccountDetailTest by changing GIDSignInTe…
brnnmrls May 8, 2024
6ce9f10
Address formatting and indicate designated initializer in GIDFakeMain…
brnnmrls May 9, 2024
4d981eb
Add stopFaking calls in appropriate tests.
brnnmrls May 9, 2024
b744a4b
Fix indentation and remove parameter from `additionalParameters`.
brnnmrls May 9, 2024
89b92d3
Let parameter-less `init` be nullable and require `initWithConfig` to…
brnnmrls May 10, 2024
78daa0b
Create `GIDSignInConstants` class to hold common constants across the…
brnnmrls May 10, 2024
7112ce5
Fix method description and make `initWithConfig` nullable.
brnnmrls May 10, 2024
241d72e
Merge branch 'briannamorales/optionsValidation' into briannamorales/p…
brnnmrls May 11, 2024
674ec5f
Merge branch 'briannamorales/vwg-flow' into briannamorales/presentAut…
brnnmrls May 14, 2024
aac80b4
Move constants to `GIDSignInConstants` and update doc comments.
brnnmrls May 14, 2024
298d9c4
Update preprocessor directives to exclude TARGET_OS_MACCATALYST.
brnnmrls May 14, 2024
227f3e3
Fix formatting.
brnnmrls May 15, 2024
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
5 changes: 1 addition & 4 deletions GoogleSignIn/Sources/GIDGoogleUser.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#import "GoogleSignIn/Sources/GIDEMMSupport.h"
#import "GoogleSignIn/Sources/GIDProfileData_Private.h"
#import "GoogleSignIn/Sources/GIDSignIn_Private.h"
#import "GoogleSignIn/Sources/GIDSignInConstants.h"
#import "GoogleSignIn/Sources/GIDSignInPreferences.h"
#import "GoogleSignIn/Sources/GIDToken_Private.h"

Expand All @@ -43,10 +44,6 @@
static NSString *const kProfileDataKey = @"profileData";
static NSString *const kAuthStateKey = @"authState";

// Parameters for the token exchange endpoint.
static NSString *const kAudienceParameter = @"audience";
static NSString *const kOpenIDRealmParameter = @"openid.realm";

// Additional parameter names for EMM.
static NSString *const kEMMSupportParameterName = @"emm_support";

Expand Down
18 changes: 1 addition & 17 deletions GoogleSignIn/Sources/GIDSignIn.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDSignInResult.h"

#import "GoogleSignIn/Sources/GIDEMMSupport.h"
#import "GoogleSignIn/Sources/GIDSignInConstants.h"
#import "GoogleSignIn/Sources/GIDSignInInternalOptions.h"
#import "GoogleSignIn/Sources/GIDSignInPreferences.h"
#import "GoogleSignIn/Sources/GIDCallbackQueue.h"
Expand Down Expand Up @@ -69,21 +70,12 @@
// The name of the query parameter used for logging the restart of auth from EMM callback.
static NSString *const kEMMRestartAuthParameter = @"emmres";

// The URL template for the authorization endpoint.
static NSString *const kAuthorizationURLTemplate = @"https://%@/o/oauth2/v2/auth";

// The URL template for the token endpoint.
static NSString *const kTokenURLTemplate = @"https://%@/token";

// The URL template for the URL to get user info.
static NSString *const kUserInfoURLTemplate = @"https://%@/oauth2/v3/userinfo?access_token=%@";

// The URL template for the URL to revoke the token.
static NSString *const kRevokeTokenURLTemplate = @"https://%@/o/oauth2/revoke?token=%@";

// Expected path in the URL scheme to be handled.
static NSString *const kBrowserCallbackPath = @"/oauth2callback";

// Expected path for EMM callback.
static NSString *const kEMMCallbackPath = @"/emmcallback";

Expand Down Expand Up @@ -124,14 +116,6 @@
// The delay before the new sign-in flow can be presented after the existing one is cancelled.
static const NSTimeInterval kPresentationDelayAfterCancel = 1.0;

// Parameters for the auth and token exchange endpoints.
static NSString *const kAudienceParameter = @"audience";
// See b/11669751 .
static NSString *const kOpenIDRealmParameter = @"openid.realm";
static NSString *const kIncludeGrantedScopesParameter = @"include_granted_scopes";
static NSString *const kLoginHintParameter = @"login_hint";
static NSString *const kHostedDomainParameter = @"hd";

// Minimum time to expiration for a restored access token.
static const NSTimeInterval kMinimumRestoredAccessTokenTimeToExpire = 600.0;

Expand Down
41 changes: 41 additions & 0 deletions GoogleSignIn/Sources/GIDSignInConstants.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2024 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>

/// The URL template for the authorization endpoint.
extern NSString *const kAuthorizationURLTemplate;

/// The URL template for the token endpoint.
extern NSString *const kTokenURLTemplate;

/// Expected path in the URL scheme to be handled.
extern NSString *const kBrowserCallbackPath;

/// The name of the audience parameter for the auth and token exchange endpoints.
extern NSString *const kAudienceParameter;

/// The name of the open ID realm parameter for the auth and token exchange endpoints.
extern NSString *const kOpenIDRealmParameter;

/// The name of the include granted scopes parameter for the auth and token exchange endpoints.
extern NSString *const kIncludeGrantedScopesParameter;

/// The name of the login hint parameter for the auth and token exchange endpoints.
extern NSString *const kLoginHintParameter;

/// The name of the hosted domain parameter for the auth and token exchange endpoints.
extern NSString *const kHostedDomainParameter;
29 changes: 29 additions & 0 deletions GoogleSignIn/Sources/GIDSignInConstants.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2024 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/GIDSignInConstants.h"

NSString *const kAuthorizationURLTemplate = @"https://%@/o/oauth2/v2/auth";
NSString *const kTokenURLTemplate = @"https://%@/token";
NSString *const kBrowserCallbackPath = @"/oauth2callback";

NSString *const kAudienceParameter = @"audience";
brnnmrls marked this conversation as resolved.
Show resolved Hide resolved
NSString *const kOpenIDRealmParameter = @"openid.realm";
NSString *const kIncludeGrantedScopesParameter = @"include_granted_scopes";
NSString *const kLoginHintParameter = @"login_hint";
NSString *const kHostedDomainParameter = @"hd";
16 changes: 8 additions & 8 deletions GoogleSignIn/Sources/GIDSignInInternalOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@

#import "GoogleSignIn/Sources/GIDSignIn_Private.h"

#if TARGET_OS_IOS
#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST
#import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDVerifyAccountDetail.h"
#endif // TARGET_OS_IOS
#endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST

@class GIDConfiguration;
@class GIDSignInResult;
Expand All @@ -45,10 +45,10 @@ NS_ASSUME_NONNULL_BEGIN
/// Whether the sign-in is an addScopes flow. NO means it is a sign in flow.
@property(nonatomic, readonly) BOOL addScopesFlow;

#if TARGET_OS_IOS
#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST
/// The user account details the Verify with Google flow will verify
@property(nonatomic, copy, nullable, readonly) NSArray<GIDVerifiableAccountDetail *> *accountDetailsToVerify;
#endif // TARGET_OS_IOS
#endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST

/// The extra parameters used in the sign-in URL.
@property(nonatomic, readonly, nullable) NSDictionary *extraParams;
Expand All @@ -67,10 +67,10 @@ NS_ASSUME_NONNULL_BEGIN
/// The completion block to be called at the completion of the flow.
@property(nonatomic, readonly, nullable) GIDSignInCompletion completion;

#if TARGET_OS_IOS
#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST
/// The completion block to be called at the completion of the verify flow.
@property(nonatomic, readonly, nullable) GIDVerifyCompletion verifyCompletion;
#endif // TARGET_OS_IOS
#endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST

/// The scopes to be used during the flow.
@property(nonatomic, copy, nullable) NSArray<NSString *> *scopes;
Expand All @@ -79,14 +79,14 @@ NS_ASSUME_NONNULL_BEGIN
@property(nonatomic, copy, nullable) NSString *loginHint;

/// Creates the default options.
#if TARGET_OS_IOS
#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST
+ (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)configuration
presentingViewController:(nullable UIViewController *)presentingViewController
loginHint:(nullable NSString *)loginHint
addScopesFlow:(BOOL)addScopesFlow
accountDetailsToVerify:(NSArray<GIDVerifiableAccountDetail *> *)accountDetailsToVerify
verifyCompletion:(nullable GIDVerifyCompletion)completion;
#endif // TARGET_OS_IOS
#endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST

#if TARGET_OS_IOS || TARGET_OS_MACCATALYST
+ (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)configuration
Expand Down
4 changes: 2 additions & 2 deletions GoogleSignIn/Sources/GIDSignInInternalOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

@implementation GIDSignInInternalOptions

#if TARGET_OS_IOS
#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST
+ (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)configuration
presentingViewController:(nullable UIViewController *)presentingViewController
loginHint:(nullable NSString *)loginHint
Expand All @@ -46,7 +46,7 @@ + (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)con
}
return options;
}
#endif // TARGET_OS_IOS
#endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST

#if TARGET_OS_IOS || TARGET_OS_MACCATALYST
+ (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,39 @@

#import "GoogleSignIn/Sources/GIDSignInInternalOptions.h"
#import "GoogleSignIn/Sources/GIDSignInCallbackSchemes.h"
#import "GoogleSignIn/Sources/GIDSignInConstants.h"
#import "GoogleSignIn/Sources/GIDSignInPreferences.h"

#if TARGET_OS_IOS
mdmathias marked this conversation as resolved.
Show resolved Hide resolved
@import GTMAppAuth;

@implementation GIDVerifyAccountDetail
#ifdef SWIFT_PACKAGE
@import AppAuth;
@import GTMSessionFetcherCore;
#else
#import <AppAuth/OIDAuthorizationRequest.h>
#import <AppAuth/OIDResponseTypes.h>
#import <AppAuth/OIDServiceConfiguration.h>
#endif

#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST
mdmathias marked this conversation as resolved.
Show resolved Hide resolved

@implementation GIDVerifyAccountDetail {
/// AppAuth configuration object.
OIDServiceConfiguration *_appAuthConfiguration;
}

- (instancetype)initWithConfig:(GIDConfiguration *)configuration {
self = [super init];
if (self) {
_configuration = configuration;

NSString *authorizationEndpointURL = [NSString stringWithFormat:kAuthorizationURLTemplate,
[GIDSignInPreferences googleAuthorizationServer]];
NSString *tokenEndpointURL = [NSString stringWithFormat:kTokenURLTemplate,
[GIDSignInPreferences googleTokenServer]];
_appAuthConfiguration = [[OIDServiceConfiguration alloc]
initWithAuthorizationEndpoint:[NSURL URLWithString:authorizationEndpointURL]
tokenEndpoint:[NSURL URLWithString:tokenEndpointURL]];
}
return self;
}
Expand Down Expand Up @@ -102,15 +126,47 @@ - (void)verifyAccountDetailsInteractivelyWithOptions:(GIDSignInInternalOptions *

// If the application does not support the required URL schemes tell the developer so.
GIDSignInCallbackSchemes *schemes =
[[GIDSignInCallbackSchemes alloc] initWithClientIdentifier:options.configuration.clientID];
[[GIDSignInCallbackSchemes alloc] initWithClientIdentifier:options.configuration.clientID];
NSArray<NSString *> *unsupportedSchemes = [schemes unsupportedSchemes];
if (unsupportedSchemes.count != 0) {
// NOLINTNEXTLINE(google-objc-avoid-throwing-exception)
[NSException raise:NSInvalidArgumentException
format:@"Your app is missing support for the following URL schemes: %@",
[unsupportedSchemes componentsJoinedByString:@", "]];
}
// TODO(#397): Start the incremental authorization flow.
NSString *redirectURI =
[NSString stringWithFormat:@"%@:%@", [schemes clientIdentifierScheme], kBrowserCallbackPath];
NSURL *redirectURL = [NSURL URLWithString:redirectURI];

NSMutableDictionary<NSString *, NSString *> *additionalParameters = [@{} mutableCopy];
if (options.configuration.serverClientID) {
additionalParameters[kAudienceParameter] = options.configuration.serverClientID;
}
if (options.loginHint) {
additionalParameters[kLoginHintParameter] = options.loginHint;
}
if (options.configuration.hostedDomain) {
additionalParameters[kHostedDomainParameter] = options.configuration.hostedDomain;
}
additionalParameters[kSDKVersionLoggingParameter] = GIDVersion();
additionalParameters[kEnvironmentLoggingParameter] = GIDEnvironment();

NSMutableArray *scopes;
for (GIDVerifiableAccountDetail *detail in options.accountDetailsToVerify) {
NSString *scopeString = [detail scope];
if (scopeString) {
[scopes addObject:scopeString];
}
}

// TODO(#405): Use request variable to present request and process response.
__unused OIDAuthorizationRequest *request =
brnnmrls marked this conversation as resolved.
Show resolved Hide resolved
[[OIDAuthorizationRequest alloc] initWithConfiguration:_appAuthConfiguration
clientId:options.configuration.clientID
scopes:scopes
redirectURL:redirectURL
responseType:OIDResponseTypeCode
additionalParameters:additionalParameters];
}

#pragma mark - Helpers
Expand Down Expand Up @@ -144,4 +200,4 @@ - (void)assertValidPresentingViewController:(GIDSignInInternalOptions *)options

@end

#endif // TARGET_OS_IOS
#endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST
brnnmrls marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#import <TargetConditionals.h>

#if TARGET_OS_IOS
#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST

#import <Foundation/Foundation.h>

Expand Down Expand Up @@ -91,4 +91,4 @@ typedef void (^GIDVerifyCompletion)(GIDVerifiedAccountDetailResult *_Nullable ve

NS_ASSUME_NONNULL_END

#endif // TARGET_OS_IOS
#endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST
1 change: 1 addition & 0 deletions GoogleSignIn/Tests/Unit/GIDFakeMainBundle.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ NS_ASSUME_NONNULL_BEGIN
* @brief Initializes a GIDFakeMainBundle object with `nil` to all of the designated initializer's parameters.
*/
- (instancetype)init;

/**
* @fn startFaking:
* @brief Starts faking [NSBundle mainBundle]
Expand Down
4 changes: 2 additions & 2 deletions GoogleSignIn/Tests/Unit/GIDSignInInternalOptionsTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ @interface GIDSignInInternalOptionsTest : XCTestCase

@implementation GIDSignInInternalOptionsTest

#if TARGET_OS_IOS
#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST
- (void)testDefaultOptionsForVerificationFlow {
GIDConfiguration *configuration = [[GIDConfiguration alloc] initWithClientID:kClientId
serverClientID:nil
Expand All @@ -59,7 +59,7 @@ - (void)testDefaultOptionsForVerificationFlow {
XCTAssertEqual(options.presentingViewController, presentingViewController);
XCTAssertEqual(options.accountDetailsToVerify, accountDetailsToVerify);
}
#endif // TARGET_OS_IOS
#endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST

- (void)testDefaultOptions {
id configuration = OCMStrictClassMock([GIDConfiguration class]);
Expand Down
6 changes: 4 additions & 2 deletions GoogleSignIn/Tests/Unit/GIDVerifyAccountDetailTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#import <XCTest/XCTest.h>

#if TARGET_OS_IOS
#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST
#import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDConfiguration.h"
#import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDVerifyAccountDetail.h"
#import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDVerifiableAccountDetail.h"
Expand Down Expand Up @@ -159,6 +159,8 @@ - (void)testCurrentUserException {
}
}

// TODO(#405): Write tests for request and response handling.

- (void)testPresentingViewControllerException {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wnonnull"
Expand Down Expand Up @@ -221,4 +223,4 @@ - (void)testSchemesNotSupportedException {

@end

#endif // TARGET_OS_IOS
#endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST
Loading