agentleFS
moasqmoasq/ios-dev-agent/.agents/skills/apple-signin/SKILL.md

apple-signin

Skill4 starsChanged 6 months agoMITView on GitHub

Use when implementing Apple Sign-In. Covers entitlement setup, AuthenticationServices framework, SwiftUI SignInWithAppleButton, and credential state checking.

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Call this in your app's .task or AppDelegate.didFinishLaunching.

    line 99

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Apple Sign-In

Implement Sign in with Apple using the native AuthenticationServices framework.

Step 1: Add Entitlement

Via xcodegen MCP:

mcp__xcodegen__add_entitlement with:
  key: "com.apple.developer.applesignin"
  value: ["Default"]

Step 2: Add Capability in Developer Portal

  1. Go to developer.apple.com/account
  2. Certificates, Identifiers & Profiles → Identifiers
  3. Select your App ID
  4. Enable "Sign In with Apple" capability

Step 3: SwiftUI Sign-In Button

import AuthenticationServices

struct SignInView: View {
    var body: some View {
        SignInWithAppleButton(.signIn) { request in
            request.requestedScopes = [.fullName, .email]
        } onCompletion: { result in
            switch result {
            case .success(let authorization):
                handleAuthorization(authorization)
            case .failure(let error):
                handleError(error)
            }
        }
        .signInWithAppleButtonStyle(.black)
        .frame(height: 50)
        .clipShape(.rect(cornerRadius: AppTheme.Style.cornerRadius))
        .padding(.horizontal, AppTheme.Spacing.md)
    }

    private func handleAuthorization(_ authorization: ASAuthorization) {
        guard let credential = authorization.credential as? ASAuthorizationAppleIDCredential else {
            return
        }

        let userID = credential.user
        let identityToken = credential.identityToken
        let email = credential.email           // Only on first sign-in
        let fullName = credential.fullName     // Only on first sign-in

        // Store userID in Keychain for future credential checks
        // Send identityToken to your configured auth service if needed
    }

    private func handleError(_ error: Error) {
        // Handle ASAuthorizationError
        // .canceled — user dismissed
        // .failed — authorization failed
        // .invalidResponse — invalid response
        // .notHandled — not handled
    }
}

Step 4: Check Credential State on Launch

func checkAppleSignInCredentialState() async {
    let provider = ASAuthorizationAppleIDProvider()
    do {
        let state = try await provider.credentialState(forUserID: storedUserID)
        switch state {
        case .authorized:
            // User is still signed in
            break
        case .revoked:
            // User revoked — sign out locally
            break
        case .notFound:
            // No credential found — show sign-in
            break
        default:
            break
        }
    } catch {
        // Handle error
    }
}

Call this in your app's .task or AppDelegate.didFinishLaunching.

Step 5: AuthService Pattern

import AuthenticationServices

@MainActor @Observable
final class AuthService {
    var isSignedIn = false
    var userID: String?

    func signInWithApple(credential: ASAuthorizationAppleIDCredential) {
        userID = credential.user
        isSignedIn = true
        // Store userID in Keychain
    }

    func checkCredentialState() async {
        guard let userID else { return }
        let provider = ASAuthorizationAppleIDProvider()
        let state = try? await provider.credentialState(forUserID: userID)
        isSignedIn = (state == .authorized)
    }

    func signOut() {
        userID = nil
        isSignedIn = false
        // Remove from Keychain
    }
}

Notes

  • Email and full name are only provided on the FIRST sign-in. Store them immediately.
  • The user identifier is stable across sign-ins. Use it as the primary key.
  • For an external auth service, send the identityToken only to that configured service.
  • Apple requires the sign-in button to follow their Human Interface Guidelines.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.