SignUpNewUserRequest.swift 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // Copyright 2023 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. import Foundation
  15. /** @var kSignupNewUserEndpoint
  16. @brief The "SingupNewUserEndpoint" endpoint.
  17. */
  18. private let kSignupNewUserEndpoint = "signupNewUser"
  19. /** @var kEmailKey
  20. @brief The key for the "email" value in the request.
  21. */
  22. private let kEmailKey = "email"
  23. /** @var kPasswordKey
  24. @brief The key for the "password" value in the request.
  25. */
  26. private let kPasswordKey = "password"
  27. /** @var kDisplayNameKey
  28. @brief The key for the "kDisplayName" value in the request.
  29. */
  30. private let kDisplayNameKey = "displayName"
  31. /** @var kReturnSecureTokenKey
  32. @brief The key for the "returnSecureToken" value in the request.
  33. */
  34. private let kReturnSecureTokenKey = "returnSecureToken"
  35. /** @var kTenantIDKey
  36. @brief The key for the tenant id value in the request.
  37. */
  38. private let kTenantIDKey = "tenantId"
  39. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  40. @objc(FIRSignUpNewUserRequest) public class SignUpNewUserRequest: IdentityToolkitRequest,
  41. AuthRPCRequest {
  42. /** @property email
  43. @brief The email of the user.
  44. */
  45. @objc public var email: String?
  46. /** @property password
  47. @brief The password inputed by the user.
  48. */
  49. @objc public var password: String?
  50. /** @property displayName
  51. @brief The password inputed by the user.
  52. */
  53. @objc public var displayName: String?
  54. /** @property returnSecureToken
  55. @brief Whether the response should return access token and refresh token directly.
  56. @remarks The default value is @c YES .
  57. */
  58. @objc public var returnSecureToken: Bool = true
  59. /** @var response
  60. @brief The corresponding response for this request
  61. */
  62. @objc public var response: AuthRPCResponse = SignUpNewUserResponse()
  63. @objc public init(requestConfiguration: AuthRequestConfiguration) {
  64. super.init(endpoint: kSignupNewUserEndpoint, requestConfiguration: requestConfiguration)
  65. }
  66. /** @fn initWithAPIKey:email:password:displayName:requestConfiguration
  67. @brief Designated initializer.
  68. @param requestConfiguration An object containing configurations to be added to the request.
  69. */
  70. @objc public init(email: String?,
  71. password: String?,
  72. displayName: String?,
  73. requestConfiguration: AuthRequestConfiguration) {
  74. self.email = email
  75. self.password = password
  76. self.displayName = displayName
  77. super.init(endpoint: kSignupNewUserEndpoint, requestConfiguration: requestConfiguration)
  78. }
  79. public func unencodedHTTPRequestBody() throws -> [String: AnyHashable] {
  80. var postBody: [String: AnyHashable] = [:]
  81. if let email {
  82. postBody[kEmailKey] = email
  83. }
  84. if let password {
  85. postBody[kPasswordKey] = password
  86. }
  87. if let displayName {
  88. postBody[kDisplayNameKey] = displayName
  89. }
  90. if returnSecureToken {
  91. postBody[kReturnSecureTokenKey] = true
  92. }
  93. if let tenantID {
  94. postBody[kTenantIDKey] = tenantID
  95. }
  96. return postBody
  97. }
  98. }