FIRVerifyAssertionResponse.m 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 "FirebaseAuth/Sources/Backend/RPC/FIRVerifyAssertionResponse.h"
  17. NS_ASSUME_NONNULL_BEGIN
  18. @implementation FIRVerifyAssertionResponse
  19. - (BOOL)setWithDictionary:(NSDictionary *)dictionary error:(NSError *_Nullable *_Nullable)error {
  20. _federatedID = [dictionary[@"federatedId"] copy];
  21. _providerID = [dictionary[@"providerId"] copy];
  22. _localID = [dictionary[@"localId"] copy];
  23. _emailRecycled = [dictionary[@"emailRecycled"] boolValue];
  24. _emailVerified = [dictionary[@"emailVerified"] boolValue];
  25. _email = [dictionary[@"email"] copy];
  26. _inputEmail = [dictionary[@"inputEmail"] copy];
  27. _originalEmail = [dictionary[@"originalEmail"] copy];
  28. _oauthRequestToken = [dictionary[@"oauthRequestToken"] copy];
  29. _oauthScope = [dictionary[@"oauthScope"] copy];
  30. _firstName = [dictionary[@"firstName"] copy];
  31. _lastName = [dictionary[@"lastName"] copy];
  32. _fullName = [dictionary[@"fullName"] copy];
  33. _nickName = [dictionary[@"nickName"] copy];
  34. _displayName = [dictionary[@"displayName"] copy];
  35. _IDToken = [dictionary[@"idToken"] copy];
  36. _approximateExpirationDate =
  37. [dictionary[@"expiresIn"] isKindOfClass:[NSString class]]
  38. ? [NSDate dateWithTimeIntervalSinceNow:[dictionary[@"expiresIn"] doubleValue]]
  39. : nil;
  40. _refreshToken = [dictionary[@"refreshToken"] copy];
  41. _isNewUser = [dictionary[@"isNewUser"] boolValue];
  42. id rawUserInfo = dictionary[@"rawUserInfo"];
  43. if ([rawUserInfo isKindOfClass:[NSString class]]) {
  44. NSData *data = [rawUserInfo dataUsingEncoding:NSUTF8StringEncoding];
  45. rawUserInfo = [NSJSONSerialization JSONObjectWithData:data
  46. options:NSJSONReadingMutableLeaves
  47. error:nil];
  48. }
  49. if ([rawUserInfo isKindOfClass:[NSDictionary class]]) {
  50. _profile = [[NSDictionary alloc] initWithDictionary:rawUserInfo copyItems:YES];
  51. }
  52. _username = [dictionary[@"username"] copy];
  53. _action = [dictionary[@"action"] copy];
  54. _language = [dictionary[@"language"] copy];
  55. _timeZone = [dictionary[@"timeZone"] copy];
  56. _photoURL = dictionary[@"photoUrl"] ? [NSURL URLWithString:dictionary[@"photoUrl"]] : nil;
  57. _dateOfBirth = [dictionary[@"dateOfBirth"] copy];
  58. _context = [dictionary[@"context"] copy];
  59. _needConfirmation = [dictionary[@"needConfirmation"] boolValue];
  60. id verifiedProvider = dictionary[@"verifiedProvider"];
  61. if ([verifiedProvider isKindOfClass:[NSString class]]) {
  62. NSData *data = [verifiedProvider dataUsingEncoding:NSUTF8StringEncoding];
  63. verifiedProvider = [NSJSONSerialization JSONObjectWithData:data
  64. options:NSJSONReadingMutableLeaves
  65. error:nil];
  66. }
  67. if ([verifiedProvider isKindOfClass:[NSArray class]]) {
  68. _verifiedProvider = [[NSArray alloc] initWithArray:verifiedProvider copyItems:YES];
  69. }
  70. _oauthIDToken = [dictionary[@"oauthIdToken"] copy];
  71. _oauthExpirationDate =
  72. [dictionary[@"oauthExpireIn"] isKindOfClass:[NSString class]]
  73. ? [NSDate dateWithTimeIntervalSinceNow:[dictionary[@"oauthExpireIn"] doubleValue]]
  74. : nil;
  75. _oauthAccessToken = [dictionary[@"oauthAccessToken"] copy];
  76. _oauthSecretToken = [dictionary[@"oauthTokenSecret"] copy];
  77. _pendingToken = [dictionary[@"pendingToken"] copy];
  78. if (dictionary[@"mfaInfo"] != nil) {
  79. NSMutableArray<FIRAuthProtoMFAEnrollment *> *MFAInfo = [NSMutableArray array];
  80. NSArray *MFAInfoDataArray = dictionary[@"mfaInfo"];
  81. for (NSDictionary *MFAInfoData in MFAInfoDataArray) {
  82. FIRAuthProtoMFAEnrollment *MFAEnrollment =
  83. [[FIRAuthProtoMFAEnrollment alloc] initWithDictionary:MFAInfoData];
  84. [MFAInfo addObject:MFAEnrollment];
  85. }
  86. _MFAInfo = MFAInfo;
  87. }
  88. _MFAPendingCredential = [dictionary[@"mfaPendingCredential"] copy];
  89. return YES;
  90. }
  91. @end
  92. NS_ASSUME_NONNULL_END