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

Process authorization response and token fetch. #414

Merged
Merged
Show file tree
Hide file tree
Changes from 61 commits
Commits
Show all changes
63 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
986c1da
Implement method to process authorization response.
brnnmrls May 6, 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
c9f6d9d
Merge branch 'briannamorales/presentAuthorizationRequest' into briann…
brnnmrls May 11, 2024
241d72e
Merge branch 'briannamorales/optionsValidation' into briannamorales/p…
brnnmrls May 11, 2024
1e4cb16
Merge branch 'briannamorales/presentAuthorizationRequest' into briann…
brnnmrls May 11, 2024
2023dbb
Fix formatting and add `openIDRealm` param.
brnnmrls May 13, 2024
52429b7
Add missing AppAuth/OID imports.
brnnmrls May 13, 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
d220aa7
Move `GIDVerifyAuthFlow` into separate files and change integer value…
brnnmrls May 15, 2024
227f3e3
Fix formatting.
brnnmrls May 15, 2024
570af10
Merge branch 'briannamorales/presentAuthorizationRequest' into briann…
brnnmrls May 15, 2024
02e047a
Create `GIDAuthFlow` class to group properties in authentication flow.
brnnmrls May 17, 2024
f42581b
Create class `GIDAuthorizationResponseHelper` to process authorizatio…
brnnmrls May 17, 2024
5249ae9
Reduce code duplication between flows using class `GIDAuthorizationRe…
brnnmrls May 17, 2024
bad0713
Merge branch 'briannamorales/vwg-flow' into briannamorales/processAut…
brnnmrls May 17, 2024
2f6d0fe
Add preprocessor directives to GIDAuthorizationResponseHelper.
brnnmrls May 18, 2024
061b76b
Return instance in GIDAuthorizationResponseHelper initializer.
brnnmrls May 20, 2024
e3a8b3d
Add test for `GIDAuthorizationResponseHelper`.
brnnmrls May 20, 2024
34df266
Add documentation and error handling.
brnnmrls May 20, 2024
5953f4e
Add designated initializer to `GIDAuthFlow`.
brnnmrls May 21, 2024
77752d8
Update documentation, constant names, and `GIDAuthorizationResponseHe…
brnnmrls May 21, 2024
06ff4d2
Add issue to clean up callback flow in the future.
brnnmrls May 21, 2024
60f276c
Add GIDAuthorizationResponseHandling and fake for testing.
brnnmrls May 24, 2024
5999eb0
Remove extra fetch token call to fix tests.
brnnmrls May 24, 2024
fab6b41
Add doc comment to `responseHandler` param.
brnnmrls May 24, 2024
7dc4c28
Move GIDAuthorizationResponse related files to designated directories.
brnnmrls May 29, 2024
6228850
Add testing for class GIDAuthorizationResponseHelper.
brnnmrls May 29, 2024
23c3d17
Add imports and preprocessor directives to testing.
brnnmrls May 29, 2024
0d56794
Fix test with no authorization code.
brnnmrls May 29, 2024
d754292
Add doc comments and remove unused imports.
brnnmrls Jun 4, 2024
6ca223c
Updating testing to check for equality.
brnnmrls Jun 4, 2024
caab226
Import OIDTokenResponse.
brnnmrls Jun 4, 2024
0caef48
Use created expiring access token time interval.
brnnmrls Jun 4, 2024
f5d4315
Update doc comments and naming.
brnnmrls Jun 5, 2024
77aea79
Changed variable names from "error" to "expectedError".
brnnmrls Jun 5, 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
61 changes: 61 additions & 0 deletions GoogleSignIn/Sources/GIDAuthFlow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* 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/GIDCallbackQueue.h"

NS_ASSUME_NONNULL_BEGIN

@class OIDAuthState;
@class GIDProfileData;

/// The callback queue used for authentication flow.
@interface GIDAuthFlow : GIDCallbackQueue
brnnmrls marked this conversation as resolved.
Show resolved Hide resolved

