SignUpNewUserRequest.swift 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. class SignUpNewUserRequest: IdentityToolkitRequest, AuthRPCRequest {
  41. typealias Response = SignUpNewUserResponse
  42. /** @property email
  43. @brief The email of the user.
  44. */
  45. var email: String?
  46. /** @property password
  47. @brief The password inputed by the user.
  48. */
  49. var password: String?
  50. /** @property displayName
  51. @brief The password inputed by the user.
  52. */
  53. 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. var returnSecureToken: Bool = true
  59. init(requestConfiguration: AuthRequestConfiguration) {
  60. super.init(endpoint: kSignupNewUserEndpoint, requestConfiguration: requestConfiguration)
  61. }
  62. /** @fn initWithAPIKey:email:password:displayName:requestConfiguration
  63. @brief Designated initializer.
  64. @param requestConfiguration An object containing configurations to be added to the request.
  65. */
  66. init(email: String?,
  67. password: String?,
  68. displayName: String?,
  69. requestConfiguration: AuthRequestConfiguration) {
  70. self.email = email
  71. self.password = password
  72. self.displayName = displayName
  73. super.init(endpoint: kSignupNewUserEndpoint, requestConfiguration: requestConfiguration)
  74. }
  75. func unencodedHTTPRequestBody() throws -> [String: AnyHashable] {
  76. var postBody: [String: AnyHashable] = [:]
  77. if let email {
  78. postBody[kEmailKey] = email
  79. }
  80. if let password {
  81. postBody[kPasswordKey] = password
  82. }
  83. if let displayName {
  84. postBody[kDisplayNameKey] = displayName
  85. }
  86. if returnSecureToken {
  87. postBody[kReturnSecureTokenKey] = true
  88. }
  89. if let tenantID {
  90. postBody[kTenantIDKey] = tenantID
  91. }
  92. return postBody
  93. }
  94. }