FIRSecureTokenResponse.m 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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/FIRSecureTokenResponse.h"
  17. #import "FirebaseAuth/Sources/Utilities/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 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
  60. NS_ASSUME_NONNULL_END