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

Handle authorization response and return result object. #426

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 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
25d5624
Add properties and initializer to GIDVerifiedAccountDetailResult class.
brnnmrls May 20, 2024
0e41187
Handle response by creating and calling completion callback method.
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
2dc6e14
Add method to let the user refresh tokens with a passed auth state.
brnnmrls May 29, 2024
0ca4cbb
Merge branch 'briannamorales/processAuthorizationResponse' into brian…
brnnmrls May 29, 2024
e3a3dfd
Import OIDAuthState to GIDVerifiedAccountDetailResult class.
brnnmrls May 29, 2024
1d1ae64
Add new detail to GIDAccountDetailType to indicate there was an error…
brnnmrls May 30, 2024
9cc4df9
Add tests and create handling for GIDVerifiedAccountDetailResult class.
brnnmrls May 31, 2024
756cc84
Add GIDVerifiedaccountDetailResultHandling protocol to public folder.
brnnmrls Jun 1, 2024
5c25d97
Add tests for GIDVerifiedAccountDetailResult class.
brnnmrls Jun 1, 2024
69a6d59
Rename `GIDVerifiedAccountDetailResultFake` to `GIDVerifiedAccountDet…
brnnmrls Jun 4, 2024
e3e4177
Check equality between GIDVerifiableAccountDetail objects.
brnnmrls Jun 4, 2024
19de2dc
Stop mocking auth state ivar to keep from carrying over to subsequent…
brnnmrls Jun 5, 2024
1064fa1
Import `OIDScopeUtilities` to utilize scopesArrayWithString.
brnnmrls Jun 5, 2024
eeb2018
Add imports to fix failing tests.
brnnmrls Jun 5, 2024
2692e2c
Make naming changes and add missing availability declarations.
brnnmrls Jun 5, 2024
6b6490e
Merge branch 'briannamorales/vwg-flow' into briannamorales/handleAuth…
brnnmrls Jun 5, 2024
9011e74
Fix naming and doc comment.
brnnmrls Jun 5, 2024
31ea7f7
Update properties of `GIDVerifiedAccountDetailResult` upon refresh. A…
brnnmrls Jun 13, 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
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 <TargetConditionals.h>

#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST

#import <Foundation/Foundation.h>

#import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDVerifiedAccountDetailHandling.h"

NS_ASSUME_NONNULL_BEGIN

@class GIDVerifiedAccountDetailResult;
@class GIDVerifiableAccountDetail;
@class OIDAuthState;
@class OIDTokenResponse;

/// A fake implementation of `GIDVerifiedAccountDetailHandling` for testing purposes.
@interface GIDVerifiedAccountDetailHandlingFake : NSObject <GIDVerifiedAccountDetailHandling>

/// The token response to be updated in the auth state.
@property (nonatomic, nullable) OIDTokenResponse *tokenResponse;

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

/// The error to be updated in the auth state.
@property (nonatomic, nullable) NSError *error;

/// A list of verified account details.
@property(nonatomic, copy, readonly) NSArray<GIDVerifiableAccountDetail *>
*verifiedAccountDetails;

/// Creates an instance conforming to `GIDVerifiedAccountDetailHandling` with the provided
/// token response, auth state, and error.
///
/// @param tokenResponse The `OIDTokenResponse` instance to update the auth state.
/// @param verifiedAuthState The `OIDAuthState` instance to refresh tokens.
/// @param error Error to indicate failure getting the token response.
- (instancetype)initWithTokenResponse:(nullable OIDTokenResponse *)tokenResponse
verifiedAuthState:(nullable OIDAuthState *)verifiedAuthState
error:(nullable NSError *)error;

@end

NS_ASSUME_NONNULL_END

#endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* 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/GIDVerifyAccountDetail/Fake/GIDVerifiedAccountDetailHandlingFake.h"

#import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDVerifiableAccountDetail.h"
#import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDVerifiedAccountDetailResult.h"

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

#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST

@implementation GIDVerifiedAccountDetailHandlingFake

- (instancetype)initWithLastTokenResponse:(OIDTokenResponse *)tokenResponse
accountDetails:(NSArray<GIDVerifiableAccountDetail *> *)accountDetails
authState:(OIDAuthState *)authState {
self = [super init];
if (self) {
NSAssert(false, @"This class is only to be used in testing. Do not use.");
}
return self;
}

- (instancetype)initWithTokenResponse:(nullable OIDTokenResponse *)tokenResponse
verifiedAuthState:(nullable OIDAuthState *)verifiedAuthState
error:(nullable NSError *)error {
self = [super init];
if (self) {
_tokenResponse = tokenResponse;
_verifiedAuthState = verifiedAuthState;
_error = error;
}
return self;
}

- (void)refreshTokensWithCompletion:(nullable void (^)(GIDVerifiedAccountDetailResult *,
NSError *))completion {
if (_tokenResponse) {
[self.verifiedAuthState updateWithTokenResponse:_tokenResponse error:nil];
} else {
[self.verifiedAuthState updateWithAuthorizationError:_error];
}

[self updateVerifiedDetailsWithTokenResponse:_tokenResponse];

GIDVerifiedAccountDetailResult *result =
[[GIDVerifiedAccountDetailResult alloc] initWithLastTokenResponse:_tokenResponse
accountDetails:_verifiedAccountDetails
authState:_verifiedAuthState];
completion(result, _error);
}

- (void)updateVerifiedDetailsWithTokenResponse:(nullable OIDTokenResponse *)response {
if (response) {
NSArray<NSString *> *accountDetailsString =
[OIDScopeUtilities scopesArrayWithString:response.scope];

NSMutableArray<GIDVerifiableAccountDetail *> *verifiedAccountDetails = [NSMutableArray array];
for (NSString *type in accountDetailsString) {
GIDAccountDetailType detailType = [GIDVerifiableAccountDetail detailTypeWithString:type];
if (detailType != GIDAccountDetailTypeUnknown) {
[verifiedAccountDetails addObject:
[[GIDVerifiableAccountDetail alloc] initWithAccountDetailType:detailType]];
}
}
_verifiedAccountDetails = [verifiedAccountDetails copy];
} else {
_verifiedAccountDetails = @[];
}
}

@end

#endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

#import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDVerifiableAccountDetail.h"

#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST

NSString *const kAccountDetailTypeAgeOver18Scope = @"https://www.googleapis.com/auth/verified.age.over18.standard";

@implementation GIDVerifiableAccountDetail
Expand All @@ -37,4 +39,24 @@ - (nullable NSString *)scope {
}
}

- (BOOL)isEqual:(id)object {
brnnmrls marked this conversation as resolved.
Show resolved Hide resolved
if (![object isKindOfClass:[GIDVerifiableAccountDetail class]]) {
return NO;
}
return self.accountDetailType == ((GIDVerifiableAccountDetail *)object).accountDetailType;
}

- (NSUInteger)hash {
return self.accountDetailType;
}

+ (GIDAccountDetailType)detailTypeWithString:(NSString *)detailTypeString {
if ([detailTypeString isEqualToString:kAccountDetailTypeAgeOver18Scope]) {
return GIDAccountDetailTypeAgeOver18;
}
return GIDAccountDetailTypeUnknown;
}

@end

#endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,115 @@

#import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDVerifiedAccountDetailResult.h"

#import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDVerifiableAccountDetail.h"

#ifdef SWIFT_PACKAGE
@import AppAuth;
#else
#import <AppAuth/OIDAuthState.h>
#import <AppAuth/OIDAuthorizationRequest.h>
#import <AppAuth/OIDAuthorizationResponse.h>
#import <AppAuth/OIDAuthorizationService.h>
#import <AppAuth/OIDScopeUtilities.h>
#import <AppAuth/OIDTokenRequest.h>
#import <AppAuth/OIDTokenResponse.h>
#endif

#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST

NS_ASSUME_NONNULL_BEGIN

@implementation GIDVerifiedAccountDetailResult

- (instancetype)initWithLastTokenResponse:(OIDTokenResponse *)tokenResponse
accountDetails:(NSArray<GIDVerifiableAccountDetail *> *)accountDetails
authState:(OIDAuthState *)authState {
self = [super init];
if (self) {
_expirationDate = tokenResponse.accessTokenExpirationDate;
_accessTokenString = tokenResponse.accessToken;
_refreshTokenString = tokenResponse.refreshToken;
_verifiedAccountDetails = accountDetails;
_verifiedAuthState = authState;
}
return self;
}

// TODO: Migrate refresh logic to `GIDGoogleuser` (#441).
- (void)refreshTokensWithCompletion:(nullable void (^)(GIDVerifiedAccountDetailResult *,
brnnmrls marked this conversation as resolved.
Show resolved Hide resolved
NSError *))completion {
OIDAuthorizationResponse *authResponse = self.verifiedAuthState.lastAuthorizationResponse;
OIDAuthorizationRequest *request = authResponse.request;

OIDTokenRequest *refreshRequest =
[[OIDTokenRequest alloc] initWithConfiguration:request.configuration
grantType:OIDGrantTypeAuthorizationCode
authorizationCode:authResponse.authorizationCode
redirectURL:request.redirectURL
clientID:request.clientID
clientSecret:request.clientSecret
scope:request.scope
refreshToken:self.refreshTokenString
codeVerifier:request.codeVerifier
additionalParameters:request.additionalParameters];

[OIDAuthorizationService performTokenRequest:refreshRequest
originalAuthorizationResponse:authResponse
callback:^(OIDTokenResponse * _Nullable tokenResponse,
NSError * _Nullable error) {
if (tokenResponse) {
[self.verifiedAuthState updateWithTokenResponse:tokenResponse error:nil];
brnnmrls marked this conversation as resolved.
Show resolved Hide resolved
} else {
[self.verifiedAuthState updateWithAuthorizationError:error];
}
[self updateVerifiedDetailsWithTokenResponse:tokenResponse];
completion(self, error);
}];
}

- (void)updateVerifiedDetailsWithTokenResponse:(nullable OIDTokenResponse *)tokenResponse {
if (tokenResponse) {
_expirationDate = tokenResponse.accessTokenExpirationDate;
_accessTokenString = tokenResponse.accessToken;
_refreshTokenString = tokenResponse.refreshToken;

NSArray<NSString *> *accountDetailsString =
[OIDScopeUtilities scopesArrayWithString:tokenResponse.scope];
NSMutableArray<GIDVerifiableAccountDetail *> *verifiedAccountDetails = [NSMutableArray array];
for (NSString *type in accountDetailsString) {
GIDAccountDetailType detailType = [GIDVerifiableAccountDetail detailTypeWithString:type];
if (detailType != GIDAccountDetailTypeUnknown) {
[verifiedAccountDetails addObject:
[[GIDVerifiableAccountDetail alloc] initWithAccountDetailType:detailType]];
}
}
_verifiedAccountDetails = [verifiedAccountDetails copy];
} else {
_verifiedAccountDetails = @[];
}
}

- (BOOL)isEqual:(id)object {
if (![object isKindOfClass:[GIDVerifiedAccountDetailResult class]]) {
return NO;
}

GIDVerifiedAccountDetailResult *other = (GIDVerifiedAccountDetailResult *)object;
return [self.expirationDate isEqual:other.expirationDate] &&
[self.accessTokenString isEqualToString:other.accessTokenString] &&
[self.refreshTokenString isEqualToString:other.refreshTokenString] &&
[self.verifiedAccountDetails isEqual:other.verifiedAccountDetails] &&
[self.verifiedAuthState isEqual:other.verifiedAuthState];
}

- (NSUInteger)hash {
return [self.expirationDate hash] ^ [self.accessTokenString hash] ^
[self.refreshTokenString hash] ^ [self.verifiedAccountDetails hash] ^
[self.verifiedAuthState hash];
}

@end

NS_ASSUME_NONNULL_END

#endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST
Loading
Loading