FIRRevokeTokenRequest.m 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright 2023 Google LLC
  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/FIRRevokeTokenRequest.h"
  17. NS_ASSUME_NONNULL_BEGIN
  18. /** @var kRevokeTokenEndpoint
  19. @brief The endpoint for the revokeToken request.
  20. */
  21. static NSString *const kRevokeTokenEndpoint = @"accounts:revokeToken";
  22. /** @var kProviderIDKey
  23. @brief The key for the provider that issued the token to revoke.
  24. */
  25. static NSString *const kProviderIDKey = @"providerId";
  26. /** @var kTokenTypeKey
  27. @brief The key for the type of the token to revoke.
  28. */
  29. static NSString *const kTokenTypeKey = @"tokenType";
  30. /** @var kTokenKey
  31. @brief The key for the token to be revoked.
  32. */
  33. static NSString *const kTokenKey = @"token";
  34. /** @var kIDTokenKey
  35. @brief The key for the ID Token associated with this credential.
  36. */
  37. static NSString *const kIDTokenKey = @"idToken";
  38. typedef NS_ENUM(NSInteger, FIRTokenType) {
  39. /** Indicates that the token type is unspecified.
  40. */
  41. FIRTokenTypeUnspecified = 0,
  42. /** Indicates that the token type is refresh token.
  43. */
  44. FIRTokenTypeRefreshToken = 1,
  45. /** Indicates that the token type is access token.
  46. */
  47. FIRTokenTypeAccessToken = 2,
  48. /** Indicates that the token type is authorization code.
  49. */
  50. FIRTokenTypeAuthorizationCode = 3,
  51. };
  52. @implementation FIRRevokeTokenRequest
  53. - (nullable instancetype)initWithToken:(NSString *)token
  54. idToken:(NSString *)idToken
  55. requestConfiguration:(FIRAuthRequestConfiguration *)requestConfiguration {
  56. self = [super initWithEndpoint:kRevokeTokenEndpoint
  57. requestConfiguration:requestConfiguration
  58. useIdentityPlatform:YES
  59. useStaging:NO];
  60. if (self) {
  61. // Apple and authorization code are the only provider and token type we support for now.
  62. // Generalize this initializer to accept other providers and token types once supported.
  63. _providerID = @"apple.com";
  64. _tokenType = FIRTokenTypeAuthorizationCode;
  65. _token = token;
  66. _idToken = idToken;
  67. }
  68. return self;
  69. }
  70. - (nullable id)unencodedHTTPRequestBodyWithError:(NSError *__autoreleasing _Nullable *)error {
  71. NSMutableDictionary *postBody = [NSMutableDictionary dictionary];
  72. if (_providerID) {
  73. postBody[kProviderIDKey] = _providerID;
  74. }
  75. if (_tokenType) {
  76. postBody[kTokenTypeKey] = [NSNumber numberWithInteger:_tokenType].stringValue;
  77. }
  78. if (_token) {
  79. postBody[kTokenKey] = _token;
  80. }
  81. if (_idToken) {
  82. postBody[kIDTokenKey] = _idToken;
  83. }
  84. return [postBody copy];
  85. }
  86. @end
  87. NS_ASSUME_NONNULL_END