No Description

FIRGoogleAuthCredential.m 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright 2017 Google
  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 "FIRGoogleAuthCredential.h"
  17. #import "FIRGoogleAuthProvider.h"
  18. #import "FIRAuthExceptionUtils.h"
  19. #import "FIRVerifyAssertionRequest.h"
  20. NS_ASSUME_NONNULL_BEGIN
  21. @interface FIRGoogleAuthCredential ()
  22. - (nullable instancetype)initWithProvider:(NSString *)provider NS_UNAVAILABLE;
  23. @end
  24. @implementation FIRGoogleAuthCredential {
  25. NSString *_IDToken;
  26. NSString *_accessToken;
  27. }
  28. - (nullable instancetype)initWithProvider:(NSString *)provider {
  29. [FIRAuthExceptionUtils raiseMethodNotImplementedExceptionWithReason:
  30. @"Please call the designated initializer."];
  31. return nil;
  32. }
  33. - (nullable instancetype)initWithIDToken:(NSString *)IDToken accessToken:(NSString *)accessToken {
  34. self = [super initWithProvider:FIRGoogleAuthProviderID];
  35. if (self) {
  36. _IDToken = [IDToken copy];
  37. _accessToken = [accessToken copy];
  38. }
  39. return self;
  40. }
  41. - (void)prepareVerifyAssertionRequest:(FIRVerifyAssertionRequest *)request {
  42. request.providerIDToken = _IDToken;
  43. request.providerAccessToken = _accessToken;
  44. }
  45. #pragma mark - NSSecureCoding
  46. + (BOOL)supportsSecureCoding {
  47. return YES;
  48. }
  49. - (nullable instancetype)initWithCoder:(NSCoder *)aDecoder {
  50. NSString *IDToken = [aDecoder decodeObjectOfClass:[NSString class] forKey:@"IDToken"];
  51. NSString *accessToken = [aDecoder decodeObjectOfClass:[NSString class] forKey:@"accessToken"];
  52. self = [self initWithIDToken:IDToken accessToken:accessToken];
  53. return self;
  54. }
  55. - (void)encodeWithCoder:(NSCoder *)aCoder {
  56. [aCoder encodeObject:_IDToken forKey:@"IDToken"];
  57. [aCoder encodeObject:_accessToken forKey:@"accessToken"];
  58. }
  59. @end
  60. NS_ASSUME_NONNULL_END