Repository navigation
Process authorization response and token fetch. #414
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
Merged
brnnmrls
merged 63 commits into
briannamorales/vwg-flow
from
briannamorales/processAuthorizationResponse
Jun 5, 2024
Merged
Changes from all commits
Commits
Show all changes
63 commits
Select commit
Hold shift + click to select a range
54df794
Create method verifyAccountDetailsInteractivelyWithOptions.
brnnmrls 5896985
Move configuration creation methods to GIDConfiguration from GIDSignIn.
brnnmrls 94a4175
Implement default options creation methods.
brnnmrls 4c2a643
Options validation.
brnnmrls 78e175d
Add config initializers.
brnnmrls 731d3a8
Merge branch 'briannamorales/vwg-flow' into briannamorales/optionsVal…
brnnmrls a5b9a61
Fix spacing.
brnnmrls d70400a
Add import to use GIDAccountDetailTypeAgeOver18.
brnnmrls f858d20
Import GIDConfiguration to test file.
brnnmrls 4a97c00
Create OIDAuthorizationRequest.
brnnmrls c4d0a16
Add tests for config initializers.
brnnmrls e04a1ea
Add in initializer with config tests.
brnnmrls 93fb453
Make used variables properties.
brnnmrls 8441f85
Merge branch 'briannamorales/optionsValidation' into briannamorales/p…
brnnmrls 066fa07
Add TODO for request/response handling tests.
brnnmrls dc6560b
Exclude MacOS for `GIDEMMSupport` use.
brnnmrls fa7845c
Silence unused 'request' variable for now until response is implemented.
brnnmrls 986c1da
Implement method to process authorization response.
brnnmrls 8bfd659
Add tests for config initializer and current user exception.
brnnmrls 9376a4b
Create fake main bundle initializer and modify tests.
brnnmrls 4cebc05
Remove Emm flow support and move GIDSignIn strings to avoid repeated …
brnnmrls 51c5a36
Unblock testing in GIDVerifyAccountDetailTest by changing GIDSignInTe…
brnnmrls 6ce9f10
Address formatting and indicate designated initializer in GIDFakeMain…
brnnmrls 4d981eb
Add stopFaking calls in appropriate tests.
brnnmrls b744a4b
Fix indentation and remove parameter from `additionalParameters`.
brnnmrls 89b92d3
Let parameter-less `init` be nullable and require `initWithConfig` to…
brnnmrls 78daa0b
Create `GIDSignInConstants` class to hold common constants across the…
brnnmrls 7112ce5
Fix method description and make `initWithConfig` nullable.
brnnmrls c9f6d9d
Merge branch 'briannamorales/presentAuthorizationRequest' into briann…
brnnmrls 241d72e
Merge branch 'briannamorales/optionsValidation' into briannamorales/p…
brnnmrls 1e4cb16
Merge branch 'briannamorales/presentAuthorizationRequest' into briann…
brnnmrls 2023dbb
Fix formatting and add `openIDRealm` param.
brnnmrls 52429b7
Add missing AppAuth/OID imports.
brnnmrls 674ec5f
Merge branch 'briannamorales/vwg-flow' into briannamorales/presentAut…
brnnmrls aac80b4
Move constants to `GIDSignInConstants` and update doc comments.
brnnmrls 298d9c4
Update preprocessor directives to exclude TARGET_OS_MACCATALYST.
brnnmrls d220aa7
Move `GIDVerifyAuthFlow` into separate files and change integer value…
brnnmrls 227f3e3
Fix formatting.
brnnmrls 570af10
Merge branch 'briannamorales/presentAuthorizationRequest' into briann…
brnnmrls 02e047a
Create `GIDAuthFlow` class to group properties in authentication flow.
brnnmrls f42581b
Create class `GIDAuthorizationResponseHelper` to process authorizatio…
brnnmrls 5249ae9
Reduce code duplication between flows using class `GIDAuthorizationRe…
brnnmrls bad0713
Merge branch 'briannamorales/vwg-flow' into briannamorales/processAut…
brnnmrls 2f6d0fe
Add preprocessor directives to GIDAuthorizationResponseHelper.
brnnmrls 061b76b
Return instance in GIDAuthorizationResponseHelper initializer.
brnnmrls e3a8b3d
Add test for `GIDAuthorizationResponseHelper`.
brnnmrls 34df266
Add documentation and error handling.
brnnmrls 5953f4e
Add designated initializer to `GIDAuthFlow`.
brnnmrls 77752d8
Update documentation, constant names, and `GIDAuthorizationResponseHe…
brnnmrls 06ff4d2
Add issue to clean up callback flow in the future.
brnnmrls 60f276c
Add GIDAuthorizationResponseHandling and fake for testing.
brnnmrls 5999eb0
Remove extra fetch token call to fix tests.
brnnmrls fab6b41
Add doc comment to `responseHandler` param.
brnnmrls 7dc4c28
Move GIDAuthorizationResponse related files to designated directories.
brnnmrls 6228850
Add testing for class GIDAuthorizationResponseHelper.
brnnmrls 23c3d17
Add imports and preprocessor directives to testing.
brnnmrls 0d56794
Fix test with no authorization code.
brnnmrls d754292
Add doc comments and remove unused imports.
brnnmrls 6ca223c
Updating testing to check for equality.
brnnmrls caab226
Import OIDTokenResponse.
brnnmrls 0caef48
Use created expiring access token time interval.
brnnmrls f5d4315
Update doc comments and naming.
brnnmrls 77aea79
Changed variable names from "error" to "expectedError".
brnnmrls File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
||
| /// 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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
62 changes: 62 additions & 0 deletions
62
GoogleSignIn/Sources/GIDAuthorizationResponse/API/GIDAuthorizationResponseHandling.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. | ||
| 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 |
44 changes: 44 additions & 0 deletions
44
GoogleSignIn/Sources/GIDAuthorizationResponse/Fake/GIDAuthorizationResponseHandlingFake.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.
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 | ||
76 changes: 76 additions & 0 deletions
76
GoogleSignIn/Sources/GIDAuthorizationResponse/Fake/GIDAuthorizationResponseHandlingFake.m
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
53 changes: 53 additions & 0 deletions
53
GoogleSignIn/Sources/GIDAuthorizationResponse/GIDAuthorizationResponseHelper.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.