You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
3.4 KiB

6 years ago
  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 "FIRAdditionalUserInfo_Internal.h"
  17. #import "FIRVerifyAssertionResponse.h"
  18. NS_ASSUME_NONNULL_BEGIN
  19. @implementation FIRAdditionalUserInfo
  20. /** @var kProviderIDCodingKey
  21. @brief The key used to encode the providerID property for NSSecureCoding.
  22. */
  23. static NSString *const kProviderIDCodingKey = @"providerID";
  24. /** @var kProfileCodingKey
  25. @brief The key used to encode the profile property for NSSecureCoding.
  26. */
  27. static NSString *const kProfileCodingKey = @"profile";
  28. /** @var kUsernameCodingKey
  29. @brief The key used to encode the username property for NSSecureCoding.
  30. */
  31. static NSString *const kUsernameCodingKey = @"username";
  32. /** @var kNewUserKey
  33. @brief The key used to encode the newUser property for NSSecureCoding.
  34. */
  35. static NSString *const kNewUserKey = @"newUser";
  36. + (nullable instancetype)userInfoWithVerifyAssertionResponse:
  37. (FIRVerifyAssertionResponse *)verifyAssertionResponse {
  38. return [[self alloc] initWithProviderID:verifyAssertionResponse.providerID
  39. profile:verifyAssertionResponse.profile
  40. username:verifyAssertionResponse.username
  41. isNewUser:verifyAssertionResponse.isNewUser];
  42. }
  43. - (nullable instancetype)initWithProviderID:(nullable NSString *)providerID
  44. profile:(nullable NSDictionary<NSString *, NSObject *> *)profile
  45. username:(nullable NSString *)username
  46. isNewUser:(BOOL)isNewUser {
  47. self = [super init];
  48. if (self) {
  49. _providerID = [providerID copy];
  50. if (profile) {
  51. _profile = [[NSDictionary alloc] initWithDictionary:profile copyItems:YES];
  52. }
  53. _username = [username copy];
  54. _newUser = isNewUser;
  55. }
  56. return self;
  57. }
  58. #pragma mark - NSSecureCoding
  59. + (BOOL)supportsSecureCoding {
  60. return YES;
  61. }
  62. - (nullable instancetype)initWithCoder:(NSCoder *)aDecoder {
  63. NSString *providerID =
  64. [aDecoder decodeObjectOfClass:[NSString class] forKey:kProviderIDCodingKey];
  65. NSDictionary<NSString *, NSObject *> *profile =
  66. [aDecoder decodeObjectOfClass:[NSDictionary class] forKey:kProfileCodingKey];
  67. NSString *username = [aDecoder decodeObjectOfClass:[NSString class] forKey:kUsernameCodingKey];
  68. NSNumber *isNewUser = [aDecoder decodeObjectOfClass:[NSNumber class] forKey:kNewUserKey];
  69. return [self initWithProviderID:providerID
  70. profile:profile
  71. username:username
  72. isNewUser:isNewUser.boolValue];
  73. }
  74. - (void)encodeWithCoder:(NSCoder *)aCoder {
  75. [aCoder encodeObject:_providerID forKey:kProviderIDCodingKey];
  76. [aCoder encodeObject:_profile forKey:kProfileCodingKey];
  77. [aCoder encodeObject:_username forKey:kUsernameCodingKey];
  78. [aCoder encodeObject:[NSNumber numberWithBool:_newUser] forKey:kNewUserKey];
  79. }
  80. @end
  81. NS_ASSUME_NONNULL_END