iOS Quickstart
Use this guide to add ThunderID authentication to an iOS application using the ThunderID iOS SDK.
What You Will Learn
- Create a new Xcode project
- Install the
ThunderIDSwiftUISwift package
- Add working sign-in and sign-out using SwiftUI components
- Display the signed-in user's name
Prerequisites
- About 15 minutes
- Xcode 15 or later
- iOS 16+ deployment target
Run ThunderID
Start a local ThunderID instance. Pick the method that works best for you:
Requires Node.js 18+
Full install guide →Once it's running, the console is available at https://localhost:8090/console.
Create an Application
-
Sign in to the Console.
Test UserIf you used the default setup, sign in to the Console as
adminwith the password generated during setup and printed to the setup output (unless you supplied your own). -
Navigate to Applications.
-
Click Add Application.
-
From the Choose a type page, select iOS.
-
Enter a name (e.g.
My iOS App). -
Select how you want to sign in users (e.g., email/password, social login, etc.).
-
Select Theme settings.
-
Leave Sign-In Approach set to Bring Your Own UI (the default for iOS applications).
-
Click Create.
Copy the Application ID from the General tab, under Quick Copy. You'll need it when configuring the SDK.
Create an iOS App
In Xcode, create a new project using the iOS > App template. Choose SwiftUI as the interface and Swift as the language.
If you already have an existing iOS project, skip this step.
Install ThunderIDSwiftUI
In Xcode, go to File > Add Package Dependencies and enter the package URL:
https://github.com/thunder-id/ios-sdks
When prompted for a version rule, select Up to Next Major Version starting at the latest release tag. When prompted to choose package products, select ThunderIDSwiftUI. This includes the core <ProductName /> client as a dependency.
Initialize the SDK
Open your app's entry point (the file that conforms to App) and apply the .thunderIDProvider(config:) modifier to your root view. This injects a ThunderIDState environment object into all child views.
import SwiftUI
import ThunderIDSwiftUI
@main
struct MyApp: App {
var body: some Scene {
WindowGroup {
ContentView()
.thunderIDProvider(config: ThunderIDConfig(
baseUrl: "https://localhost:8090",
scopes: ["openid", "profile", "email"],
applicationId: "<your-application-id>"
))
}
}
}
Replace <your-application-id> with the Application ID from your ThunderID application settings.
Configuration Parameters
| Parameter | Description |
|---|---|
baseUrl | Your ThunderID instance URL. Must use HTTPS. |
scopes | OAuth 2.0 scopes to request. Include "openid" at minimum. |
applicationId | The Application ID used for the app-native sign-in and sign-up flows |
Add Sign-In and Sign-Out
The ThunderID iOS SDK provides SignedIn and SignedOut guard views for conditional rendering, a SignIn component for the embedded sign-in flow, and a SignOutButton for sign-out.
Replace the contents of ContentView.swift with:
import SwiftUI
import ThunderIDSwiftUI
struct ContentView: View {
@EnvironmentObject var state: ThunderIDState
var body: some View {
Group {
if !state.isInitialized {
ProgressView("Loading...")
} else {
SignedIn {
HomeView()
} fallback: {
AuthView()
}
}
}
}
}
Create AuthView.swift to display the sign-in form:
import SwiftUI
import ThunderIDSwiftUI
struct AuthView: View {
var body: some View {
VStack(spacing: 24) {
Text("Welcome")
.font(.largeTitle)
.bold()
SignIn(applicationId: "<your-application-id>")
.padding()
}
.padding()
}
}
Display User Profile Information
Create HomeView.swift to show the authenticated user's name and a sign-out button:
import SwiftUI
import ThunderIDSwiftUI
struct HomeView: View {
@EnvironmentObject var state: ThunderIDState
var body: some View {
NavigationStack {
VStack(spacing: 24) {
if let user = state.user {
Text("Welcome, \(user.displayName ?? user.email ?? "User")!")
.font(.title2)
.bold()
Text(user.email ?? "")
.foregroundStyle(.secondary)
}
SignOutButton()
.buttonStyle(.borderedProminent)
}
.padding()
.navigationTitle("Home")
}
}
}
Run the App
In Xcode, select an iOS 16+ simulator and press Run (⌘R).
You'll need a user to sign in with. If you haven't created one yet, open https://localhost:8090/console, navigate to Users, and add a test user with an email and password.
You should see the sign-in form. Enter your test user credentials and tap Submit. After successful authentication, the home screen displays the user's name and a Sign Out button.