OIDTokenRequest.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*! @file OIDTokenRequest.h
  2. @brief AppAuth iOS SDK
  3. @copyright
  4. Copyright 2015 Google Inc. All Rights Reserved.
  5. @copydetails
  6. Licensed under the Apache License, Version 2.0 (the "License");
  7. you may not use this file except in compliance with the License.
  8. You may obtain a copy of the License at
  9. http://www.apache.org/licenses/LICENSE-2.0
  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. // This file only declares string constants useful for constructing a @c OIDTokenRequest, so it is
  18. // imported here for convenience.
  19. #import "OIDGrantTypes.h"
  20. @class OIDAuthorizationResponse;
  21. @class OIDServiceConfiguration;
  22. NS_ASSUME_NONNULL_BEGIN
  23. /*! @brief Represents a token request.
  24. @see https://tools.ietf.org/html/rfc6749#section-3.2
  25. @see https://tools.ietf.org/html/rfc6749#section-4.1.3
  26. */
  27. @interface OIDTokenRequest : NSObject <NSCopying, NSSecureCoding>
  28. /*! @brief The service's configuration.
  29. @remarks This configuration specifies how to connect to a particular OAuth provider.
  30. Configurations may be created manually, or via an OpenID Connect Discovery Document.
  31. */
  32. @property(nonatomic, readonly) OIDServiceConfiguration *configuration;
  33. /*! @brief The type of token being sent to the token endpoint, i.e. "authorization_code" for the
  34. authorization code exchange, or "refresh_token" for an access token refresh request.
  35. @remarks grant_type
  36. @see https://tools.ietf.org/html/rfc6749#section-4.1.3
  37. @see https://www.google.com/url?sa=D&q=https%3A%2F%2Ftools.ietf.org%2Fhtml%2Frfc6749%23section-6
  38. */
  39. @property(nonatomic, readonly) NSString *grantType;
  40. /*! @brief The authorization code received from the authorization server.
  41. @remarks code
  42. @see https://tools.ietf.org/html/rfc6749#section-4.1.3
  43. */
  44. @property(nonatomic, readonly, nullable) NSString *authorizationCode;
  45. /*! @brief The client's redirect URI.
  46. @remarks redirect_uri
  47. @see https://tools.ietf.org/html/rfc6749#section-4.1.3
  48. */
  49. @property(nonatomic, readonly, nullable) NSURL *redirectURL;
  50. /*! @brief The client identifier.
  51. @remarks client_id
  52. @see https://tools.ietf.org/html/rfc6749#section-4.1.3
  53. */
  54. @property(nonatomic, readonly) NSString *clientID;
  55. /*! @brief The client secret.
  56. @remarks client_secret
  57. @see https://tools.ietf.org/html/rfc6749#section-2.3.1
  58. */
  59. @property(nonatomic, readonly, nullable) NSString *clientSecret;
  60. /*! @brief The value of the scope parameter is expressed as a list of space-delimited,
  61. case-sensitive strings.
  62. @remarks scope
  63. @see https://tools.ietf.org/html/rfc6749#section-3.3
  64. */
  65. @property(nonatomic, readonly, nullable) NSString *scope;
  66. /*! @brief The refresh token, which can be used to obtain new access tokens using the same
  67. authorization grant.
  68. @remarks refresh_token
  69. @see https://tools.ietf.org/html/rfc6749#section-5.1
  70. */
  71. @property(nonatomic, readonly, nullable) NSString *refreshToken;
  72. /*! @brief The PKCE code verifier used to redeem the authorization code.
  73. @remarks code_verifier
  74. @see https://tools.ietf.org/html/rfc7636#section-4.3
  75. */
  76. @property(nonatomic, readonly, nullable) NSString *codeVerifier;
  77. /*! @brief The client's additional token request parameters.
  78. */
  79. @property(nonatomic, readonly, nullable) NSDictionary<NSString *, NSString *> *additionalParameters;
  80. /*! @internal
  81. @brief Unavailable. Please use
  82. initWithConfiguration:grantType:code:redirectURL:clientID:additionalParameters:.
  83. */
  84. - (instancetype)init NS_UNAVAILABLE;
  85. /*! @param configuration The service's configuration.
  86. @param grantType the type of token being sent to the token endpoint, i.e. "authorization_code"
  87. for the authorization code exchange, or "refresh_token" for an access token refresh request.
  88. @see OIDGrantTypes.h
  89. @param code The authorization code received from the authorization server.
  90. @param redirectURL The client's redirect URI.
  91. @param clientID The client identifier.
  92. @param clientSecret The client secret.
  93. @param scopes An array of scopes to combine into a single scope string per the OAuth2 spec.
  94. @param refreshToken The refresh token.
  95. @param codeVerifier The PKCE code verifier.
  96. @param additionalParameters The client's additional token request parameters.
  97. */
  98. - (instancetype)initWithConfiguration:(OIDServiceConfiguration *)configuration
  99. grantType:(NSString *)grantType
  100. authorizationCode:(nullable NSString *)code
  101. redirectURL:(nullable NSURL *)redirectURL
  102. clientID:(NSString *)clientID
  103. clientSecret:(nullable NSString *)clientSecret
  104. scopes:(nullable NSArray<NSString *> *)scopes
  105. refreshToken:(nullable NSString *)refreshToken
  106. codeVerifier:(nullable NSString *)codeVerifier
  107. additionalParameters:(nullable NSDictionary<NSString *, NSString *> *)additionalParameters;
  108. /*! @brief Designated initializer.
  109. @param configuration The service's configuration.
  110. @param grantType the type of token being sent to the token endpoint, i.e. "authorization_code"
  111. for the authorization code exchange, or "refresh_token" for an access token refresh request.
  112. @see OIDGrantTypes.h
  113. @param code The authorization code received from the authorization server.
  114. @param redirectURL The client's redirect URI.
  115. @param clientID The client identifier.
  116. @param clientSecret The client secret.
  117. @param scope The value of the scope parameter is expressed as a list of space-delimited,
  118. case-sensitive strings.
  119. @param refreshToken The refresh token.
  120. @param codeVerifier The PKCE code verifier.
  121. @param additionalParameters The client's additional token request parameters.
  122. */
  123. - (instancetype)initWithConfiguration:(OIDServiceConfiguration *)configuration
  124. grantType:(NSString *)grantType
  125. authorizationCode:(nullable NSString *)code
  126. redirectURL:(nullable NSURL *)redirectURL
  127. clientID:(NSString *)clientID
  128. clientSecret:(nullable NSString *)clientSecret
  129. scope:(nullable NSString *)scope
  130. refreshToken:(nullable NSString *)refreshToken
  131. codeVerifier:(nullable NSString *)codeVerifier
  132. additionalParameters:(nullable NSDictionary<NSString *, NSString *> *)additionalParameters
  133. NS_DESIGNATED_INITIALIZER;
  134. /*! @brief Constructs an @c NSURLRequest representing the token request.
  135. @return An @c NSURLRequest representing the token request.
  136. */
  137. - (NSURLRequest *)URLRequest;
  138. @end
  139. NS_ASSUME_NONNULL_END