GIDAuthorizationCompletionOperation.m 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //
  2. // GIDAuthorizationCompletionOperation.m
  3. // GoogleSignIn
  4. //
  5. // Created by Matt Mathias on 4/3/25.
  6. //
  7. #import "GIDAuthorizationCompletionOperation.h"
  8. #import "GoogleSignIn/Sources/GIDSignIn_Private.h"
  9. #import "GoogleSignIn/Sources/GIDSignInResult_Private.h"
  10. #import "GoogleSignIn/Sources/GIDAuthorizationFlow/Implementations/Operations/GIDSaveAuthOperation.h"
  11. #import "GoogleSignIn/Sources/GIDSignInInternalOptions.h"
  12. #import "GoogleSignIn/Sources/GIDAuthorizationFlow/Implementations/GIDAuthorizationFlow.h"
  13. #ifdef SWIFT_PACKAGE
  14. @import AppAuth;
  15. @import GTMAppAuth;
  16. #else
  17. #import <AppAuth/OIDAuthState.h>
  18. #import <GTMAppAuth/GTMAuthSession>
  19. #endif
  20. @interface GIDAuthorizationCompletionOperation ()
  21. @property(nonatomic, nullable) GIDAuthorizationFlow *authFlow;
  22. @end
  23. @implementation GIDAuthorizationCompletionOperation
  24. - (id)initWithAuthorizationFlow:(GIDAuthorizationFlow *)authFlow {
  25. self = [super init];
  26. if (self) {
  27. _authFlow = authFlow;
  28. }
  29. return self;
  30. }
  31. - (void)main {
  32. GIDSaveAuthOperation *saveAuth = (GIDSaveAuthOperation *)self.dependencies.firstObject;
  33. GIDSignInInternalOptions *options = saveAuth.options;
  34. if (options.completion) {
  35. GIDSignInCompletion completion = options.completion;
  36. self.authFlow.options = nil;
  37. dispatch_async(dispatch_get_main_queue(), ^{
  38. if (saveAuth.error) {
  39. completion(nil, saveAuth.error);
  40. } else {
  41. OIDAuthState *authState = saveAuth.authState;
  42. NSString *_Nullable serverAuthCode =
  43. [authState.lastTokenResponse.additionalParameters[@"server_code"] copy];
  44. GIDSignInResult *signInResult =
  45. [[GIDSignInResult alloc] initWithGoogleUser:saveAuth.currentUser
  46. serverAuthCode:serverAuthCode];
  47. completion(signInResult, nil);
  48. }
  49. });
  50. }
  51. }
  52. @end