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.

86 lines
3.9 KiB

6 years ago
6 years ago
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. NS_ASSUME_NONNULL_BEGIN
  18. @implementation FIRVerifyAssertionResponse
  19. - (BOOL)setWithDictionary:(NSDictionary *)dictionary
  20. error:(NSError *_Nullable *_Nullable)error {
  21. _federatedID = [dictionary[@"federatedId"] copy];
  22. _providerID = [dictionary[@"providerId"] copy];
  23. _localID = [dictionary[@"localId"] copy];
  24. _emailRecycled = [dictionary[@"emailRecycled"] boolValue];
  25. _emailVerified = [dictionary[@"emailVerified"] boolValue];
  26. _email = [dictionary[@"email"] copy];
  27. _inputEmail = [dictionary[@"inputEmail"] copy];
  28. _originalEmail = [dictionary[@"originalEmail"] copy];
  29. _oauthRequestToken = [dictionary[@"oauthRequestToken"] copy];
  30. _oauthScope = [dictionary[@"oauthScope"] copy];
  31. _firstName = [dictionary[@"firstName"] copy];
  32. _lastName = [dictionary[@"lastName"] copy];
  33. _fullName = [dictionary[@"fullName"] copy];
  34. _nickName = [dictionary[@"nickName"] copy];
  35. _displayName = [dictionary[@"displayName"] copy];
  36. _IDToken = [dictionary[@"idToken"] copy];
  37. _approximateExpirationDate = [dictionary[@"expiresIn"] isKindOfClass:[NSString class]] ?
  38. [NSDate dateWithTimeIntervalSinceNow:[dictionary[@"expiresIn"] doubleValue]] : nil;
  39. _refreshToken = [dictionary[@"refreshToken"] copy];
  40. _isNewUser = [dictionary[@"isNewUser"] boolValue];
  41. id rawUserInfo = dictionary[@"rawUserInfo"];
  42. if ([rawUserInfo isKindOfClass:[NSString class]]) {
  43. NSData *data = [rawUserInfo dataUsingEncoding:NSUTF8StringEncoding];
  44. rawUserInfo = [NSJSONSerialization JSONObjectWithData:data
  45. options:NSJSONReadingMutableLeaves
  46. error:nil];
  47. }
  48. if ([rawUserInfo isKindOfClass:[NSDictionary class]]) {
  49. _profile = [[NSDictionary alloc] initWithDictionary:rawUserInfo
  50. 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
  69. copyItems:YES];
  70. }
  71. _oauthIDToken = [dictionary[@"oauthIdToken"] copy];
  72. _oauthExpirationDate = [dictionary[@"oauthExpireIn"] isKindOfClass:[NSString class]] ?
  73. [NSDate dateWithTimeIntervalSinceNow:[dictionary[@"oauthExpireIn"] doubleValue]] : nil;
  74. _oauthAccessToken = [dictionary[@"oauthAccessToken"] copy];
  75. _oauthSecretToken = [dictionary[@"oauthTokenSecret"] copy];
  76. _pendingToken = [dictionary[@"pendingToken"] copy];
  77. return YES;
  78. }
  79. @end
  80. NS_ASSUME_NONNULL_END