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.

113 lines
4.3 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 <Foundation/Foundation.h>
  17. #import "FIRAuthRPCRequest.h"
  18. NS_ASSUME_NONNULL_BEGIN
  19. /** @enum FIRSecureTokenRequestGrantType
  20. @brief Represents the possible grant types for a token request.
  21. */
  22. typedef NS_ENUM(NSUInteger, FIRSecureTokenRequestGrantType) {
  23. /** @var FIRSecureTokenRequestGrantTypeAuthorizationCode
  24. @brief Indicates an authorization code request.
  25. @remarks Exchanges a Gitkit "ID Token" for an STS Access Token and Refresh Token.
  26. */
  27. FIRSecureTokenRequestGrantTypeAuthorizationCode,
  28. /** @var FIRSecureTokenRequestGrantTypeRefreshToken
  29. @brief Indicates an refresh token request.
  30. @remarks Uses an existing Refresh Token to create a new Access Token.
  31. */
  32. FIRSecureTokenRequestGrantTypeRefreshToken,
  33. };
  34. /** @class FIRSecureTokenRequest
  35. @brief Represents the parameters for the token endpoint.
  36. */
  37. @interface FIRSecureTokenRequest : NSObject <FIRAuthRPCRequest>
  38. /** @property grantType
  39. @brief The type of grant requested.
  40. @see FIRSecureTokenRequestGrantType
  41. */
  42. @property(nonatomic, assign, readonly) FIRSecureTokenRequestGrantType grantType;
  43. /** @property scope
  44. @brief The scopes requested (a comma-delimited list of scope strings.)
  45. */
  46. @property(nonatomic, copy, readonly, nullable) NSString *scope;
  47. /** @property refreshToken
  48. @brief The client's refresh token.
  49. */
  50. @property(nonatomic, copy, readonly, nullable) NSString *refreshToken;
  51. /** @property code
  52. @brief The client's authorization code (legacy Gitkit "ID Token").
  53. */
  54. @property(nonatomic, copy, readonly, nullable) NSString *code;
  55. /** @property APIKey
  56. @brief The client's API Key.
  57. */
  58. @property(nonatomic, copy, readonly) NSString *APIKey;
  59. /** @fn authCodeRequestWithCode:
  60. @brief Creates an authorization code request with the given code (legacy Gitkit "ID Token").
  61. @param code The authorization code (legacy Gitkit "ID Token").
  62. @param requestConfiguration An object containing configurations to be added to the request.
  63. @return An authorization request.
  64. */
  65. + (FIRSecureTokenRequest *)authCodeRequestWithCode:(NSString *)code
  66. requestConfiguration:(FIRAuthRequestConfiguration *)
  67. requestConfiguration;
  68. /** @fn refreshRequestWithCode:
  69. @brief Creates a refresh request with the given refresh token.
  70. @param refreshToken The refresh token.
  71. @param requestConfiguration An object containing configurations to be added to the request.
  72. @return A refresh request.
  73. */
  74. + (FIRSecureTokenRequest *)refreshRequestWithRefreshToken:(NSString *)refreshToken
  75. requestConfiguration:(FIRAuthRequestConfiguration *)
  76. requestConfiguration;
  77. /** @fn init
  78. @brief Please use initWithGrantType:scope:refreshToken:code:
  79. */
  80. - (instancetype)init NS_UNAVAILABLE;
  81. /** @fn initWithGrantType:scope:refreshToken:code:APIKey:
  82. @brief Designated initializer.
  83. @param grantType The type of request.
  84. @param scope The scopes requested.
  85. @param refreshToken The client's refresh token (for refresh requests.)
  86. @param code The client's authorization code (Gitkit ID Token) (for authorization code requests.)
  87. @param requestConfiguration An object containing configurations to be added to the request.
  88. */
  89. - (nullable instancetype)initWithGrantType:(FIRSecureTokenRequestGrantType)grantType
  90. scope:(nullable NSString *)scope
  91. refreshToken:(nullable NSString *)refreshToken
  92. code:(nullable NSString *)code
  93. requestConfiguration:(FIRAuthRequestConfiguration *)requestConfiguration
  94. NS_DESIGNATED_INITIALIZER;
  95. @end
  96. NS_ASSUME_NONNULL_END