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
This creates a standard app with SwiftUI and Swift Package Manager support, perfect for Auth0 integration.
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 app on your Auth0 tenant and configure your project.
- Auth0.plist
- Programmatic
Create macOS:
Auth0.plist
in your project directory:Auth0.plist
- Go to Auth0 Dashboard
- Applications > Create Application > Name it, select Native > Create
- Copy Client ID and Domain from Settings tab into
Auth0.plist
- Drag
Auth0.plist
into Xcode (check “Add to target”) - Set Allowed Callback URLs and Allowed Logout URLs:
4
Create the Authentication Service
Create
AuthenticationService.swift
:- Right-click your project → New File… → Swift File
- Name it
AuthenticationService
- Replace contents with:
AuthenticationService.swift
5
Create UI Components
Create UI files and add code:
6
Configure Authentication Flow (Optional)
Eliminate the permission alert by choosing one option:
Skip this step to use the default behavior with a permission alert. You can configure this later.
- 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:YOUR_AUTH0_DOMAIN
Requires: Paid Apple Developer account, iOS 17.4+/macOS 14.4+
Best for production apps.
7
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.swift
is listed - CocoaPods: Ensure you’re opening the
.xcworkspace
file, not.xcodeproj
- Carthage: Verify
Auth0.xcframework
is 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.plist
is in your Xcode project navigator - Select the file → Inspector → Ensure your app target is checked
- Confirm it has
ClientId
andDomain
keys with your values - Alternative: Use programmatic configuration (see Step 3, Programmatic tab)
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.com
This is required for certain features to work properly:- Update
Auth0.plist
with 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
@MainActor
for UI updates @Published
properties 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
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
CredentialsManager
in each target
Authentication Flow Options Comparison
Feature | Universal Links | Ephemeral Session | Default (Alert) |
---|---|---|---|
Permission Alert | None | None | Shows alert |
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: Universal Links (best UX, requires Apple Developer account)
- Testing/Development: Ephemeral Sessions (quick setup, no alert)
- Quick start/Prototyping: Default with alert (no setup, can migrate later)