Skip to main content

iOS Quickstart

Cloud has the newest features. Some may not be in a release yet; the newest release is Identity & Access Management 7.3.0.

Use this guide to add Choreo Identity & Access Management authentication to an iOS application using the Choreo Identity & Access Management iOS SDK.

Get the complete sample

What You Will Learn​

  • Create a new Xcode project
  • Install the ThunderIDSwiftUI Swift 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

Create an Application​

  1. Sign in to the Console at https://console.cloud.choreolabs.com/iam/. Select your project in the project switcher in the header.
  2. Navigate to Applications.
  3. Click Add application.
  4. From the Choose a type page, select iOS.
  5. Enter a name (e.g. My iOS App).
  6. Select how you want to sign in users (e.g., email/password, social login, etc.).
  7. Select Theme settings.
  8. Leave Sign-in approach set to Bring your own UI (the default for iOS applications).
  9. Click Create.
warning

Copy the Application ID from the General tab, under Quick copy. You'll need it when configuring the SDK.

  1. Open the Advanced Settings tab, turn on Dev mode under Platform attestation, then click Save.
Platform attestation

Mobile applications prove their binary identity before starting a sign-in flow. If platform attestation is not configured and Dev mode is off, sign-in fails with FES-1016, Attestation not configured. Dev Mode is a bypass for local development; configure platform attestation for production.

Data plane URL

Code in this guide uses https://<DATA_PLANE_URL> for your environment's data plane URL, where users sign in and tokens are issued. Replace it with the URL on the environment's Endpoints page. To open it, select your project, go to Deployment pipeline, and click Open environment on the environment's card. See Control Plane and Data Plane URLs.

Deploy your changes

Saving a change does not make it live. You author in the control plane, and your users sign in on a separate data plane, so a change takes effect in an environment only after you deploy it. Go to Deploy, deploy the latest version to your first environment, then promote it to the next environment when you are ready.

Auto-sync deploys saved changes to your first environment within seconds. Turning it on is your choice, per project. See Deploy a Version, or learn why you deploy and how auto-sync works.

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.

note

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 ThunderID 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.

MyApp.swift
import SwiftUI
import ThunderIDSwiftUI

@main
struct MyApp: App {
var body: some Scene {
WindowGroup {
ContentView()
.thunderIDProvider(config: ThunderIDConfig(
baseUrl: "https://<DATA_PLANE_URL>",
scopes: ["openid", "profile", "email"],
applicationId: "<your-application-id>"
))
}
}
}
Configuration

Replace <your-application-id> with the Application ID from your Choreo Identity & Access Management application settings.

Configuration Parameters​

ParameterDescription
baseUrlYour Choreo Identity & Access Management instance URL. Must use HTTPS.
scopesOAuth 2.0 scopes to request. Include "openid" at minimum.
applicationIdThe Application ID used for the app-native sign-in and sign-up flows

Add Sign-In and Sign-Out​

The Choreo Identity & Access Management 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:

ContentView.swift
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:

AuthView.swift
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:

HomeView.swift
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).

Test credentials

You'll need a user to sign in with. If you haven't created one yet, open https://console.cloud.choreolabs.com/iam/, navigate to Users, and add a test user with an email and password.

Success

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.

Run the Sample App​

The iOS sample is a working version of the app this guide builds. To run it instead of building the app yourself:

  1. Download the sample from its releases and open its folder.

  2. Create Sources/Config.plist in the sample's folder with your application's values:

    Sources/Config.plist
    <?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>THUNDERID_BASE_URL</key>
    <string>https://<DATA_PLANE_URL></string>
    <key>THUNDERID_APPLICATION_ID</key>
    <string>your-application-id</string>
    </dict>
    </plist>
  3. Open Quickstart.xcodeproj in Xcode and run the Quickstart scheme on a simulator or device.

What's Next​

Was this page helpful?