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.

70 lines
2.0 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 "FIRSecureTokenResponse.h"
  17. #import "FIRAuthErrorUtils.h"
  18. /** @var kExpiresInKey
  19. @brief The key for the number of seconds till the access token expires.
  20. */
  21. static NSString *const kExpiresInKey = @"expires_in";
  22. /** @var kRefreshTokenKey
  23. @brief The key for the refresh token.
  24. */
  25. static NSString *const kRefreshTokenKey = @"refresh_token";
  26. /** @var kAccessTokenKey
  27. @brief The key for the access token.
  28. */
  29. static NSString *const kAccessTokenKey = @"access_token";
  30. /** @var kIDTokenKey
  31. @brief The key for the "id_token" value in the response.
  32. */
  33. static NSString *const kIDTokenKey = @"id_token";
  34. @implementation FIRSecureTokenResponse
  35. - (nullable NSString *)expectedKind {
  36. return nil;
  37. }
  38. - (BOOL)setWithDictionary:(NSDictionary *)dictionary
  39. error:(NSError *_Nullable *_Nullable)error {
  40. _refreshToken = dictionary[kRefreshTokenKey];
  41. _accessToken = dictionary[kAccessTokenKey];
  42. _IDToken = dictionary[kIDTokenKey];
  43. if (!_accessToken.length) {
  44. if (error) {
  45. *error = [FIRAuthErrorUtils unexpectedResponseWithDeserializedResponse:dictionary];
  46. }
  47. return NO;
  48. }
  49. id expiresIn = dictionary[kExpiresInKey];
  50. if (![expiresIn isKindOfClass:[NSString class]]) {
  51. if (error) {
  52. *error = [FIRAuthErrorUtils unexpectedResponseWithDeserializedResponse:dictionary];
  53. }
  54. return NO;
  55. }
  56. _approximateExpirationDate = [NSDate dateWithTimeIntervalSinceNow:[expiresIn doubleValue]];
  57. return YES;
  58. }
  59. @end