AuthBackend.swift 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  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 FirebaseCore
  15. import FirebaseCoreExtension
  16. import Foundation
  17. #if COCOAPODS
  18. import GTMSessionFetcher
  19. #else
  20. import GTMSessionFetcherCore
  21. #endif
  22. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  23. protocol AuthBackendProtocol: Sendable {
  24. func call<T: AuthRPCRequest>(with request: T) async throws -> T.Response
  25. }
  26. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  27. final class AuthBackend: AuthBackendProtocol {
  28. static func authUserAgent() -> String {
  29. return "FirebaseAuth.iOS/\(FirebaseVersion()) \(GTMFetcherStandardUserAgentString(nil))"
  30. }
  31. private let rpcIssuer: any AuthBackendRPCIssuerProtocol
  32. init(rpcIssuer: any AuthBackendRPCIssuerProtocol) {
  33. self.rpcIssuer = rpcIssuer
  34. }
  35. /// Calls the RPC using HTTP request.
  36. /// Possible error responses:
  37. /// * See FIRAuthInternalErrorCodeRPCRequestEncodingError
  38. /// * See FIRAuthInternalErrorCodeJSONSerializationError
  39. /// * See FIRAuthInternalErrorCodeNetworkError
  40. /// * See FIRAuthInternalErrorCodeUnexpectedErrorResponse
  41. /// * See FIRAuthInternalErrorCodeUnexpectedResponse
  42. /// * See FIRAuthInternalErrorCodeRPCResponseDecodingError
  43. /// - Parameter request: The request.
  44. /// - Returns: The response.
  45. func call<T: AuthRPCRequest>(with request: T) async throws -> T.Response {
  46. let response = try await callInternal(with: request)
  47. if let auth = request.requestConfiguration().auth,
  48. let mfaError = Self.generateMFAError(response: response, auth: auth) {
  49. throw mfaError
  50. } else if let error = Self.phoneCredentialInUse(response: response) {
  51. throw error
  52. } else {
  53. return response
  54. }
  55. }
  56. static func request(for url: URL,
  57. httpMethod: String,
  58. contentType: String,
  59. requestConfiguration: AuthRequestConfiguration) async -> URLRequest {
  60. // Kick off tasks for the async header values.
  61. async let heartbeatsHeaderValue = requestConfiguration.heartbeatLogger?.asyncHeaderValue()
  62. async let appCheckTokenHeaderValue = requestConfiguration.appCheck?
  63. .getToken(forcingRefresh: true)
  64. var request = URLRequest(url: url)
  65. request.setValue(contentType, forHTTPHeaderField: "Content-Type")
  66. let additionalFrameworkMarker = requestConfiguration.additionalFrameworkMarker
  67. let clientVersion = "iOS/FirebaseSDK/\(FirebaseVersion())/\(additionalFrameworkMarker)"
  68. request.setValue(clientVersion, forHTTPHeaderField: "X-Client-Version")
  69. request.setValue(Bundle.main.bundleIdentifier, forHTTPHeaderField: "X-Ios-Bundle-Identifier")
  70. request.setValue(requestConfiguration.appID, forHTTPHeaderField: "X-Firebase-GMPID")
  71. request.httpMethod = httpMethod
  72. let preferredLocalizations = Bundle.main.preferredLocalizations
  73. if preferredLocalizations.count > 0 {
  74. request.setValue(preferredLocalizations.first, forHTTPHeaderField: "Accept-Language")
  75. }
  76. if let languageCode = requestConfiguration.languageCode,
  77. languageCode.count > 0 {
  78. request.setValue(languageCode, forHTTPHeaderField: "X-Firebase-Locale")
  79. }
  80. // Wait for the async header values.
  81. await request.setValue(heartbeatsHeaderValue, forHTTPHeaderField: "X-Firebase-Client")
  82. if let tokenResult = await appCheckTokenHeaderValue {
  83. if let error = tokenResult.error {
  84. AuthLog.logWarning(code: "I-AUT000018",
  85. message: "Error getting App Check token; using placeholder " +
  86. "token instead. Error: \(error)")
  87. }
  88. request.setValue(tokenResult.token, forHTTPHeaderField: "X-Firebase-AppCheck")
  89. }
  90. return request
  91. }
  92. private static func generateMFAError(response: AuthRPCResponse, auth: Auth) -> Error? {
  93. #if !os(iOS)
  94. return nil
  95. #else
  96. if let mfaResponse = response as? AuthMFAResponse,
  97. mfaResponse.idToken == nil,
  98. let enrollments = mfaResponse.mfaInfo {
  99. var info: [MultiFactorInfo] = []
  100. for enrollment in enrollments {
  101. // check which MFA factors are enabled.
  102. if let _ = enrollment.phoneInfo {
  103. info.append(PhoneMultiFactorInfo(proto: enrollment))
  104. } else if let _ = enrollment.totpInfo {
  105. info.append(TOTPMultiFactorInfo(proto: enrollment))
  106. } else {
  107. AuthLog.logError(code: "I-AUT000021", message: "Multifactor type is not supported")
  108. }
  109. }
  110. return AuthErrorUtils.secondFactorRequiredError(
  111. pendingCredential: mfaResponse.mfaPendingCredential,
  112. hints: info,
  113. auth: auth
  114. )
  115. } else {
  116. return nil
  117. }
  118. #endif // !os(iOS)
  119. }
  120. // Check whether or not the successful response is actually the special case phone
  121. // auth flow that returns a temporary proof and phone number.
  122. private static func phoneCredentialInUse(response: AuthRPCResponse) -> Error? {
  123. #if !os(iOS)
  124. return nil
  125. #else
  126. if let phoneAuthResponse = response as? VerifyPhoneNumberResponse,
  127. let phoneNumber = phoneAuthResponse.phoneNumber,
  128. phoneNumber.count > 0,
  129. let temporaryProof = phoneAuthResponse.temporaryProof,
  130. temporaryProof.count > 0 {
  131. let credential = PhoneAuthCredential(withTemporaryProof: temporaryProof,
  132. phoneNumber: phoneNumber,
  133. providerID: PhoneAuthProvider.id)
  134. return AuthErrorUtils.credentialAlreadyInUseError(message: nil,
  135. credential: credential,
  136. email: nil)
  137. } else {
  138. return nil
  139. }
  140. #endif // !os(iOS)
  141. }
  142. /// Calls the RPC using HTTP request.
  143. ///
  144. /// Possible error responses:
  145. /// * See FIRAuthInternalErrorCodeRPCRequestEncodingError
  146. /// * See FIRAuthInternalErrorCodeJSONSerializationError
  147. /// * See FIRAuthInternalErrorCodeNetworkError
  148. /// * See FIRAuthInternalErrorCodeUnexpectedErrorResponse
  149. /// * See FIRAuthInternalErrorCodeUnexpectedResponse
  150. /// * See FIRAuthInternalErrorCodeRPCResponseDecodingError
  151. /// - Parameter request: The request.
  152. /// - Returns: The response.
  153. fileprivate func callInternal<T: AuthRPCRequest>(with request: T) async throws -> T.Response {
  154. var bodyData: Data?
  155. if let postBody = request.unencodedHTTPRequestBody {
  156. #if DEBUG
  157. let JSONWritingOptions = JSONSerialization.WritingOptions.prettyPrinted
  158. #else
  159. let JSONWritingOptions = JSONSerialization.WritingOptions(rawValue: 0)
  160. #endif
  161. guard JSONSerialization.isValidJSONObject(postBody) else {
  162. throw AuthErrorUtils.JSONSerializationErrorForUnencodableType()
  163. }
  164. bodyData = try? JSONSerialization.data(
  165. withJSONObject: postBody,
  166. options: JSONWritingOptions
  167. )
  168. if bodyData == nil {
  169. // This is an untested case. This happens exclusively when there is an error in the
  170. // framework implementation of dataWithJSONObject:options:error:. This shouldn't normally
  171. // occur as isValidJSONObject: should return NO in any case we should encounter an error.
  172. throw AuthErrorUtils.JSONSerializationErrorForUnencodableType()
  173. }
  174. }
  175. let (data, error) = await rpcIssuer
  176. .asyncCallToURL(with: request, body: bodyData, contentType: "application/json")
  177. // If there is an error with no body data at all, then this must be a
  178. // network error.
  179. guard let data = data else {
  180. if let error = error {
  181. throw AuthErrorUtils.networkError(underlyingError: error)
  182. } else {
  183. // TODO: this was ignored before
  184. fatalError("Auth Internal error: RPC call didn't return data or an error.")
  185. }
  186. }
  187. // Try to decode the HTTP response data which may contain either a
  188. // successful response or error message.
  189. var dictionary: [String: AnyHashable]
  190. var rawDecode: Any
  191. do {
  192. rawDecode = try JSONSerialization.jsonObject(
  193. with: data, options: JSONSerialization.ReadingOptions.mutableLeaves
  194. )
  195. } catch let jsonError {
  196. if error != nil {
  197. // We have an error, but we couldn't decode the body, so we have no
  198. // additional information other than the raw response and the
  199. // original NSError (the jsonError is inferred by the error code
  200. // (AuthErrorCodeUnexpectedHTTPResponse, and is irrelevant.)
  201. throw AuthErrorUtils.unexpectedErrorResponse(data: data, underlyingError: error)
  202. } else {
  203. // This is supposed to be a "successful" response, but we couldn't
  204. // deserialize the body.
  205. throw AuthErrorUtils.unexpectedResponse(data: data, underlyingError: jsonError)
  206. }
  207. }
  208. guard let decodedDictionary = rawDecode as? [String: AnyHashable] else {
  209. if error != nil {
  210. throw AuthErrorUtils.unexpectedErrorResponse(deserializedResponse: rawDecode,
  211. underlyingError: error)
  212. } else {
  213. throw AuthErrorUtils.unexpectedResponse(deserializedResponse: rawDecode)
  214. }
  215. }
  216. dictionary = decodedDictionary
  217. let responseResult = Result {
  218. try T.Response(dictionary: dictionary)
  219. }
  220. // At this point we either have an error with successfully decoded
  221. // details in the body, or we have a response which must pass further
  222. // validation before we know it's truly successful. We deal with the
  223. // case where we have an error with successfully decoded error details
  224. // first:
  225. switch responseResult {
  226. case let .success(response):
  227. try propagateError(error, dictionary: dictionary, response: response)
  228. // In case returnIDPCredential of a verifyAssertion request is set to
  229. // @YES, the server may return a 200 with a response that may contain a
  230. // server error.
  231. if let verifyAssertionRequest = request as? VerifyAssertionRequest {
  232. if verifyAssertionRequest.returnIDPCredential {
  233. if let errorMessage = dictionary["errorMessage"] as? String {
  234. if let clientError = Self.clientError(
  235. withServerErrorMessage: errorMessage,
  236. errorDictionary: dictionary,
  237. response: response,
  238. error: error
  239. ) {
  240. throw clientError
  241. }
  242. }
  243. }
  244. }
  245. return response
  246. case let .failure(failure):
  247. try propagateError(error, dictionary: dictionary, response: nil)
  248. throw AuthErrorUtils
  249. .RPCResponseDecodingError(deserializedResponse: dictionary, underlyingError: failure)
  250. }
  251. }
  252. private func propagateError(_ error: Error?, dictionary: [String: AnyHashable],
  253. response: AuthRPCResponse?) throws {
  254. guard let error else {
  255. return
  256. }
  257. if let errorDictionary = dictionary["error"] as? [String: AnyHashable] {
  258. if let errorMessage = errorDictionary["message"] as? String {
  259. if let clientError = Self.clientError(
  260. withServerErrorMessage: errorMessage,
  261. errorDictionary: errorDictionary,
  262. response: response,
  263. error: error
  264. ) {
  265. throw clientError
  266. }
  267. }
  268. // Not a message we know, return the message directly.
  269. throw AuthErrorUtils.unexpectedErrorResponse(
  270. deserializedResponse: errorDictionary,
  271. underlyingError: error
  272. )
  273. }
  274. // No error message at all, return the decoded response.
  275. throw AuthErrorUtils
  276. .unexpectedErrorResponse(deserializedResponse: dictionary, underlyingError: error)
  277. }
  278. private static func splitStringAtFirstColon(_ input: String) -> (before: String, after: String) {
  279. guard let colonIndex = input.firstIndex(of: ":") else {
  280. return (input, "") // No colon, return original string before and empty after
  281. }
  282. let before = String(input.prefix(upTo: colonIndex))
  283. .trimmingCharacters(in: .whitespacesAndNewlines)
  284. let after = String(input.suffix(from: input.index(after: colonIndex)))
  285. .trimmingCharacters(in: .whitespacesAndNewlines)
  286. return (before, after.isEmpty ? "" : after) // Return empty after if it's empty
  287. }
  288. private static func clientError(withServerErrorMessage serverErrorMessage: String,
  289. errorDictionary: [String: Any],
  290. response: AuthRPCResponse?,
  291. error: Error?) -> Error? {
  292. let (shortErrorMessage, serverDetailErrorMessage) = splitStringAtFirstColon(serverErrorMessage)
  293. switch shortErrorMessage {
  294. case "USER_NOT_FOUND": return AuthErrorUtils
  295. .userNotFoundError(message: serverDetailErrorMessage)
  296. case "MISSING_CONTINUE_URI": return AuthErrorUtils
  297. .missingContinueURIError(message: serverDetailErrorMessage)
  298. // "INVALID_IDENTIFIER" can be returned by createAuthURI RPC. Considering email addresses are
  299. // currently the only identifiers, we surface the FIRAuthErrorCodeInvalidEmail error code in
  300. // this case.
  301. case "INVALID_IDENTIFIER": return AuthErrorUtils
  302. .invalidEmailError(message: serverDetailErrorMessage)
  303. case "INVALID_ID_TOKEN": return AuthErrorUtils
  304. .invalidUserTokenError(message: serverDetailErrorMessage)
  305. case "CREDENTIAL_TOO_OLD_LOGIN_AGAIN": return AuthErrorUtils
  306. .requiresRecentLoginError(message: serverDetailErrorMessage)
  307. case "EMAIL_EXISTS": return AuthErrorUtils
  308. .emailAlreadyInUseError(email: nil)
  309. case "OPERATION_NOT_ALLOWED": return AuthErrorUtils
  310. .operationNotAllowedError(message: serverDetailErrorMessage)
  311. case "PASSWORD_LOGIN_DISABLED": return AuthErrorUtils
  312. .operationNotAllowedError(message: serverDetailErrorMessage)
  313. case "USER_DISABLED": return AuthErrorUtils
  314. .userDisabledError(message: serverDetailErrorMessage)
  315. case "INVALID_EMAIL": return AuthErrorUtils
  316. .invalidEmailError(message: serverDetailErrorMessage)
  317. case "EXPIRED_OOB_CODE": return AuthErrorUtils
  318. .expiredActionCodeError(message: serverDetailErrorMessage)
  319. case "INVALID_OOB_CODE": return AuthErrorUtils
  320. .invalidActionCodeError(message: serverDetailErrorMessage)
  321. case "INVALID_MESSAGE_PAYLOAD": return AuthErrorUtils
  322. .invalidMessagePayloadError(message: serverDetailErrorMessage)
  323. case "INVALID_SENDER": return AuthErrorUtils
  324. .invalidSenderError(message: serverDetailErrorMessage)
  325. case "INVALID_RECIPIENT_EMAIL": return AuthErrorUtils
  326. .invalidRecipientEmailError(message: serverDetailErrorMessage)
  327. case "WEAK_PASSWORD": return AuthErrorUtils
  328. .weakPasswordError(serverResponseReason: serverDetailErrorMessage)
  329. case "TOO_MANY_ATTEMPTS_TRY_LATER": return AuthErrorUtils
  330. .tooManyRequestsError(message: serverDetailErrorMessage)
  331. case "EMAIL_NOT_FOUND": return AuthErrorUtils
  332. .userNotFoundError(message: serverDetailErrorMessage)
  333. case "MISSING_EMAIL": return AuthErrorUtils
  334. .missingEmailError(message: serverDetailErrorMessage)
  335. case "MISSING_IOS_BUNDLE_ID": return AuthErrorUtils
  336. .missingIosBundleIDError(message: serverDetailErrorMessage)
  337. case "MISSING_ANDROID_PACKAGE_NAME": return AuthErrorUtils
  338. .missingAndroidPackageNameError(message: serverDetailErrorMessage)
  339. case "UNAUTHORIZED_DOMAIN": return AuthErrorUtils
  340. .unauthorizedDomainError(message: serverDetailErrorMessage)
  341. case "INVALID_CONTINUE_URI": return AuthErrorUtils
  342. .invalidContinueURIError(message: serverDetailErrorMessage)
  343. case "INVALID_PASSWORD": return AuthErrorUtils
  344. .wrongPasswordError(message: serverDetailErrorMessage)
  345. case "INVALID_IDP_RESPONSE": return AuthErrorUtils
  346. .invalidCredentialError(message: serverDetailErrorMessage)
  347. case "INVALID_PENDING_TOKEN": return AuthErrorUtils
  348. .invalidCredentialError(message: serverDetailErrorMessage)
  349. case "INVALID_LOGIN_CREDENTIALS": return AuthErrorUtils
  350. .invalidCredentialError(message: serverDetailErrorMessage)
  351. case "INVALID_CUSTOM_TOKEN": return AuthErrorUtils
  352. .invalidCustomTokenError(message: serverDetailErrorMessage)
  353. case "CREDENTIAL_MISMATCH": return AuthErrorUtils
  354. .customTokenMismatchError(message: serverDetailErrorMessage)
  355. case "INVALID_PHONE_NUMBER": return AuthErrorUtils
  356. .invalidPhoneNumberError(message: serverDetailErrorMessage)
  357. case "QUOTA_EXCEEDED": return AuthErrorUtils
  358. .quotaExceededError(message: serverDetailErrorMessage)
  359. case "APP_NOT_VERIFIED": return AuthErrorUtils
  360. .appNotVerifiedError(message: serverDetailErrorMessage)
  361. case "CAPTCHA_CHECK_FAILED": return AuthErrorUtils
  362. .captchaCheckFailedError(message: serverDetailErrorMessage)
  363. case "INVALID_APP_CREDENTIAL": return AuthErrorUtils
  364. .invalidAppCredential(message: serverDetailErrorMessage)
  365. case "MISSING_APP_CREDENTIAL": return AuthErrorUtils
  366. .missingAppCredential(message: serverDetailErrorMessage)
  367. case "INVALID_CODE": return AuthErrorUtils
  368. .invalidVerificationCodeError(message: serverDetailErrorMessage)
  369. case "INVALID_HOSTING_LINK_DOMAIN": return AuthErrorUtils
  370. .invalidHostingLinkDomainError(message: serverDetailErrorMessage)
  371. case "INVALID_SESSION_INFO": return AuthErrorUtils
  372. .invalidVerificationIDError(message: serverDetailErrorMessage)
  373. case "SESSION_EXPIRED": return AuthErrorUtils
  374. .sessionExpiredError(message: serverDetailErrorMessage)
  375. case "ADMIN_ONLY_OPERATION": return AuthErrorUtils
  376. .error(code: AuthErrorCode.adminRestrictedOperation, message: serverDetailErrorMessage)
  377. case "BLOCKING_FUNCTION_ERROR_RESPONSE": return AuthErrorUtils
  378. .blockingCloudFunctionServerResponse(message: serverDetailErrorMessage)
  379. case "EMAIL_CHANGE_NEEDS_VERIFICATION": return AuthErrorUtils
  380. .error(code: AuthErrorCode.emailChangeNeedsVerification, message: serverDetailErrorMessage)
  381. case "INVALID_MFA_PENDING_CREDENTIAL": return AuthErrorUtils
  382. .error(code: AuthErrorCode.invalidMultiFactorSession, message: serverDetailErrorMessage)
  383. case "INVALID_PROVIDER_ID": return AuthErrorUtils
  384. .invalidProviderIDError(message: serverDetailErrorMessage)
  385. case "MFA_ENROLLMENT_NOT_FOUND": return AuthErrorUtils
  386. .error(code: AuthErrorCode.multiFactorInfoNotFound, message: serverDetailErrorMessage)
  387. case "MISSING_CLIENT_IDENTIFIER": return AuthErrorUtils
  388. .missingClientIdentifierError(message: serverDetailErrorMessage)
  389. case "MISSING_IOS_APP_TOKEN": return AuthErrorUtils
  390. .missingAppTokenError(underlyingError: nil)
  391. case "MISSING_MFA_ENROLLMENT_ID": return AuthErrorUtils
  392. .error(code: AuthErrorCode.missingMultiFactorInfo, message: serverDetailErrorMessage)
  393. case "MISSING_MFA_PENDING_CREDENTIAL": return AuthErrorUtils
  394. .error(code: AuthErrorCode.missingMultiFactorSession, message: serverDetailErrorMessage)
  395. case "MISSING_OR_INVALID_NONCE": return AuthErrorUtils
  396. .missingOrInvalidNonceError(message: serverDetailErrorMessage)
  397. case "SECOND_FACTOR_EXISTS": return AuthErrorUtils
  398. .error(code: AuthErrorCode.secondFactorAlreadyEnrolled, message: serverDetailErrorMessage)
  399. case "SECOND_FACTOR_LIMIT_EXCEEDED": return AuthErrorUtils
  400. .error(
  401. code: AuthErrorCode.maximumSecondFactorCountExceeded,
  402. message: serverDetailErrorMessage
  403. )
  404. case "TENANT_ID_MISMATCH": return AuthErrorUtils.tenantIDMismatchError()
  405. case "TOKEN_EXPIRED": return AuthErrorUtils
  406. .userTokenExpiredError(message: serverDetailErrorMessage)
  407. case "UNSUPPORTED_FIRST_FACTOR": return AuthErrorUtils
  408. .error(code: AuthErrorCode.unsupportedFirstFactor, message: serverDetailErrorMessage)
  409. case "UNSUPPORTED_TENANT_OPERATION": return AuthErrorUtils
  410. .unsupportedTenantOperationError()
  411. case "UNVERIFIED_EMAIL": return AuthErrorUtils
  412. .error(code: AuthErrorCode.unverifiedEmail, message: serverDetailErrorMessage)
  413. case "FEDERATED_USER_ID_ALREADY_LINKED":
  414. guard let verifyAssertion = response as? VerifyAssertionResponse else {
  415. return AuthErrorUtils.credentialAlreadyInUseError(
  416. message: serverDetailErrorMessage, credential: nil, email: nil
  417. )
  418. }
  419. let credential = OAuthCredential(withVerifyAssertionResponse: verifyAssertion)
  420. let email = verifyAssertion.email
  421. return AuthErrorUtils.credentialAlreadyInUseError(
  422. message: serverDetailErrorMessage, credential: credential, email: email
  423. )
  424. default:
  425. if let underlyingErrors = errorDictionary["errors"] as? [[String: String]] {
  426. for underlyingError in underlyingErrors {
  427. if let reason = underlyingError["reason"] {
  428. if reason.starts(with: "keyInvalid") {
  429. return AuthErrorUtils.invalidAPIKeyError()
  430. }
  431. if underlyingError["reason"] == "ipRefererBlocked" {
  432. return AuthErrorUtils.appNotAuthorizedError()
  433. }
  434. }
  435. }
  436. }
  437. }
  438. return nil
  439. }
  440. }