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.

74 lines
2.1 KiB

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