Registry / security / cloudflare-apple-sign-in

cloudflare-apple-sign-in

JSON →
library1.0.7jsnpmunverified

A fork of apple-sign-in-rest library adapted for Cloudflare Workers runtime, implementing the Sign In with Apple REST API (v1.0.7). Provides a credential-instance approach with caching of Apple public keys. Releases are infrequent. Key differentiator: optimized for Workers (no Node.js dependencies) vs original library. Supports ESM and CJS, ships TypeScript types.

npm install cloudflare-apple-sign-in
INSTALL
IMPORT
SIG · CLOUDFLARE-APPLE-S
C
cloudflare-apple-sign-in
securityjavascriptv1.0.7
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

AppleSignIn
import { AppleSignIn } from 'cloudflare-apple-sign-in'
import AppleSignIn from 'cloudflare-apple-sign-in'
Named export, not default. Also works with CJS require.
AppleSignInOptions
import type { AppleSignInOptions } from 'cloudflare-apple-sign-in'
import { AppleSignInOptions } from 'cloudflare-apple-sign-in'
TypeScript type import. Do not use as value at runtime.
AuthorizationUrlOptions
import type { AuthorizationUrlOptions } from 'cloudflare-apple-sign-in'
import { AuthorizationUrlOptions } from 'cloudflare-apple-sign-in'
TypeScript type for getAuthorizationUrl options.

Shows instantiation, authorization URL generation, token exchange, and ID token verification.

import { AppleSignIn } from 'cloudflare-apple-sign-in'; const appleSignIn = new AppleSignIn({ clientId: "com.example.app", teamId: "5B645323E8", keyIdentifier: "U3B842SVGC", privateKey: `-----BEGIN PRIVATE KEY-----\nMIGTAgEHIHMJKJyqGSM32AgEGC...-----END PRIVATE KEY-----` }); // Generate authorization URL const authUrl = appleSignIn.getAuthorizationUrl({ redirectUri: "https://example.com/callback", scope: ["name", "email"], state: "random-state" }); // Exchange authorization code for tokens const tokens = await appleSignIn.getAuthorizationToken(authCode, { redirectUri: "https://example.com/callback" }); // tokens contains id_token, access_token, refresh_token // Verify identity token const claims = await appleSignIn.verifyIdToken(tokens.id_token, { ignoreExpiration: false }); console.log(claims.sub); // Apple user ID
Debug
Known issues
gotchaThe library is forked from apple-sign-in-rest; ensure compatibility with Cloudflare Workers (no Node built-ins).
fix
Use cloudflare-apple-sign-in instead of apple-sign-in-rest if deploying on Workers.
affects: all
gotchaPrivate key must be in PEM format with \n escaped. Paste verbatim from Apple Developer Portal.
fix
Use backtick string with actual newlines or escape \n.
affects: all
gotchaclientId differs per flow: web login uses Service ID, iOS uses Bundle ID.
fix
Set clientId based on the authentication context.
affects: all
gotchaThe getAuthorizationUrl returns a URL string, not a redirect response. You must handle redirect yourself.
fix
Use Response.redirect(authUrl) in Workers.
affects: all
breakingOriginal apple-sign-in-rest v2 broke options for verifyIdToken; this fork may follow, check release notes.
fix
Review options parameter structure; pass { ignoreExpiration: boolean } as second argument.
affects: >=1.0.0
Errors
Common errors & fixes
error:0300009C:digital envelope routines::operation not supported
Node.js 17+ OpenSSL 3 incompatibility with certain crypto operations.
fix
Use NODE_OPTIONS=--openssl-legacy-provider or upgrade library to v1.0.7+.
MissingAppleSignInConfigError: Missing required config 'clientId'
AppleSignIn constructor called without required fields.
fix
Pass clientId, teamId, keyIdentifier, and privateKey in options object.
AppleSignInError: invalid_grant
Authorization code expired or invalid.
fix
Ensure code is fresh and not reused; redirectUri must match exactly the one used in auth URL.
TypeError: Cannot read properties of undefined (reading 'sub')
verifyIdToken returns undefined or null when token is invalid.
fix
Check if result exists before accessing claims; add try/catch.
Upgrade
Version history
1.0.7latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
37 hits · last 30 days
node
32
OpenAI (training)
1
Resources
cloudflare-apple-sign-in — npm install cloudflare-apple-sign-in · libregistry