GIDAuthorizationFlowFake.m 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright 2025 Google LLC
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import "GIDAuthorizationFlowFake.h"
  17. #import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDConfiguration.h"
  18. #import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDSignInResult.h"
  19. #import "GoogleSignIn/Sources/GIDGoogleUser_Private.h"
  20. #import "GoogleSignIn/Sources/GIDSignInResult_Private.h"
  21. #import "GoogleSignIn/Sources/GIDSignInInternalOptions.h"
  22. #import "GoogleSignIn/Sources/GIDConfiguration_Private.h"
  23. @implementation GIDAuthorizationFlowFake
  24. - (instancetype)initWithSignInOptions:(GIDSignInInternalOptions *)options
  25. authState:(OIDAuthState *)authState
  26. profileData:(nullable GIDProfileData *)profileData
  27. googleUser:(nullable GIDGoogleUser *)googleUser
  28. externalUserAgentSession:(nullable id<OIDExternalUserAgentSession>)userAgentSession
  29. emmSupport:(nullable NSString *)emmSupport
  30. error:(nullable NSError *)error {
  31. self = [super init];
  32. if (self) {
  33. _options = options;
  34. _authState = authState;
  35. _profileData = profileData;
  36. _googleUser = googleUser;
  37. _currentUserAgentSession = userAgentSession;
  38. _error = error;
  39. _emmSupport = emmSupport;
  40. }
  41. return self;
  42. }
  43. - (void)authorize {
  44. // Create the `googleUser` from the passed `authState` and `profileData` to simulate creating a
  45. // `googleUser` via that sign in silently flow
  46. self.googleUser = [[GIDGoogleUser alloc] initWithAuthState:self.authState
  47. profileData:self.profileData];
  48. GIDSignInResult *result = [[GIDSignInResult alloc] initWithGoogleUser:self.googleUser
  49. serverAuthCode:@"abcd"];
  50. self.options.completion(result, self.error);
  51. }
  52. - (void)authorizeInteractively {
  53. GIDSignInResult *result = [[GIDSignInResult alloc] initWithGoogleUser:self.googleUser
  54. serverAuthCode:@"abcd"];
  55. self.options.completion(result, self.error);
  56. }
  57. @end