SignInWithApple

1.1.0

Utilities to simplify Sign in with Apple for Vapor projects.
mpdifran/vapor-sign-in-with-apple

What's New

Version 1.1.0

2025-01-06T15:35:14Z

Add patch version to maintain compatibility with SPM.

Vapor - Sign in with Apple

Utilities to simplify Sign in with Apple for Vapor projects.

Setup

Link to your project like so:

dependencies: [
    ...
    .package(url: "https://github.com/mpdifran/vapor-sign-in-with-apple.git", from: "1.0.0"),
],
targets: [
    .executableTarget(
        name: "App",
        dependencies: [
            ...
            .product(name: "SignInWithApple", package: "vapor-sign-in-with-apple"),
        ]
    )
],

Create Private Key

Create an ApplePrivateKey with the name and contents of the JWT Apple provides you. Register a new key on the developer portal here.

let siwaJWKID = "12345ABCDE" // Example key name
let siwaPrivateKey = "<contents of file as String>" // Store this in an environment variable, do not check into source control.

let privateKey = try ApplePrivateKey(
    kid: JWKIdentifier(string: siwaJWKId),
    privateKey: siwaPrivateKey
)

Token Generation

Use the following method to generate refresh and access tokens from Apple's servers. Apple's documentation on this process can be found here.

let details = AppleTokenGenerationDetails(
    teamIdentifier: 123456, // Your Apple Team ID.
    appIdentifier: com.example.app, // Application Bundle ID.
    identityToken: "ABCDEF", // Identity Token generated by Sign in with Apple on the client.
    authorizationCode: "1234", // Authorization code generated by Sign in with Apple on the client.
    privateKey: privateKey // See above for generation details.
)
let tokenResponse = try await request.signInWithApple.generateAppleTokens(details: details)

// Store tokens

Token Validation

Use the following method to validate an existing refresh token obtained by the above method. Apple's documentation on this process can be found here.

let details = AppleTokenValidationDetails(
    teamIdentifier: 123456, // Your Apple Team ID.
    appIdentifier: com.example.app, // Application Bundle ID.
    identityToken: "ABCDEF", // Identity Token generated by Sign in with Apple on the client.
    refreshToken: "1A2B3C", // Refresh token stored from previous call to `generateAppleTokens(details:)`.
    privateKey: privateKey // See above for generation details.
)
let tokenResponse = try await request.signInWithApple.validateAppleTokens(details: details)

// Store tokens

Description

  • Swift Tools 6.0.0
View More Packages from this Author

Dependencies

Last updated: Fri May 16 2025 22:50:54 GMT-0900 (Hawaii-Aleutian Daylight Time)