Registry / authentication / apple-signin

apple-signin

JSON →
library1.0.9jsnpmunverified

Node.js wrapper around the Sign in with Apple REST API, enabling authentication with Apple accounts in Node.js applications. Current stable version is 1.0.9. The package supports generating authorization URLs, exchanging authorization codes for tokens, verifying ID tokens, and refreshing access tokens. It requires Apple Developer Program enrollment and proper configuration (Service ID, private key). Release cadence is low (last update: September 2019). Differentiators: simple API wrapping Apple's OAuth flow; limited to server-side use (no browser SDK integration). Alternatives like 'apple-auth' or 'passport-apple' may offer more features. Note: library is unmaintained; no TypeScript types; uses callbacks/promises.

npm install apple-signin
INSTALL
IMPORT
SIG · APPLE-SIGNIN
A
apple-signin
authenticationjavascriptv1.0.9
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
const appleSignin = require('apple-signin')
import appleSignin from 'apple-signin'
Package is CommonJS-only; no ESM or default export. Use require().
getAuthorizationUrl
const { getAuthorizationUrl } = require('apple-signin')
const { getAuthUrl } = require('apple-signin')
Function name is exactly 'getAuthorizationUrl'. No destructuring alternative if you need multiple functions.
getClientSecret
const appleSignin = require('apple-signin'); const secret = appleSignin.getClientSecret({clientID, teamId, privateKeyPath, keyIdentifier})
const { getClientSecret } = require('apple-signin'); getClientSecret({...})
getClientSecret expects an object with specific keys; wrong casing or missing fields causes errors.
getAuthorizationToken
const appleSignin = require('apple-signin'); appleSignin.getAuthorizationToken(code, options).then(...)
appleSignin.getAuthorizationToken(code, clientSecret) without options object
Second argument must be an options object containing clientID, redirectUri, and clientSecret.
verifyIdToken
const appleSignin = require('apple-signin'); appleSignin.verifyIdToken(idToken, clientID).then(result => ...)
appleSignin.verifyIdToken(idToken) without clientID
clientID is required as second argument to verify against expected audience.

Full authentication flow: generate auth URL, exchange code for tokens, verify ID token, and get user's unique Apple ID.

const appleSignin = require('apple-signin'); // Step 1: Generate authorization URL const authUrl = appleSignin.getAuthorizationUrl({ clientID: process.env.APPLE_CLIENT_ID ?? '', redirectUri: 'https://example.com/callback', state: 'random-state-string', scope: 'email' }); console.log('Redirect user to:', authUrl); // Step 2: Exchange authorization code for tokens const clientSecret = appleSignin.getClientSecret({ clientID: process.env.APPLE_CLIENT_ID ?? '', teamId: process.env.APPLE_TEAM_ID ?? '', privateKeyPath: '/path/to/AuthKey.p8', keyIdentifier: process.env.APPLE_KEY_ID ?? '' }); const code = 'authorization-code-from-callback'; // obtain from query param appleSignin.getAuthorizationToken(code, { clientID: process.env.APPLE_CLIENT_ID ?? '', redirectUri: 'https://example.com/callback', clientSecret }).then(tokenResponse => { console.log('Token response:', tokenResponse); // Step 3: Verify ID token return appleSignin.verifyIdToken(tokenResponse.id_token, process.env.APPLE_CLIENT_ID ?? ''); }).then(decoded => { console.log('User unique identifier:', decoded.sub); }).catch(err => { console.error('Authentication failed:', err); });
Debug
Known issues
breakingThe library is unmaintained; last update in 2019. Apple's REST API may change, breaking compatibility.
fix
Consider using an actively maintained alternative like 'apple-auth' or implement OAuth manually using jsonwebtoken and axios.
affects: >=1.0.0
deprecatedNode.js version < 12 may not support ES6 features used by dependencies. Minimum Node.js version unknown; test on Node 10+.
fix
Upgrade Node.js to active LTS (18 or 20) or higher.
affects: >=1.0.0
gotchaThe 'privateKeyPath' parameter in getClientSecret must point to the key file; it does not accept the key content directly.
fix
Provide file path string; if you have the key content, write to a temp file or modify the library.
affects: >=1.0.0
gotchagetAuthorizationToken expects an options object with clientID, redirectUri, clientSecret. Missing redirectUri will cause Apple to reject the request with a invalid_client error.
fix
Ensure redirectUri matches exactly what is registered in Apple Developer Console.
affects: >=1.0.0
gotchaThe id_token returned by Apple is a JWT signed with RSA256. The verifyIdToken function verifies signature but does not check token expiration ('exp') automatically; you should verify expiry separately.
fix
After verification, check decoded.exp < Date.now()/1000 to ensure token is not expired.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Invalid client secret
The client secret JWT is malformed or has mismatched claims (e.g., wrong teamId or clientID).
fix
Check that teamId, clientID, keyIdentifier, and privateKeyPath are correct. Regenerate private key if needed.
Error: invalid_request: The 'redirect_uri' parameter does not match any registered redirect URI
The redirectUri passed to getAuthorizationToken does not match exactly (including trailing slashes) with Apple Console configuration.
fix
Verify registered redirect URIs in Apple Developer; ensure case and path match exactly.
Error: The token is not valid or has expired
The verification fails because token is expired, signed with wrong key, or audience does not match clientID.
fix
Ensure you are using the correct id_token (from latest token exchange) and that clientID matches the intended audience. Refresh token if expired.
Error: Cannot find module 'apple-signin'
Package not installed or not in node_modules.
fix
Run 'npm install apple-signin' in your project directory.
Upgrade
Version history
1.0.9latest on npm
Audit
Dependencies
jsonwebtokenrequiredUsed to sign client secrets and verify ID tokens (JWT operations).
node-joserequiredMay be used for JWT handling or key processing (depending on version).
Agent activity
19 hits · last 30 days
node
16
OpenAI (training)
1
Resources