Get Started
1
Create a new project
Create a new iOS or macOS project for this quickstart.In Xcode:
- File → New → Project (or ⌘+Shift+N)
- Select either:
- iOS tab → App template
- macOS tab → App template
- Configure your project:
- Product Name:
Auth0-Sample - Interface: SwiftUI
- Language: Swift
- Use Core Data: Unchecked
- Include Tests: Checked (recommended)
- Product Name:
- Choose a location and click Create
2
Add the Auth0 SDK
Add the Auth0 SDK to your project using your preferred package manager.
- Swift Package Manager
- CocoaPods
- Carthage
In Xcode:
- File → Add Package Dependencies… (or ⌘+Shift+K)
- Enter the Auth0 SDK URL:
- Add Package → Select your app target → Add Package
3
Configure Auth0
Create a new Auth0 application and configure callback URLs.
- Go to Auth0 Dashboard
- Applications > Create Application > Name it, select Native > Create
- In the Settings tab, note your Client ID and Domain
- Add the following URLs to Allowed Callback URLs:
- iOS
- macOS
- Add the following URLs to Allowed Logout URLs:
- iOS
- macOS
- Click Save Changes
4
Configure App Credentials
Create Drag
Auth0.plist in your project directory:Auth0.plist
Auth0.plist into Xcode and ensure “Add to target” is checked.5
Create the Authentication Service
Create
AuthenticationService.swift:- Right-click your project → New File… → Swift File
- Name it
AuthenticationService - Replace contents with:
AuthenticationService.swift
6
Create UI Components
Create UI files and add code:
7
Configure Authentication Flow (Optional)
To improve the user experience, you can minimize system alerts in the following ways:
- Use Universal Links: This eliminates the ‘Open in “AppName”?’ prompt that appears during the redirect. Note: The ASWebAuthenticationSession permission alert will still appear.
- Use Ephemeral Sessions: This eliminates all permission alerts. Note: This disables Single Sign-On (SSO) and shared cookies.
- Universal Links
- Ephemeral Session
- Auth0 Dashboard → Applications → Your app → Settings → Advanced Settings → Device Settings
- Add Apple Team ID and bundle identifier → Save
- Xcode: Target → Signing & Capabilities → + Capability → Associated Domains
- Add:
webcredentials:{yourDomain}
8
Run your app
Press ⌘+R in Xcode.
- Tap “Log In” → Permission alert (if using default) → Tap “Continue”
- Complete login in browser
- See your profile!
CheckpointYou now have a fully functional Auth0 login in your iOS or macOS app!
Troubleshooting & Advanced
Common Issues & Solutions
Common Issues & Solutions
Build errors: ‘Auth0’ module not found
Solutions:- Swift Package Manager: Check Package Dependencies → Verify
Auth0.swiftis listed - CocoaPods: Ensure you’re opening the
.xcworkspacefile, not.xcodeproj - Carthage: Verify
Auth0.xcframeworkis added to Frameworks, Libraries, and Embedded Content - Clean and rebuild: ⌘+Shift+K then ⌘+R
- Restart Xcode if needed
App crashes: ‘Auth0.plist not found’
Fix:- Verify
Auth0.plistis in your Xcode project navigator - Select the file → Inspector → Ensure your app target is checked
- Confirm it has
ClientIdandDomainkeys with your values - Alternative: Use programmatic configuration (see Advanced Integration section below)
Browser opens but never returns to app
Fix:- Check callback URLs in Auth0 Dashboard match your bundle identifier and platform exactly
- For iOS: URLs should contain
/ios/, for macOS:/macos/ - Verify bundle identifier in Xcode matches Auth0 settings
- Ensure no typos in URLs (common: missing colons, wrong domain format)
- Custom domain users: Verify you’re using your custom domain, not the Auth0 domain
Permission alert appears every time
This is standard iOS/macOS security behavior when using custom URL schemes. See Step 6 to eliminate this alert using Universal Links or Ephemeral Sessions.Custom Domain Configuration
Custom Domain Configuration
If you’re using a custom domain, use its value instead of your Auth0 domain everywhere.Example: Use
login.example.com instead of tenant.auth0.comThis is required for certain features to work properly:- Update
Auth0.plistwith your custom domain - Use custom domain in callback/logout URLs
- For Universal Links, use:
webcredentials:login.example.com
Production Deployment
Production Deployment
App Store Preparation
- Configure Universal Links to eliminate the permission alert
- Test on multiple platform versions and device sizes
- Implement proper error handling for network failures
- Add Privacy Usage descriptions if using Keychain with biometrics
- Follow App Store Review Guidelines for authentication flows
Security Best Practices
- Never log sensitive authentication data in production
- Implement App Transport Security (ATS) compliance
- Use HTTPS for all network requests
- Do NOT pin Auth0 API certificates - Auth0 does not recommend this practice
Performance Optimization
- All async operations properly use
@MainActorfor UI updates @Publishedproperties use proper memory handling- Credentials are cached securely in the Keychain for offline access
- User profile is retrieved from ID token (no additional network request)
Advanced Integration
Advanced Integration
Programmatic Configuration
Instead of usingAuth0.plist, you can pass credentials directly in your code. This is useful when credentials need to be dynamic or environment-specific (e.g., different Auth0 tenants for dev/staging/production).Replace Auth0.webAuth() calls with Auth0.webAuth(clientId:domain:):Enhanced Keychain Security with Biometrics
Require Face ID or Touch ID to access stored credentials:Automatic Token Refresh
TheCredentialsManager automatically refreshes expired access tokens:Shared Credentials Across App Extensions
For widgets, app extensions, or background tasks that need access tokens:- Enable App Groups capability in Xcode for all targets
- Use the same app group identifier across targets
- Configure the shared
CredentialsManagerin each target
Authentication Flow Options Comparison
| Feature | Universal Links | Ephemeral Session | Default (Alert) |
|---|---|---|---|
| Permission Alert | Reduced (no redirect prompt) | None | Shows all alerts |
| SSO Support | Yes | No | Yes |
| Apple Developer Account | Required | Not required | Not required |
| User Experience | Best | Good | Acceptable |
| Setup Complexity | Medium | Easy | Easy |
| Private Browsing Support | Yes | Yes | No |
- Production apps with SSO: Universal Links (better UX, SSO support, requires Apple Developer account)
- Production apps without SSO: Ephemeral Sessions (no alerts, simpler setup)
- Testing/Development: Ephemeral Sessions (quick setup, cleanest UX)
- Quick start/Prototyping: Default with alerts (no setup, can migrate later)