1.1.1 • Published 3 months ago

apple-jwt-generator v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

apple-jwt-generator

Yet another package to generate an Apple Client Secret for SIWA.

The apple-jwt-generator is a lightweight Node.js library designed for generating JSON Web Tokens (JWT) for server-to-server communication with Apple's services. It simplifies the process of creating JWTs using your Apple Developer account's team ID, key ID, and private key, providing an easy-to-use interface for authenticating with Apple's APIs.

Installation

Install the package via npm:

npm install apple-jwt-generator
yarn add apple-jwt-generator
pnpm install apple-jwt-generator
bun add apple-jwt-generator

Usage

import { generateAppleJWT, AppleJWTConfig } from 'apple-jwt-generator';

const config: AppleJWTConfig = {
  teamId: 'YOUR_TEAM_ID',
  keyId: 'YOUR_KEY_ID',
  clientId: 'YOUR_CLIENT_ID',
  privateKey: `-----BEGIN PRIVATE KEY-----
YOUR_PRIVATE_KEY_HERE
-----END PRIVATE KEY-----`,
};

const jwt = generateAppleJWT(config);
console.log(jwt);

API Reference

generateAppleJWT(config: AppleJWTConfig): string

Generates a JWT for server-to-server authentication with Apple's services. This function takes a configuration object as its only argument and returns a JWT string.

Parameters

ParameterTypeDescription
configAppleJWTConfigConfiguration object for generating the JWT.
AppleJWTConfig Fields
FieldTypeRequiredDescriptionDefault
teamIdstringYesTeam ID from Apple Developer Account.N/A
keyIdstringYesKey ID of the Private Key.N/A
clientIdstringYesClient ID for the JWT.N/A
privateKeystringYesApple Private Key in PEM format.N/A
expiresInnumberNoExpiration in seconds from now for the JWT. Maximum expiration is 6 months.15778476

Returns

  • string: The generated Apple JWT.

Disclaimer

Node.js Version Requirement

This package requires a minimum Node.js version of 12.0.0 to operate correctly due to its reliance on specific features and improvements introduced in this version.

Not Suitable for Browser Environments

apple-jwt-generator is designed to be used in server-side environments and makes use of Node.js's crypto module, which is not available in browser environments. Attempting to use this package in the browser would result in errors, as browsers do not have the necessary module for cryptographic operations that this package depends on. Moreover, exposing sensitive credentials (such as private keys) in client-side code can lead to security vulnerabilities, making it critical to handle JWT generation server-side.

License

Licensed under the MIT License

See LICENSE for more information.

1.1.1

3 months ago

1.1.0

3 months ago

1.0.1

3 months ago

1.0.0

3 months ago

0.0.0

3 months ago