CreateAuthURIRequest.swift 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 kCreateAuthURIEndpoint
  16. @brief The "createAuthUri" endpoint.
  17. */
  18. private let kCreateAuthURIEndpoint = "createAuthUri"
  19. /** @var kProviderIDKey
  20. @brief The key for the "providerId" value in the request.
  21. */
  22. private let kProviderIDKey = "providerId"
  23. /** @var kIdentifierKey
  24. @brief The key for the "identifier" value in the request.
  25. */
  26. private let kIdentifierKey = "identifier"
  27. /** @var kContinueURIKey
  28. @brief The key for the "continueUri" value in the request.
  29. */
  30. private let kContinueURIKey = "continueUri"
  31. /** @var kOpenIDRealmKey
  32. @brief The key for the "openidRealm" value in the request.
  33. */
  34. private let kOpenIDRealmKey = "openidRealm"
  35. /** @var kClientIDKey
  36. @brief The key for the "clientId" value in the request.
  37. */
  38. private let kClientIDKey = "clientId"
  39. /** @var kContextKey
  40. @brief The key for the "context" value in the request.
  41. */
  42. private let kContextKey = "context"
  43. /** @var kAppIDKey
  44. @brief The key for the "appId" value in the request.
  45. */
  46. private let kAppIDKey = "appId"
  47. /** @var kTenantIDKey
  48. @brief The key for the tenant id value in the request.
  49. */
  50. private let kTenantIDKey = "tenantId"
  51. /** @class FIRCreateAuthURIRequest
  52. @brief Represents the parameters for the createAuthUri endpoint.
  53. @see https://developers.google.com/identity/toolkit/web/reference/relyingparty/createAuthUri
  54. */
  55. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  56. @objc(FIRCreateAuthURIRequest) public class CreateAuthURIRequest: IdentityToolkitRequest,
  57. AuthRPCRequest {
  58. /** @property identifier
  59. @brief The email or federated ID of the user.
  60. */
  61. @objc public let identifier: String
  62. /** @property continueURI
  63. @brief The URI to which the IDP redirects the user after the federated login flow.
  64. */
  65. @objc public let continueURI: String
  66. /** @property openIDRealm
  67. @brief Optional realm for OpenID protocol. The sub string "scheme://domain:port" of the param
  68. "continueUri" is used if this is not set.
  69. */
  70. @objc public var openIDRealm: String?
  71. /** @property providerID
  72. @brief The IdP ID. For white listed IdPs it's a short domain name e.g. google.com, aol.com,
  73. live.net and yahoo.com. For other OpenID IdPs it's the OP identifier.
  74. */
  75. @objc public var providerID: String?
  76. /** @property clientID
  77. @brief The relying party OAuth client ID.
  78. */
  79. @objc public var clientID: String?
  80. /** @property context
  81. @brief The opaque value used by the client to maintain context info between the authentication
  82. request and the IDP callback.
  83. */
  84. @objc public var context: String?
  85. /** @property appID
  86. @brief The iOS client application's bundle identifier.
  87. */
  88. @objc public var appID: String?
  89. /** @var response
  90. @brief The corresponding response for this request
  91. */
  92. @objc public var response: AuthRPCResponse = CreateAuthURIResponse()
  93. @objc public init(identifier: String, continueURI: String,
  94. requestConfiguration: AuthRequestConfiguration) {
  95. self.identifier = identifier
  96. self.continueURI = continueURI
  97. super.init(endpoint: kCreateAuthURIEndpoint, requestConfiguration: requestConfiguration)
  98. }
  99. public func unencodedHTTPRequestBody() throws -> [String: AnyHashable] {
  100. var postBody: [String: AnyHashable] = [
  101. kIdentifierKey: identifier,
  102. kContinueURIKey: continueURI,
  103. ]
  104. if let providerID = providerID {
  105. postBody[kProviderIDKey] = providerID
  106. }
  107. if let openIDRealm = openIDRealm {
  108. postBody[kOpenIDRealmKey] = openIDRealm
  109. }
  110. if let clientID = clientID {
  111. postBody[kClientIDKey] = clientID
  112. }
  113. if let context = context {
  114. postBody[kContextKey] = context
  115. }
  116. if let appID = appID {
  117. postBody[kAppIDKey] = appID
  118. }
  119. if let tenantID = tenantID {
  120. postBody[kTenantIDKey] = tenantID
  121. }
  122. return postBody
  123. }
  124. }