/// A representation of the state of the OAuth session for this instance.
@property(nonatomic, strong, nullable) OIDAuthState *authState;

/// The error thrown from the OAuth session encountered for this instance.
@property(nonatomic, strong, nullable) NSError *error;

/// The EMM support version.
@property(nonatomic, copy, nullable) NSString *emmSupport;

/// The profile data extracted from the ID token.
@property(nonatomic, nullable) GIDProfileData *profileData;

/// Initialize a `GIDAuthFlow` object by specifying all available properties.
///
/// @param authState The configuration to be used.
/// @param error The configuration to be used.
/// @param emmSupport The configuration to be used.
/// @param profileData The configuration to be used.
/// @return An initialized `GIDAuthFlow` instance.
- (instancetype)initWithAuthState:(nullable OIDAuthState *)authState
error:(nullable NSError *)error
emmSupport:(nullable NSString *)emmSupport
profileData:(nullable GIDProfileData *)profileData
NS_DESIGNATED_INITIALIZER;

/// Initialize a `GIDAuthFlow` object by calling the designated initializer with `nil` values.
///
/// @return An initialized `GIDAuthFlow` instance.
- (instancetype)init;

@end

NS_ASSUME_NONNULL_END
41 changes: 41 additions & 0 deletions GoogleSignIn/Sources/GIDAuthFlow.m
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 "GoogleSignIn/Sources/GIDAuthFlow.h"

@implementation GIDAuthFlow

- (instancetype)initWithAuthState:(nullable OIDAuthState *)authState
error:(nullable NSError *)error
emmSupport:(nullable NSString *)emmSupport
profileData:(nullable GIDProfileData *)profileData {
self = [super init];
if (self) {
_authState = authState;
_error = error;
_emmSupport = emmSupport;
_profileData = profileData;
}
return self;
}

