This commit is contained in:
Konstantin Wohlwend 2026-01-19 13:51:10 -08:00
parent 66b066db6e
commit bcb4aa8403
9 changed files with 3188 additions and 0 deletions

View File

@ -4,5 +4,6 @@ packages:
- examples/*
- docs
- sdks/*
- sdks/implementations/*
minimumReleaseAge: 2880

View File

@ -0,0 +1,21 @@
// swift-tools-version: 5.9
import PackageDescription
let package = Package(
name: "StackAuthMacOS",
platforms: [
.macOS(.v14)
],
dependencies: [
.package(name: "StackAuth", path: "../..")
],
targets: [
.executableTarget(
name: "StackAuthMacOS",
dependencies: [
.product(name: "StackAuth", package: "StackAuth")
],
path: "StackAuthMacOS"
)
]
)

View File

@ -0,0 +1,111 @@
# Stack Auth macOS Example
A comprehensive macOS SwiftUI application for testing all Stack Auth SDK functions interactively.
## Prerequisites
- macOS 14.0+
- Swift 5.9+
- A running Stack Auth backend (default: `http://localhost:8102`)
## Running the Example
1. Start the Stack Auth backend:
```bash
cd /path/to/stack-2
pnpm run dev
```
2. Open and run the example:
```bash
cd Examples/StackAuthMacOS
swift run
```
Or open in Xcode:
```bash
open Package.swift
```
## Features
The example app provides a sidebar navigation with the following sections:
### Configuration
- **Settings**: Configure API base URL, project ID, and API keys
- **Logs**: View real-time logs of all SDK operations
### Client App Testing
- **Authentication**
- Sign up with email/password
- Sign in with credentials
- Sign in with wrong password (error testing)
- Sign out
- Get current user
- Get user (or throw)
- **User Management**
- Set display name
- Update client metadata
- Update password
- Get access/refresh tokens
- Get auth headers
- Get partial user from token
- **Teams**
- Create team
- List user's teams
- Get team by ID
- List team members
- **Contact Channels**
- List contact channels
- **OAuth**
- Generate OAuth URLs for Google, GitHub, Microsoft
- Test PKCE code generation
- **Tokens**
- Get access token (JWT format)
- Get refresh token
- Get auth headers
- Test different token stores
### Server App Testing
- **Server Users**
- Create user (basic and with all options)
- List users with pagination
- Get user by ID
- Delete user
- **Server Teams**
- Create team
- List all teams
- Add/remove users from teams
- List team users
- Delete team
- **Sessions**
- Create session (impersonation)
- Use session tokens with client app
## Default Configuration
The example is pre-configured for local development:
- Base URL: `http://localhost:8102`
- Project ID: `internal`
- Publishable Key: `this-publishable-client-key-is-for-local-development-only`
- Secret Key: `this-secret-server-key-is-for-local-development-only`
## SDK Functions Covered
| Category | Functions |
|----------|-----------|
| Auth | signUpWithCredential, signInWithCredential, signOut, getUser, getOAuthUrl |
| User | setDisplayName, update (metadata), updatePassword, getAccessToken, getRefreshToken, getAuthHeaders, getPartialUser |
| Teams | createTeam, listTeams, getTeam, listUsers (team members) |
| Contact | listContactChannels |
| Server Users | createUser, listUsers, getUser, delete, update (metadata, password) |
| Server Teams | createTeam, listTeams, getTeam, addUser, removeUser, listUsers, delete |
| Sessions | createSession |
| Errors | EmailPasswordMismatchError, UserNotSignedInError, PasswordConfirmationMismatchError |

View File

@ -0,0 +1,21 @@
// swift-tools-version: 5.9
import PackageDescription
let package = Package(
name: "StackAuthiOS",
platforms: [
.iOS(.v17)
],
dependencies: [
.package(name: "StackAuth", path: "../..")
],
targets: [
.executableTarget(
name: "StackAuthiOS",
dependencies: [
.product(name: "StackAuth", package: "StackAuth")
],
path: "StackAuthiOS"
)
]
)

View File

@ -0,0 +1,107 @@
# Stack Auth iOS Example
A comprehensive iOS SwiftUI application for testing all Stack Auth SDK functions interactively.
## Prerequisites
- iOS 17.0+
- Swift 5.9+
- Xcode 15.0+
- A running Stack Auth backend accessible from the iOS device/simulator
## Running the Example
1. Start the Stack Auth backend:
```bash
cd /path/to/stack-2
pnpm run dev
```
2. Open in Xcode:
```bash
cd Examples/StackAuthiOS
open Package.swift
```
3. Select an iOS simulator or device and run.
**Note**: When testing on a physical device, update the base URL in Settings to point to your machine's IP address (e.g., `http://192.168.1.x:8102`).
## Features
The example app uses a tab-based navigation with the following sections:
### Auth Tab
- Sign up with email/password
- Sign in with credentials
- Sign in with wrong password (error testing)
- Sign out
- Get current user
- Get user (or throw)
- Generate OAuth URLs (Google, GitHub, Microsoft)
### User Tab
- Set display name
- Update client metadata
- Update password (correct and wrong old password)
- Get access/refresh tokens
- Get auth headers
- Get partial user from token
- List contact channels
### Teams Tab
- Create team
- List user's teams
- Select and view team details
- List team members
- Update team name
### Server Tab
- **Users**
- Create user (basic and with all options)
- List users
- Get/delete user by ID
- Create session (impersonation)
- **Teams**
- Create team
- List all teams
- Add/remove users from teams
- List team users
- Delete team
### Settings Tab
- Configure API base URL
- Configure project ID and API keys
- View operation logs
## Default Configuration
The example is pre-configured for local development:
- Base URL: `http://localhost:8102`
- Project ID: `internal`
- Publishable Key: `this-publishable-client-key-is-for-local-development-only`
- Secret Key: `this-secret-server-key-is-for-local-development-only`
## Simulator Network Notes
When running in the iOS Simulator, `localhost` will connect to your Mac's localhost. For physical devices, use your Mac's local IP address.
## SDK Functions Covered
| Category | Functions |
|----------|-----------|
| Auth | signUpWithCredential, signInWithCredential, signOut, getUser, getOAuthUrl |
| User | setDisplayName, update (metadata), updatePassword, getAccessToken, getRefreshToken, getAuthHeaders, getPartialUser |
| Teams | createTeam, listTeams, getTeam, listUsers (team members), update |
| Contact | listContactChannels |
| Server Users | createUser, listUsers, getUser, delete, createSession |
| Server Teams | createTeam, listTeams, getTeam, addUser, removeUser, listUsers, delete |
| Errors | EmailPasswordMismatchError, UserNotSignedInError, PasswordConfirmationMismatchError |
## Testing Edge Cases
The app includes buttons specifically for testing error scenarios:
- "Sign In (Wrong Password)" - triggers EmailPasswordMismatchError
- "Get User (or throw)" - triggers UserNotSignedInError when not signed in
- "Update (Wrong Old Password)" - triggers PasswordConfirmationMismatchError

View File

@ -136,6 +136,34 @@ The following are browser-only and not exposed:
- Cookie-based token storage
- `redirectMethod` constructor option
## Examples
Interactive example apps are available for testing all SDK functions:
### macOS Example
```bash
cd Examples/StackAuthMacOS
swift run
```
Features a sidebar-based UI for testing authentication, user management, teams, OAuth, tokens, and server-side operations.
### iOS Example
```bash
cd Examples/StackAuthiOS
open Package.swift # Opens in Xcode
```
Features a tab-based UI optimized for iOS with the same comprehensive SDK coverage.
Both examples include:
- Configurable API endpoints
- Real-time operation logs
- Error testing scenarios (wrong password, unauthorized access, etc.)
- Client and server app operations
## Testing
Tests use Swift Testing framework against a running backend.

View File

@ -0,0 +1,12 @@
{
"name": "@stackframe/swift-sdk",
"version": "0.0.0",
"private": true,
"description": "Stack Auth Swift SDK",
"scripts": {
"test": "swift test",
"build": "swift build",
"start:mac-example": "cd Examples/StackAuthMacOS && swift run",
"start:ios-example": "echo 'iOS example requires Xcode. Run: open Examples/StackAuthiOS/Package.swift'"
}
}