"A server with the specified hostname could not be found" Error with Auth0 Swift SDK in Xcode

Overview

This article addresses a common error encountered when integrating the Auth0 Swift SDK into an Xcode project: "A server with the specified hostname could not be found. " This issue typically indicates a networking problem preventing the application from connecting to an Auth0 tenant.

Applies To

  • Auth0 Swift SDK

Cause

The error “A server with the specified hostname could not be found” (NSURLErrorDomain Code=-1003) almost always points to a network connectivity issue. Specifically, when Xcode’s App Sandbox is enabled for an application, it imposes strict restrictions on network access. If these permissions are not explicitly granted, the application will be unable to establish outbound connections to the Auth0 tenant’s domain, leading to the hostname not found error.

Solution

The solution involves configuring the appropriate network entitlements within the Xcode project’s capabilities when App Sandbox is enabled.

  1. Open the Xcode project.

  2. In the Project Navigator, select the project target.

  3. Navigate to the Signing & Capabilities tab.

  4. Under the App Sandbox section, enable the following Network options by checking the boxes:

    • Incoming Connections (Server)
    • Outgoing Connections (Client)

By explicitly granting these network permissions, the application is able to communicate with the Auth0 tenant, resolving the hostname error and enabling successful authentication flows.