- (instancetype)init {
return [self initWithAuthState:nil
error:nil
emmSupport:nil
profileData:nil];
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* 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>

@class GIDAuthFlow;
@class GIDConfiguration;
@class OIDAuthorizationResponse;

NS_ASSUME_NONNULL_BEGIN

/// A list of potential current flow names.
typedef NS_ENUM(NSInteger, GIDFlowName) {
/// The Sign In flow.
brnnmrls marked this conversation as resolved.
Show resolved Hide resolved
GIDFlowNameSignIn = 0,
/// The Verify flow.
GIDFlowNameVerifyAccountDetail = 1,
};

@protocol GIDAuthorizationResponseHandling

/// Initializes a new instance of the `GIDAuthorizationResponseHandling` class with the provided fields.
///
/// @param authorizationResponse The authorization response to be processed.
/// @param emmSupport The EMM support version.
/// @param flowName The name of the current flow.
/// @param configuration The configuration.
/// @param error The error thrown if there's no authorization response.
/// @return A new initialized instance of the `GIDAuthorizationResponseHandling` class.
- (instancetype)
initWithAuthorizationResponse:(nullable OIDAuthorizationResponse *)authorizationResponse
emmSupport:(nullable NSString *)emmSupport
flowName:(enum GIDFlowName)flowName
configuration:(nullable GIDConfiguration *)configuration
error:(nullable NSError *)error;

/// Fetches the access token if necessary as part of the auth flow.
///
/// @param authFlow The auth flow to either fetch tokens or error.
- (void)maybeFetchToken:(GIDAuthFlow *)authFlow;

/// Processes the authorization response and returns an auth flow.
///
/// @return An instance of `GIDAuthFlow`.
- (GIDAuthFlow *)generateAuthFlowFromAuthorizationResponse;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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/GIDAuthorizationResponse/API/GIDAuthorizationResponseHandling.h"

NS_ASSUME_NONNULL_BEGIN

@class OIDAuthState;

/// A fake implementation of `GIDAuthorizationResponseHandling` for testing purposes.
@interface GIDAuthorizationResponseHandlingFake : NSObject <GIDAuthorizationResponseHandling>
brnnmrls marked this conversation as resolved.
Show resolved Hide resolved

/// The auth state to be used to fetch tokens.
@property (nonatomic, nullable) OIDAuthState *authState;

/// The error to be passed into the completion.
@property (nonatomic, nullable) NSError *error;

/// Creates an instance conforming to `GIDAuthorizationResponseHandling` with the provided
/// auth state and error.
///
/// @param authState The `OIDAuthState` instance to access tokens.
/// @param error The `NSError` to pass into the completion.
- (instancetype)initWithAuthState:(nullable OIDAuthState *)authState
error:(nullable NSError *)error;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* 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 "GoogleSignIn/Sources/GIDAuthorizationResponse/Fake/GIDAuthorizationResponseHandlingFake.h"

#import "GoogleSignIn/Sources/GIDAuthorizationResponse/API/GIDAuthorizationResponseHandling.h"

#import "GoogleSignIn/Sources/GIDAuthFlow.h"
#import "GoogleSignIn/Sources/GIDSignInConstants.h"

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

@implementation GIDAuthorizationResponseHandlingFake

- (instancetype)initWithAuthorizationResponse:(OIDAuthorizationResponse *)authorizationResponse
emmSupport:(NSString *)emmSupport
flowName:(enum GIDFlowName)flowName
configuration:(GIDConfiguration *)configuration
error:(NSError *)error {
self = [super init];
if (self) {
NSAssert(false, @"This class is only to be used in testing. Do not use.");
}
return self;
}

- (instancetype)initWithAuthState:(nullable OIDAuthState *)authState
error:(nullable NSError *)error {
self = [super init];
if (self) {
_authState = authState;
_error = error;
}
return self;
}

- (GIDAuthFlow *)generateAuthFlowFromAuthorizationResponse {
GIDAuthFlow *authFlow = [[GIDAuthFlow alloc] initWithAuthState:self.authState
error:self.error
emmSupport:nil
profileData:nil];
return authFlow;
}

- (void)maybeFetchToken:(GIDAuthFlow *)authFlow {
if (authFlow.error ||
(_authState.lastTokenResponse.accessToken &&
[_authState.lastTokenResponse.accessTokenExpirationDate timeIntervalSinceNow] >
kMinimumRestoredAccessTokenTimeToExpire)) {
return;
}

authFlow.authState = self.authState;
authFlow.error = self.error;
}

@end

Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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/GIDAuthorizationResponse/API/GIDAuthorizationResponseHandling.h"

@class GIDAuthFlow;
@class GIDConfiguration;
@class OIDAuthorizationResponse;

NS_ASSUME_NONNULL_BEGIN

/// A helper class to process the authorization response.
@interface GIDAuthorizationResponseHelper : NSObject

/// The response handler used to process the authorization response.
@property (nonatomic, readonly) id<GIDAuthorizationResponseHandling> responseHandler;

/// Initializes a new instance of the `GIDAuthorizationResponseHelper` class with the provided field.
///
/// @param responseHandler The response handler with the authorization response to process.
/// @return A new initialized instance of the `GIDAuthorizationResponseHelper` class.
- (instancetype)
initWithAuthorizationResponseHandler:(id<GIDAuthorizationResponseHandling>)responseHandler;

/// Fetches the access token if necessary using the response handler as part of the auth flow.
///
/// @param authFlow The auth flow to either fetch tokens or error.
- (void)fetchTokenWithAuthFlow:(GIDAuthFlow *)authFlow;


/// Processes the initialized authorization response and returns a filled `GIDAuthFlow` instance.
///
/// @return An instance of `GIDAuthFlow` to either fetch tokens or error.
- (GIDAuthFlow *)fetchAuthFlowFromProcessedResponse;

@end

NS_ASSUME_NONNULL_END
Loading
Loading