Sin descripción

FIRAuthTokenResult.m 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright 2018 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 "FIRAuthTokenResult_Internal.h"
  17. NS_ASSUME_NONNULL_BEGIN
  18. /** @var kExpirationDateKey
  19. @brief The key used to encode the expirationDate property for NSSecureCoding.
  20. */
  21. static NSString *const kExpirationDateKey = @"expiratinDate";
  22. /** @var kTokenKey
  23. @brief The key used to encode the token property for NSSecureCoding.
  24. */
  25. static NSString *const kTokenKey = @"token";
  26. /** @var kAuthDateKey
  27. @brief The key used to encode the authDate property for NSSecureCoding.
  28. */
  29. static NSString *const kAuthDateKey = @"authDate";
  30. /** @var kIssuedDateKey
  31. @brief The key used to encode the issuedDate property for NSSecureCoding.
  32. */
  33. static NSString *const kIssuedDateKey = @"issuedDate";
  34. /** @var kSignInProviderKey
  35. @brief The key used to encode the signInProvider property for NSSecureCoding.
  36. */
  37. static NSString *const kSignInProviderKey = @"signInProvider";
  38. /** @var kClaimsKey
  39. @brief The key used to encode the claims property for NSSecureCoding.
  40. */
  41. static NSString *const kClaimsKey = @"claims";
  42. @implementation FIRAuthTokenResult
  43. - (instancetype)initWithToken:(NSString *)token
  44. expirationDate:(NSDate *)expirationDate
  45. authDate:(NSDate *)authDate
  46. issuedAtDate:(NSDate *)issuedAtDate
  47. signInProvider:(NSString *)signInProvider
  48. claims:(NSDictionary *)claims {
  49. self = [super init];
  50. if (self) {
  51. _token = token;
  52. _expirationDate = expirationDate;
  53. _authDate = authDate;
  54. _issuedAtDate = issuedAtDate;
  55. _signInProvider = signInProvider;
  56. _claims = claims;
  57. }
  58. return self;
  59. }
  60. #pragma mark - NSSecureCoding
  61. + (BOOL)supportsSecureCoding {
  62. return YES;
  63. }
  64. - (nullable instancetype)initWithCoder:(NSCoder *)aDecoder {
  65. NSString *token =
  66. [aDecoder decodeObjectOfClass:[NSDate class] forKey:kTokenKey];
  67. NSDate *expirationDate =
  68. [aDecoder decodeObjectOfClass:[NSDate class] forKey:kExpirationDateKey];
  69. NSDate *authDate =
  70. [aDecoder decodeObjectOfClass:[NSDate class] forKey:kAuthDateKey];
  71. NSDate *issuedAtDate =
  72. [aDecoder decodeObjectOfClass:[NSDate class] forKey:kAuthDateKey];
  73. NSString *signInProvider =
  74. [aDecoder decodeObjectOfClass:[NSString class] forKey:kSignInProviderKey];
  75. NSDictionary<NSString *, NSString *> *claims =
  76. [aDecoder decodeObjectOfClass:[NSDictionary<NSString *, NSString *> class] forKey:kClaimsKey];
  77. return [self initWithToken:token
  78. expirationDate:expirationDate
  79. authDate:authDate
  80. issuedAtDate:issuedAtDate
  81. signInProvider:signInProvider
  82. claims:claims];
  83. }
  84. - (void)encodeWithCoder:(NSCoder *)aCoder {
  85. [aCoder encodeObject:_token forKey:kTokenKey];
  86. [aCoder encodeObject:_expirationDate forKey:kExpirationDateKey];
  87. [aCoder encodeObject:_authDate forKey:kAuthDateKey];
  88. [aCoder encodeObject:_issuedAtDate forKey:kIssuedDateKey];
  89. [aCoder encodeObject:_signInProvider forKey:kSignInProviderKey];
  90. [aCoder encodeObject:_claims forKey:kClaimsKey];
  91. }
  92. @end
  93. NS_ASSUME_NONNULL_END