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.

76 lines
3.5 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 "FIRVerifyAssertionResponse.h"
  17. @implementation FIRVerifyAssertionResponse
  18. - (BOOL)setWithDictionary:(NSDictionary *)dictionary
  19. 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 = [dictionary[@"expiresIn"] isKindOfClass:[NSString class]] ?
  37. [NSDate dateWithTimeIntervalSinceNow:[dictionary[@"expiresIn"] doubleValue]] : nil;
  38. _refreshToken = [dictionary[@"refreshToken"] copy];
  39. _isNewUser = [dictionary[@"isNewUser"] boolValue];
  40. id rawUserInfo = dictionary[@"rawUserInfo"];
  41. if ([rawUserInfo isKindOfClass:[NSString class]]) {
  42. NSData *data = [rawUserInfo dataUsingEncoding:NSUTF8StringEncoding];
  43. rawUserInfo = [NSJSONSerialization JSONObjectWithData:data
  44. options:NSJSONReadingMutableLeaves
  45. error:nil];
  46. }
  47. if ([rawUserInfo isKindOfClass:[NSDictionary class]]) {
  48. _profile = [[NSDictionary alloc] initWithDictionary:rawUserInfo
  49. copyItems:YES];
  50. }
  51. _username = [dictionary[@"username"] copy];
  52. _action = [dictionary[@"action"] copy];
  53. _language = [dictionary[@"language"] copy];
  54. _timeZone = [dictionary[@"timeZone"] copy];
  55. _photoURL = dictionary[@"photoUrl"] ? [NSURL URLWithString:dictionary[@"photoUrl"]] : nil;
  56. _dateOfBirth = [dictionary[@"dateOfBirth"] copy];
  57. _context = [dictionary[@"context"] copy];
  58. _needConfirmation = [dictionary[@"needConfirmation"] boolValue];
  59. id verifiedProvider = dictionary[@"verifiedProvider"];
  60. if ([verifiedProvider isKindOfClass:[NSString class]]) {
  61. NSData *data = [verifiedProvider dataUsingEncoding:NSUTF8StringEncoding];
  62. verifiedProvider = [NSJSONSerialization JSONObjectWithData:data
  63. options:NSJSONReadingMutableLeaves
  64. error:nil];
  65. }
  66. if ([verifiedProvider isKindOfClass:[NSArray class]]) {
  67. _verifiedProvider = [[NSArray alloc] initWithArray:verifiedProvider
  68. copyItems:YES];
  69. }
  70. return YES;
  71. }
  72. @end