OAuthProvider.swift 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  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 CommonCrypto
  15. import Foundation
  16. /// Utility class for constructing OAuth Sign In credentials.
  17. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  18. @objc(FIROAuthProvider) open class OAuthProvider: NSObject, FederatedAuthProvider {
  19. @objc public static let id = "OAuth"
  20. /// Array used to configure the OAuth scopes.
  21. @objc open var scopes: [String]?
  22. /// Dictionary used to configure the OAuth custom parameters.
  23. @objc open var customParameters: [String: String]?
  24. /// The provider ID indicating the specific OAuth provider this OAuthProvider instance represents.
  25. @objc public let providerID: String
  26. /// An instance of OAuthProvider corresponding to the given provider ID.
  27. /// - Parameters:
  28. /// - providerID: The provider ID of the IDP for which this auth provider instance will be
  29. /// configured.
  30. /// - Returns: An instance of OAuthProvider corresponding to the specified provider ID.
  31. #if !FIREBASE_CI
  32. @available(
  33. swift,
  34. deprecated: 0.01,
  35. message: "Use `provider(providerID: AuthProviderID) -> OAuthProvider` instead."
  36. )
  37. #endif // !FIREBASE_CI
  38. @objc(providerWithProviderID:) open class func provider(providerID: String) -> OAuthProvider {
  39. return OAuthProvider(providerID: providerID, auth: Auth.auth())
  40. }
  41. /// An instance of OAuthProvider corresponding to the given provider ID.
  42. /// - Parameters:
  43. /// - providerID: The provider ID of the IDP for which this auth provider instance will be
  44. /// configured.
  45. /// - Returns: An instance of OAuthProvider corresponding to the specified provider ID.
  46. public class func provider(providerID: AuthProviderID) -> OAuthProvider {
  47. return OAuthProvider(providerID: providerID.rawValue, auth: Auth.auth())
  48. }
  49. /// An instance of OAuthProvider corresponding to the given provider ID and auth instance.
  50. /// - Parameters:
  51. /// - providerID: The provider ID of the IDP for which this auth provider instance will be
  52. /// configured.
  53. /// - auth: The auth instance to be associated with the OAuthProvider instance.
  54. /// - Returns: An instance of OAuthProvider corresponding to the specified provider ID.
  55. #if !FIREBASE_CI
  56. @available(
  57. swift,
  58. deprecated: 0.01,
  59. message: "Use `provider(providerID: AuthProviderID, auth: Auth) -> OAuthProvider` instead."
  60. )
  61. #endif // !FIREBASE_CI
  62. @objc(providerWithProviderID:auth:) open class func provider(providerID: String,
  63. auth: Auth) -> OAuthProvider {
  64. return OAuthProvider(providerID: providerID, auth: auth)
  65. }
  66. /// An instance of OAuthProvider corresponding to the given provider ID and auth instance.
  67. /// - Parameters:
  68. /// - providerID: The provider ID of the IDP for which this auth provider instance will be
  69. /// configured.
  70. /// - auth: The auth instance to be associated with the OAuthProvider instance.
  71. /// - Returns: An instance of OAuthProvider corresponding to the specified provider ID.
  72. public class func provider(providerID: AuthProviderID, auth: Auth) -> OAuthProvider {
  73. return OAuthProvider(providerID: providerID.rawValue, auth: auth)
  74. }
  75. /// Initializes an `OAuthProvider`.
  76. /// - Parameter providerID: The provider ID of the IDP for which this auth provider instance will
  77. /// be configured.
  78. /// - Parameter auth: The auth instance to be associated with the OAuthProvider instance.
  79. /// - Returns: An instance of OAuthProvider corresponding to the specified provider ID.
  80. public init(providerID: String, auth: Auth = Auth.auth()) {
  81. if auth.requestConfiguration.emulatorHostAndPort == nil {
  82. if providerID == FacebookAuthProvider.id {
  83. fatalError("Sign in with Facebook is not supported via generic IDP; the Facebook TOS " +
  84. "dictate that you must use the Facebook iOS SDK for Facebook login.")
  85. }
  86. if providerID == AuthProviderID.apple.rawValue {
  87. fatalError("Sign in with Apple is not supported via generic IDP; You must use the Apple SDK" +
  88. " for Sign in with Apple.")
  89. }
  90. }
  91. self.auth = auth
  92. self.providerID = providerID
  93. scopes = [""]
  94. customParameters = [:]
  95. if let clientID = auth.app?.options.clientID {
  96. let reverseClientIDScheme = clientID.components(separatedBy: ".").reversed()
  97. .joined(separator: ".")
  98. if let urlTypes = auth.mainBundleUrlTypes,
  99. AuthWebUtils.isCallbackSchemeRegistered(forCustomURLScheme: reverseClientIDScheme,
  100. urlTypes: urlTypes) {
  101. callbackScheme = reverseClientIDScheme
  102. usingClientIDScheme = true
  103. return
  104. }
  105. }
  106. usingClientIDScheme = false
  107. if let appID = auth.app?.options.googleAppID {
  108. callbackScheme = "app-\(appID.replacingOccurrences(of: ":", with: "-"))"
  109. } else {
  110. fatalError("Missing googleAppID for constructing callbackScheme")
  111. }
  112. }
  113. /// Initializes an `OAuthProvider`.
  114. /// - Parameter providerID: The provider ID of the IDP for which this auth provider instance will
  115. /// be configured.
  116. /// - Parameter auth: The auth instance to be associated with the OAuthProvider instance.
  117. /// - Returns: An instance of OAuthProvider corresponding to the specified provider ID.
  118. public convenience init(providerID: AuthProviderID, auth: Auth = Auth.auth()) {
  119. self.init(providerID: providerID.rawValue, auth: auth)
  120. }
  121. /// Creates an `AuthCredential` for the OAuth 2 provider identified by provider ID, ID
  122. /// token, and access token.
  123. /// - Parameter providerID: The provider ID associated with the Auth credential being created.
  124. /// - Parameter idToken: The IDToken associated with the Auth credential being created.
  125. /// - Parameter accessToken: The access token associated with the Auth credential be created, if
  126. /// available.
  127. /// - Returns: An AuthCredential for the specified provider ID, ID token and access token.
  128. #if !FIREBASE_CI
  129. @available(
  130. swift,
  131. deprecated: 0.01,
  132. message: "Use `credential(providerID: AuthProviderID, idToken: String, accessToken: String? = nil) -> OAuthCredential` instead."
  133. )
  134. #endif // !FIREBASE_CI
  135. @objc(credentialWithProviderID:IDToken:accessToken:)
  136. public static func credential(withProviderID providerID: String,
  137. idToken: String,
  138. accessToken: String?) -> OAuthCredential {
  139. return OAuthCredential(withProviderID: providerID, idToken: idToken, accessToken: accessToken)
  140. }
  141. /// Creates an `AuthCredential` for the OAuth 2 provider identified by provider ID, ID
  142. /// token, and access token.
  143. /// - Parameter providerID: The provider ID associated with the Auth credential being created.
  144. /// - Parameter idToken: The IDToken associated with the Auth credential being created.
  145. /// - Parameter accessToken: The access token associated with the Auth credential be created, if
  146. /// available.
  147. /// - Returns: An AuthCredential for the specified provider ID, ID token and access token.
  148. public static func credential(providerID: AuthProviderID,
  149. idToken: String,
  150. accessToken: String? = nil) -> OAuthCredential {
  151. return OAuthCredential(
  152. withProviderID: providerID.rawValue,
  153. idToken: idToken,
  154. accessToken: accessToken
  155. )
  156. }
  157. /// Creates an `AuthCredential` for the OAuth 2 provider identified by provider ID, ID
  158. /// token, and access token.
  159. /// - Parameter providerID: The provider ID associated with the Auth credential being created.
  160. /// - Parameter accessToken: The access token associated with the Auth credential be created, if
  161. /// available.
  162. /// - Returns: An AuthCredential for the specified provider ID, ID token and access token.
  163. #if !FIREBASE_CI
  164. @available(
  165. swift,
  166. deprecated: 0.01,
  167. message: "Use `credential(providerID: AuthProviderID, accessToken: String) -> OAuthCredential` instead."
  168. )
  169. #endif // !FIREBASE_CI
  170. @objc(credentialWithProviderID:accessToken:)
  171. public static func credential(withProviderID providerID: String,
  172. accessToken: String) -> OAuthCredential {
  173. return OAuthCredential(withProviderID: providerID, accessToken: accessToken)
  174. }
  175. /// Creates an `AuthCredential` for the OAuth 2 provider identified by provider ID using
  176. /// an ID token.
  177. /// - Parameter providerID: The provider ID associated with the Auth credential being created.
  178. /// - Parameter accessToken: The access token associated with the Auth credential be created
  179. /// - Returns: An AuthCredential.
  180. public static func credential(providerID: AuthProviderID,
  181. accessToken: String) -> OAuthCredential {
  182. return OAuthCredential(withProviderID: providerID.rawValue, accessToken: accessToken)
  183. }
  184. /// Creates an `AuthCredential` for that OAuth 2 provider identified by provider ID, ID
  185. /// token, raw nonce, and access token.
  186. /// - Parameter providerID: The provider ID associated with the Auth credential being created.
  187. /// - Parameter idToken: The IDToken associated with the Auth credential being created.
  188. /// - Parameter rawNonce: The raw nonce associated with the Auth credential being created.
  189. /// - Parameter accessToken: The access token associated with the Auth credential be created.
  190. /// - Returns: An AuthCredential for the specified provider ID, ID token and access token.
  191. #if !FIREBASE_CI
  192. @available(
  193. swift,
  194. deprecated: 0.01,
  195. message: "Use `credential(providerID: AuthProviderID, idToken: String, rawNonce: String, accessToken: String? = nil) -> OAuthCredential` instead."
  196. )
  197. #endif // !FIREBASE_CI
  198. @objc(credentialWithProviderID:IDToken:rawNonce:accessToken:)
  199. public static func credential(withProviderID providerID: String, idToken: String,
  200. rawNonce: String,
  201. accessToken: String) -> OAuthCredential {
  202. return OAuthCredential(
  203. withProviderID: providerID,
  204. idToken: idToken,
  205. rawNonce: rawNonce,
  206. accessToken: accessToken
  207. )
  208. }
  209. /// Creates an `AuthCredential` for that OAuth 2 provider identified by providerID using
  210. /// an ID token and raw nonce.
  211. /// - Parameter providerID: The provider ID associated with the Auth credential being created.
  212. /// - Parameter idToken: The IDToken associated with the Auth credential being created.
  213. /// - Parameter rawNonce: The raw nonce associated with the Auth credential being created.
  214. /// - Returns: An AuthCredential.
  215. #if !FIREBASE_CI
  216. @available(
  217. swift,
  218. deprecated: 0.01,
  219. message: "Use `credential(providerID: AuthProviderID, idToken: String, rawNonce: String, accessToken: String? = nil) -> OAuthCredential` instead."
  220. )
  221. #endif // !FIREBASE_CI
  222. @objc(credentialWithProviderID:IDToken:rawNonce:)
  223. public static func credential(withProviderID providerID: String, idToken: String,
  224. rawNonce: String) -> OAuthCredential {
  225. return OAuthCredential(withProviderID: providerID, idToken: idToken, rawNonce: rawNonce)
  226. }
  227. /// Creates an `AuthCredential` for that OAuth 2 provider identified by provider ID, ID
  228. /// token, raw nonce, and access token.
  229. /// - Parameter providerID: The provider ID associated with the Auth credential being created.
  230. /// - Parameter idToken: The IDToken associated with the Auth credential being created.
  231. /// - Parameter rawNonce: The raw nonce associated with the Auth credential being created.
  232. /// - Parameter accessToken: The access token associated with the Auth credential be created, if
  233. /// available.
  234. /// - Returns: An AuthCredential for the specified provider ID, ID token and access token.
  235. public static func credential(providerID: AuthProviderID, idToken: String,
  236. rawNonce: String,
  237. accessToken: String? = nil) -> OAuthCredential {
  238. return OAuthCredential(
  239. withProviderID: providerID.rawValue,
  240. idToken: idToken,
  241. rawNonce: rawNonce,
  242. accessToken: accessToken
  243. )
  244. }
  245. #if os(iOS)
  246. /// Used to obtain an auth credential via a mobile web flow.
  247. ///
  248. /// This method is available on iOS only.
  249. /// - Parameter uiDelegate: An optional UI delegate used to present the mobile web flow.
  250. /// - Parameter completion: Optionally; a block which is invoked asynchronously on the main
  251. /// thread when the mobile web flow is completed.
  252. open func getCredentialWith(_ uiDelegate: AuthUIDelegate?,
  253. completion: ((AuthCredential?, Error?) -> Void)? = nil) {
  254. guard let urlTypes = auth.mainBundleUrlTypes,
  255. AuthWebUtils.isCallbackSchemeRegistered(forCustomURLScheme: callbackScheme,
  256. urlTypes: urlTypes) else {
  257. fatalError(
  258. "Please register custom URL scheme \(callbackScheme) in the app's Info.plist file."
  259. )
  260. }
  261. kAuthGlobalWorkQueue.async { [weak self] in
  262. guard let self = self else { return }
  263. let eventID = AuthWebUtils.randomString(withLength: 10)
  264. let sessionID = AuthWebUtils.randomString(withLength: 10)
  265. let callbackOnMainThread: ((AuthCredential?, Error?) -> Void) = { credential, error in
  266. if let completion {
  267. DispatchQueue.main.async {
  268. completion(credential, error)
  269. }
  270. }
  271. }
  272. Task {
  273. do {
  274. guard let headfulLiteURL = try await self.getHeadfulLiteUrl(eventID: eventID,
  275. sessionID: sessionID) else {
  276. fatalError(
  277. "FirebaseAuth Internal Error: Both error and headfulLiteURL return are nil"
  278. )
  279. }
  280. let callbackMatcher: (URL?) -> Bool = { callbackURL in
  281. AuthWebUtils.isExpectedCallbackURL(callbackURL,
  282. eventID: eventID,
  283. authType: "signInWithRedirect",
  284. callbackScheme: self.callbackScheme)
  285. }
  286. self.auth.authURLPresenter.present(headfulLiteURL,
  287. uiDelegate: uiDelegate,
  288. callbackMatcher: callbackMatcher) { callbackURL, error in
  289. if let error {
  290. callbackOnMainThread(nil, error)
  291. return
  292. }
  293. guard let callbackURL else {
  294. fatalError("FirebaseAuth Internal Error: Both error and callbackURL return are nil")
  295. }
  296. let (oAuthResponseURLString, error) = self.oAuthResponseForURL(url: callbackURL)
  297. if let error {
  298. callbackOnMainThread(nil, error)
  299. return
  300. }
  301. guard let oAuthResponseURLString else {
  302. fatalError(
  303. "FirebaseAuth Internal Error: Both error and oAuthResponseURLString return are nil"
  304. )
  305. }
  306. let credential = OAuthCredential(withProviderID: self.providerID,
  307. sessionID: sessionID,
  308. OAuthResponseURLString: oAuthResponseURLString)
  309. callbackOnMainThread(credential, nil)
  310. }
  311. } catch {
  312. callbackOnMainThread(nil, error)
  313. }
  314. }
  315. }
  316. }
  317. /// Used to obtain an auth credential via a mobile web flow.
  318. /// This method is available on iOS only.
  319. /// - Parameter uiDelegate: An optional UI delegate used to present the mobile web flow.
  320. @available(iOS 13, tvOS 13, macOS 10.15, watchOS 8, *)
  321. @objc(getCredentialWithUIDelegate:completion:)
  322. @MainActor
  323. open func credential(with uiDelegate: AuthUIDelegate?) async throws -> AuthCredential {
  324. return try await withCheckedThrowingContinuation { continuation in
  325. getCredentialWith(uiDelegate) { credential, error in
  326. if let credential = credential {
  327. continuation.resume(returning: credential)
  328. } else {
  329. continuation.resume(throwing: error!) // TODO: Change to ?? and generate unknown error
  330. }
  331. }
  332. }
  333. }
  334. #endif
  335. /// Creates an `AuthCredential` for the Sign in with Apple OAuth 2 provider identified by ID
  336. /// token, raw nonce, and full name.This method is specific to the Sign in with Apple OAuth 2
  337. /// provider as this provider requires the full name to be passed explicitly.
  338. /// - Parameter idToken: The IDToken associated with the Sign in with Apple Auth credential being
  339. /// created.
  340. /// - Parameter rawNonce: The raw nonce associated with the Sign in with Apple Auth credential
  341. /// being created.
  342. /// - Parameter fullName: The full name associated with the Sign in with Apple Auth credential
  343. /// being created.
  344. /// - Returns: An AuthCredential.
  345. @objc(appleCredentialWithIDToken:rawNonce:fullName:)
  346. public static func appleCredential(withIDToken idToken: String,
  347. rawNonce: String?,
  348. fullName: PersonNameComponents?) -> OAuthCredential {
  349. return OAuthCredential(withProviderID: AuthProviderID.apple.rawValue,
  350. idToken: idToken,
  351. rawNonce: rawNonce,
  352. fullName: fullName)
  353. }
  354. // MARK: - Private Methods
  355. /// Parses the redirected URL and returns a string representation of the OAuth response URL.
  356. /// - Parameter url: The url to be parsed for an OAuth response URL.
  357. /// - Returns: The OAuth response if successful.
  358. private func oAuthResponseForURL(url: URL) -> (String?, Error?) {
  359. var urlQueryItems = AuthWebUtils.dictionary(withHttpArgumentsString: url.query)
  360. if let item = urlQueryItems["deep_link_id"],
  361. let deepLinkURL = URL(string: item) {
  362. urlQueryItems = AuthWebUtils.dictionary(withHttpArgumentsString: deepLinkURL.query)
  363. if let queryItemLink = urlQueryItems["link"] {
  364. return (queryItemLink, nil)
  365. }
  366. }
  367. if let errorData = urlQueryItems["firebaseError"]?.data(using: .utf8) {
  368. do {
  369. let error = try JSONSerialization.jsonObject(with: errorData) as? [String: Any]
  370. let code = (error?["code"] as? String) ?? "missing code"
  371. let message = (error?["message"] as? String) ?? "missing message"
  372. return (nil, AuthErrorUtils.urlResponseError(code: code, message: message))
  373. } catch {
  374. return (nil, AuthErrorUtils.JSONSerializationError(underlyingError: error))
  375. }
  376. }
  377. return (nil, AuthErrorUtils.webSignInUserInteractionFailure(
  378. reason: "SignIn failed with unparseable firebaseError"
  379. ))
  380. }
  381. /// Constructs a URL used for opening a headful-lite flow using a given event
  382. /// ID and session ID.
  383. /// - Parameter eventID: The event ID used for this purpose.
  384. /// - Parameter sessionID: The session ID used when completing the headful lite flow.
  385. /// - Returns: A url.
  386. private func getHeadfulLiteUrl(eventID: String,
  387. sessionID: String) async throws -> URL? {
  388. let authDomain = try await AuthWebUtils
  389. .fetchAuthDomain(withRequestConfiguration: auth.requestConfiguration)
  390. let bundleID = Bundle.main.bundleIdentifier
  391. let clientID = auth.app?.options.clientID
  392. let appID = auth.app?.options.googleAppID
  393. let apiKey = auth.requestConfiguration.apiKey
  394. let tenantID = auth.tenantID
  395. let appCheck = auth.requestConfiguration.appCheck
  396. // TODO: Should we fail if these strings are empty? Only ibi was explicit in ObjC.
  397. var urlArguments = ["apiKey": apiKey,
  398. "authType": "signInWithRedirect",
  399. "ibi": bundleID ?? "",
  400. "sessionId": hash(forString: sessionID),
  401. "v": AuthBackend.authUserAgent(),
  402. "eventId": eventID,
  403. "providerId": providerID]
  404. if usingClientIDScheme {
  405. urlArguments["clientId"] = clientID
  406. } else {
  407. urlArguments["appId"] = appID
  408. }
  409. if let tenantID {
  410. urlArguments["tid"] = tenantID
  411. }
  412. if let scopes, scopes.count > 0 {
  413. urlArguments["scopes"] = scopes.joined(separator: ",")
  414. }
  415. if let customParameters, customParameters.count > 0 {
  416. do {
  417. let customParametersJSONData = try JSONSerialization
  418. .data(withJSONObject: customParameters)
  419. let rawJson = String(decoding: customParametersJSONData, as: UTF8.self)
  420. urlArguments["customParameters"] = rawJson
  421. } catch {
  422. throw AuthErrorUtils.JSONSerializationError(underlyingError: error)
  423. }
  424. }
  425. if let languageCode = auth.requestConfiguration.languageCode {
  426. urlArguments["hl"] = languageCode
  427. }
  428. let argumentsString = httpArgumentsString(forArgsDictionary: urlArguments)
  429. var urlString: String
  430. if (auth.requestConfiguration.emulatorHostAndPort) != nil {
  431. urlString = "http://\(authDomain)/emulator/auth/handler?\(argumentsString)"
  432. } else {
  433. urlString = "https://\(authDomain)/__/auth/handler?\(argumentsString)"
  434. }
  435. guard let percentEncoded = urlString.addingPercentEncoding(
  436. withAllowedCharacters: CharacterSet.urlFragmentAllowed
  437. ) else {
  438. fatalError("Internal Auth Error: failed to percent encode a string")
  439. }
  440. var components = URLComponents(string: percentEncoded)
  441. if let appCheck {
  442. let tokenResult = await appCheck.getToken(forcingRefresh: false)
  443. if let error = tokenResult.error {
  444. AuthLog.logWarning(code: "I-AUT000018",
  445. message: "Error getting App Check token; using placeholder " +
  446. "token instead. Error: \(error)")
  447. }
  448. let appCheckTokenFragment = "fac=\(tokenResult.token)"
  449. components?.fragment = appCheckTokenFragment
  450. }
  451. return components?.url
  452. }
  453. /// Returns the SHA256 hash representation of a given string object.
  454. /// - Parameter string: The string for which a SHA256 hash is desired.
  455. /// - Returns: An hexadecimal string representation of the SHA256 hash.
  456. private func hash(forString string: String) -> String {
  457. guard let sessionIdData = string.data(using: .utf8) as? NSData else {
  458. fatalError("FirebaseAuth Internal error: Failed to create hash for sessionID")
  459. }
  460. let digestLength = Int(CC_SHA256_DIGEST_LENGTH)
  461. var hash = [UInt8](repeating: 0, count: digestLength)
  462. CC_SHA256(sessionIdData.bytes, UInt32(sessionIdData.length), &hash)
  463. let dataHash = NSData(bytes: hash, length: digestLength)
  464. var bytes = [UInt8](repeating: 0, count: digestLength)
  465. dataHash.getBytes(&bytes, length: digestLength)
  466. var hexString = ""
  467. for byte in bytes {
  468. hexString += String(format: "%02x", UInt8(byte))
  469. }
  470. return hexString
  471. }
  472. private func httpArgumentsString(forArgsDictionary argsDictionary: [String: String]) -> String {
  473. var argsString: [String] = []
  474. for (key, value) in argsDictionary {
  475. let keyString = AuthWebUtils.string(byUnescapingFromURLArgument: key)
  476. let valueString = AuthWebUtils.string(byUnescapingFromURLArgument: value.description)
  477. argsString.append("\(keyString)=\(valueString)")
  478. }
  479. return argsString.joined(separator: "&")
  480. }
  481. private let auth: Auth
  482. private let callbackScheme: String
  483. private let usingClientIDScheme: Bool
  484. }