FIRRevokeTokenRequest.m 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 requestConfiguration:requestConfiguration];
  57. self.useIdentityPlatform = YES;
  58. if (self) {
  59. // Apple and authorization code are the only provider and token type we support for now.
  60. // Generalize this initializer to accept other providers and token types once supported.
  61. _providerID = @"apple.com";
  62. _tokenType = FIRTokenTypeAuthorizationCode;
  63. _token = token;
  64. _idToken = idToken;
  65. }
  66. return self;
  67. }
  68. - (nullable id)unencodedHTTPRequestBodyWithError:(NSError *__autoreleasing _Nullable *)error {
  69. NSMutableDictionary *postBody = [NSMutableDictionary dictionary];
  70. if (_providerID) {
  71. postBody[kProviderIDKey] = _providerID;
  72. }
  73. if (_tokenType) {
  74. postBody[kTokenTypeKey] = [NSNumber numberWithInteger:_tokenType].stringValue;
  75. }
  76. if (_token) {
  77. postBody[kTokenKey] = _token;
  78. }
  79. if (_idToken) {
  80. postBody[kIDTokenKey] = _idToken;
  81. }
  82. return [postBody copy];
  83. }
  84. @end
  85. NS_ASSUME_NONNULL_END