No Description

FIROAuthCredential.m 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 "FIROAuthCredential.h"
  17. #import "FIRAuthCredential_Internal.h"
  18. #import "FIRAuthExceptionUtils.h"
  19. #import "FIROAuthCredential_Internal.h"
  20. #import "FIRVerifyAssertionRequest.h"
  21. NS_ASSUME_NONNULL_BEGIN
  22. @interface FIROAuthCredential ()
  23. - (nullable instancetype)initWithProvider:(NSString *)provider NS_UNAVAILABLE;
  24. @end
  25. @implementation FIROAuthCredential
  26. - (nullable instancetype)initWithProvider:(NSString *)provider {
  27. [FIRAuthExceptionUtils raiseMethodNotImplementedExceptionWithReason:
  28. @"Please call the designated initializer."];
  29. return nil;
  30. }
  31. - (instancetype)initWithProviderID:(NSString *)providerID
  32. IDToken:(nullable NSString *)IDToken
  33. accessToken:(nullable NSString *)accessToken
  34. pendingToken:(nullable NSString *)pendingToken {
  35. self = [super initWithProvider:providerID];
  36. if (self) {
  37. _IDToken = IDToken;
  38. _accessToken = accessToken;
  39. _pendingToken = pendingToken;
  40. }
  41. return self;
  42. }
  43. - (instancetype)initWithProviderID:(NSString *)providerID
  44. sessionID:(NSString *)sessionID
  45. OAuthResponseURLString:(NSString *)OAuthResponseURLString {
  46. self = [self initWithProviderID:providerID IDToken:nil accessToken:nil pendingToken:nil];
  47. if (self) {
  48. _OAuthResponseURLString = OAuthResponseURLString;
  49. _sessionID = sessionID;
  50. }
  51. return self;
  52. }
  53. - (void)prepareVerifyAssertionRequest:(FIRVerifyAssertionRequest *)request {
  54. request.providerIDToken = _IDToken;
  55. request.providerAccessToken = _accessToken;
  56. }
  57. #pragma mark - NSSecureCoding
  58. + (BOOL)supportsSecureCoding {
  59. return YES;
  60. }
  61. - (nullable instancetype)initWithCoder:(NSCoder *)aDecoder {
  62. NSString *IDToken = [aDecoder decodeObjectOfClass:[NSString class] forKey:@"IDToken"];
  63. NSString *accessToken = [aDecoder decodeObjectOfClass:[NSString class] forKey:@"accessToken"];
  64. NSString *pendingToken = [aDecoder decodeObjectOfClass:[NSString class] forKey:@"pendingToken"];
  65. self = [self initWithProviderID:self.provider
  66. IDToken:IDToken
  67. accessToken:accessToken
  68. pendingToken:pendingToken];
  69. return self;
  70. }
  71. - (void)encodeWithCoder:(NSCoder *)aCoder {
  72. [aCoder encodeObject:self.IDToken forKey:@"IDToken"];
  73. [aCoder encodeObject:self.accessToken forKey:@"accessToken"];
  74. [aCoder encodeObject:self.pendingToken forKey:@"pendingToken"];
  75. }
  76. @end
  77. NS_ASSUME_NONNULL_END