$npx -y skills add rshankras/claude-code-apple-skills --skill auth-flowGenerates authentication infrastructure with Sign in with Apple, biometrics, and Keychain storage. Use when user wants to add authentication, login, or Sign in with Apple.
| 1 | # Auth Flow Generator |
| 2 | |
| 3 | Generate a complete authentication flow with Sign in with Apple, biometric authentication (Face ID/Touch ID), and secure Keychain storage. |
| 4 | |
| 5 | ## When This Skill Activates |
| 6 | |
| 7 | Use this skill when the user: |
| 8 | - Asks to "add authentication" or "add login" |
| 9 | - Mentions "Sign in with Apple" or "SIWA" |
| 10 | - Wants "Face ID login" or "biometric auth" |
| 11 | - Asks about "Keychain" or "secure storage" |
| 12 | - Mentions "user session" or "auth token" |
| 13 | |
| 14 | ## Pre-Generation Checks |
| 15 | |
| 16 | ### 1. Project Context Detection |
| 17 | - [ ] Check for existing auth implementations |
| 18 | - [ ] Check for AuthenticationServices framework usage |
| 19 | - [ ] Verify entitlements file exists |
| 20 | - [ ] Identify source file locations |
| 21 | |
| 22 | ### 2. Conflict Detection |
| 23 | Search for existing auth: |
| 24 | ``` |
| 25 | Glob: **/*Auth*.swift, **/*Keychain*.swift |
| 26 | Grep: "ASAuthorizationController" or "LAContext" |
| 27 | ``` |
| 28 | |
| 29 | If found, ask user: |
| 30 | - Replace existing implementation? |
| 31 | - Extend with additional methods? |
| 32 | |
| 33 | ### 3. Required Capabilities |
| 34 | |
| 35 | **Sign in with Apple requires:** |
| 36 | - Add "Sign in with Apple" capability in Xcode |
| 37 | - Configure in App Store Connect |
| 38 | - Add entitlement: `com.apple.developer.applesignin` |
| 39 | |
| 40 | ## Configuration Questions |
| 41 | |
| 42 | Ask user via AskUserQuestion: |
| 43 | |
| 44 | 1. **Authentication methods?** (multi-select) |
| 45 | - Sign in with Apple |
| 46 | - Biometrics (Face ID/Touch ID) |
| 47 | - Both |
| 48 | |
| 49 | 2. **Session storage?** |
| 50 | - Keychain (secure, persists reinstall) |
| 51 | - UserDefaults (simple, cleared on reinstall) |
| 52 | |
| 53 | 3. **Session management?** |
| 54 | - Auto-refresh tokens |
| 55 | - Manual refresh |
| 56 | - No token refresh needed |
| 57 | |
| 58 | ## Generation Process |
| 59 | |
| 60 | ### Step 1: Create Core Files |
| 61 | |
| 62 | Generate these files: |
| 63 | 1. `AuthenticationManager.swift` - Core auth orchestration |
| 64 | 2. `KeychainManager.swift` - Secure storage |
| 65 | 3. `SignInWithAppleManager.swift` - SIWA handling |
| 66 | 4. `BiometricAuthManager.swift` - Face ID/Touch ID |
| 67 | |
| 68 | ### Step 2: Create SwiftUI Components |
| 69 | |
| 70 | Based on configuration: |
| 71 | - `SignInWithAppleButton.swift` - SwiftUI button wrapper |
| 72 | - `AuthenticationView.swift` - Complete auth UI |
| 73 | |
| 74 | ### Step 3: Determine File Location |
| 75 | |
| 76 | Check project structure: |
| 77 | - If `Sources/` exists → `Sources/Auth/` |
| 78 | - If `App/` exists → `App/Auth/` |
| 79 | - Otherwise → `Auth/` |
| 80 | |
| 81 | ## Entitlements Required |
| 82 | |
| 83 | ### Sign in with Apple |
| 84 | ```xml |
| 85 | <!-- YourApp.entitlements --> |
| 86 | <key>com.apple.developer.applesignin</key> |
| 87 | <array> |
| 88 | <string>Default</string> |
| 89 | </array> |
| 90 | ``` |
| 91 | |
| 92 | ### Keychain Sharing (optional) |
| 93 | ```xml |
| 94 | <key>keychain-access-groups</key> |
| 95 | <array> |
| 96 | <string>$(AppIdentifierPrefix)com.yourcompany.shared</string> |
| 97 | </array> |
| 98 | ``` |
| 99 | |
| 100 | ## Info.plist Required |
| 101 | |
| 102 | ### Face ID Usage Description |
| 103 | ```xml |
| 104 | <key>NSFaceIDUsageDescription</key> |
| 105 | <string>Use Face ID to securely sign in to your account</string> |
| 106 | ``` |
| 107 | |
| 108 | ## Output Format |
| 109 | |
| 110 | After generation, provide: |
| 111 | |
| 112 | ### Files Created |
| 113 | ``` |
| 114 | Sources/Auth/ |
| 115 | ├── AuthenticationManager.swift # Core orchestration |
| 116 | ├── KeychainManager.swift # Secure storage |
| 117 | ├── SignInWithAppleManager.swift # SIWA delegate |
| 118 | ├── BiometricAuthManager.swift # Face ID/Touch ID |
| 119 | ├── AuthenticationState.swift # Auth state model |
| 120 | └── Views/ |
| 121 | ├── SignInWithAppleButton.swift # SwiftUI button |
| 122 | └── AuthenticationView.swift # Complete UI |
| 123 | ``` |
| 124 | |
| 125 | ### Integration Steps |
| 126 | |
| 127 | **App Entry Point:** |
| 128 | ```swift |
| 129 | @main |
| 130 | struct MyApp: App { |
| 131 | @State private var authManager = AuthenticationManager() // AuthenticationManager is @Observable |
| 132 | |
| 133 | var body: some Scene { |
| 134 | WindowGroup { |
| 135 | if authManager.isAuthenticated { |
| 136 | ContentView() |
| 137 | } else { |
| 138 | AuthenticationView() |
| 139 | } |
| 140 | } |
| 141 | .environment(authManager) |
| 142 | } |
| 143 | } |
| 144 | ``` |
| 145 | |
| 146 | **Sign in with Apple Button:** |
| 147 | ```swift |
| 148 | SignInWithAppleButtonView { result in |
| 149 | switch result { |
| 150 | case .success(let user): |
| 151 | print("Signed in: \(user.id)") |
| 152 | case .failure(let error): |
| 153 | print("Failed: \(error)") |
| 154 | } |
| 155 | } |
| 156 | ``` |
| 157 | |
| 158 | **Biometric Auth:** |
| 159 | ```swift |
| 160 | Button("Unlock with Face ID") { |
| 161 | Task { |
| 162 | if await BiometricAuthManager.shared.authenticate() { |
| 163 | // Authenticated |
| 164 | } |
| 165 | } |
| 166 | } |
| 167 | ``` |
| 168 | |
| 169 | ### Required Setup |
| 170 | |
| 171 | 1. **Xcode Capabilities:** |
| 172 | - Add "Sign in with Apple" capability |
| 173 | - Enable Keychain Sharing (if needed) |
| 174 | |
| 175 | 2. **App Store Connect:** |
| 176 | - Configure Sign in with Apple for your App ID |
| 177 | |
| 178 | 3. **Info.plist:** |
| 179 | - Add `NSFaceIDUsageDescription` |
| 180 | |
| 181 | ### Testing Instructions |
| 182 | |
| 183 | **Sign in with Apple:** |
| 184 | - Use Simulator for basic testing |
| 185 | - Test on device for full flow |
| 186 | - Use sandbox Apple ID for testing |
| 187 | |
| 188 | **Biometrics:** |
| 189 | - Simulator: Features > Face ID > Enrolled |
| 190 | - Test enrolled/not enrolled states |
| 191 | - Test failed authentication |
| 192 | |
| 193 | ## References |
| 194 | |
| 195 | - **auth-patterns.md** - Security best practices |
| 196 | - **templates/** - All template files |
| 197 | - Apple Docs: Authentication Services, LocalAuthentication |