Skip to content

Latest commit

 

History

History

Sample-01

Swift Sample Application

This sample application demonstrates the integration of the Auth0.swift SDK into a Swift iOS / macOS application. The sample is a companion to the Auth0 Swift Quickstart.

Requirements

  • iOS 15+ / macOS 11+
  • Xcode 14.x / 15.x

Note

On iOS 17.4+ and macOS 14.4+ it is possible to use Universal Links as callback and logout URLs. Auth0.swift will fall back to using a custom URL scheme on older iOS / macOS versions.

This feature requires Xcode 15.3+ and a paid Apple Developer account.

If you do not have a paid Apple Developer account, skip step 2 and comment out the two useHTTPS() calls in MainView.swift.

Important

On every step, if you have a custom domain, replace the YOUR_AUTH0_DOMAIN and {DOMAIN} placeholders with your custom domain instead of the value from the settings page.

Configuration

1. Configure the callback and logout URLs

Go to the settings page of your Auth0 application and add the following URLs to Allowed Callback URLs and Allowed Logout URLs, depending on the app target you want to run –either SwiftSample (iOS) or SwiftSample (macOS).

SwiftSample (iOS)

https://YOUR_AUTH0_DOMAIN/ios/YOUR_BUNDLE_IDENTIFIER/callback,
YOUR_BUNDLE_IDENTIFIER://YOUR_AUTH0_DOMAIN/ios/YOUR_BUNDLE_IDENTIFIER/callback

SwiftSample (macOS)

https://YOUR_AUTH0_DOMAIN/macos/YOUR_BUNDLE_IDENTIFIER/callback,
YOUR_BUNDLE_IDENTIFIER://YOUR_AUTH0_DOMAIN/macos/YOUR_BUNDLE_IDENTIFIER/callback
Example

If your iOS bundle identifier were com.example.MyApp and your Auth0 Domain were example.us.auth0.com, then this value would be:

https://example.us.auth0.com/ios/com.example.MyApp/callback,
com.example.MyApp://example.us.auth0.com/ios/com.example.MyApp/callback

Important

Make sure that the Auth0 application type is Native. Otherwise, you might run into errors due to the different configurations of other application types.

2. Configure the associated domain

2.1. Configure the entitlement

Open SwiftSample.xcodeproj in Xcode and go to the settings of the app target you want to run. In the Signing & Capabilities tab, change the default bundle identifier from com.auth0.samples.SwiftSample to another value of your choosing. Then, ensure the Automatically manage signing box is checked, and that your Apple Team is selected.

Under Associated Domains, find the following entry:

webcredentials:YOUR_AUTH0_DOMAIN

Replace the YOUR_AUTH0_DOMAIN placeholder with the domain of your Auth0 application.

Example

If your Auth0 Domain were example.us.auth0.com, then this value would be:

webcredentials:example.us.auth0.com

2.2. Configure the Team ID and bundle identifier

Open the settings page of your Auth0 application, scroll to the end, and open Advanced Settings > Device Settings. In the iOS section, set Team ID to your Apple Team ID, and App ID to the app's bundle identifier.

Screenshot of the iOS section inside the Auth0 application settings page

This will add the app to your Auth0 tenant's apple-app-site-association file.

Note

For the associated domain to work, the app must be signed with your team certificate even when building for the iOS simulator. Make sure you are using the Apple Team whose Team ID is configured in the settings page of your Auth0 application.

3. Configure Auth0.swift

Rename the Auth0.plist.example file to Auth0.plist, and replace the {CLIENT_ID} and {DOMAIN} placeholders with the Client ID and domain of your Auth0 application.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>ClientId</key>
    <string>{CLIENT_ID}</string>
    <key>Domain</key>
    <string>{DOMAIN}</string>
</dict>
</plist>

Issue Reporting

For general support or usage questions, use the Auth0 Community forums or raise a support ticket. Only raise an issue if you have found a bug or want to request a feature.

Do not report security vulnerabilities on the public GitHub issue tracker. The Responsible Disclosure Program details the procedure for disclosing security issues.


Auth0 Logo

Auth0 is an easy-to-implement, adaptable authentication and authorization platform. To learn more check out Why Auth0?

This project is licensed under the MIT license. See the LICENSE file for more info.