npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@bradford-tech/asc-auth

v0.0.3

Published

JWT authentication helper for the Apple App Store Connect API

Readme

@bradford-tech/asc-auth

JWT authentication helper for the Apple App Store Connect API. Zero runtime dependencies — uses the Web Crypto API for ES256 signing.

Installation

npm install @bradford-tech/asc-auth

Quick Start

import { client } from "@bradford-tech/asc-sdk";
import { createASCAuth } from "@bradford-tech/asc-auth";

const auth = createASCAuth({
  issuerId: "57246542-96fe-1a63-e053-0824d011072a",
  keyId: "2X9R4HXF34",
  privateKey: process.env.ASC_PRIVATE_KEY!,
});

client.setConfig({ auth });

// All SDK calls now auto-authenticate with cached, auto-refreshing JWTs.

Team Keys vs. Individual Keys

Team Keys (default)

Team keys are scoped to the organization and require an Issuer ID:

const auth = createASCAuth({
  issuerId: "57246542-96fe-1a63-e053-0824d011072a",
  keyId: "2X9R4HXF34",
  privateKey: process.env.ASC_PRIVATE_KEY!,
});

Individual Keys

Individual keys are tied to a specific user's apps and permissions:

const auth = createASCAuth({
  keyType: "individual",
  keyId: "2X9R4HXF34",
  privateKey: process.env.ASC_PRIVATE_KEY!,
});

Key Input Formats

PEM String (most common)

Pass the .p8 file contents directly. Works with environment variables:

// From environment variable
const auth = createASCAuth({
  issuerId: "...",
  keyId: "...",
  privateKey: process.env.ASC_PRIVATE_KEY!,
});

// From file (Node.js only)
import { readFileSync } from "node:fs";
const auth = createASCAuth({
  issuerId: "...",
  keyId: "...",
  privateKey: readFileSync("./AuthKey_2X9R4HXF34.p8", "utf8"),
});

The PEM parser is forgiving: it handles CRLF/LF line endings, missing BEGIN/END markers, single-line base64, literal \n from environment variables, and extra whitespace.

CryptoKey (pre-imported)

If you import the key yourself (e.g., from a KMS or Vault):

const key = await crypto.subtle.importKey(
  "pkcs8",
  derBuffer,
  { name: "ECDSA", namedCurve: "P-256" },
  false,
  ["sign"],
);

const auth = createASCAuth({
  issuerId: "...",
  keyId: "...",
  privateKey: key,
});

Token Caching

Tokens are cached and automatically refreshed. By default:

  • Token lifetime: 1200 seconds (20 minutes — Apple's maximum for standard tokens)
  • Refresh buffer: 30 seconds (sign a new token 30s before expiry)

Customize these:

const auth = createASCAuth({
  issuerId: "...",
  keyId: "...",
  privateKey: "...",
  expiration: 900, // 15-minute tokens
  refreshBuffer: 60, // refresh 60s before expiry
});

The expiration parameter is the total token lifetime in seconds (exp - iat), which is what Apple checks — not wall-clock "seconds from now until expiry."

Manual Cache Control

auth.refresh(); // Force sign a new token, bypassing cache
auth.clearCache(); // Drop the cached token (does NOT invalidate it on Apple's side — JWTs are stateless)

Scoped Tokens

Restrict a token to specific operations:

const auth = createASCAuth({
  issuerId: "...",
  keyId: "...",
  privateKey: "...",
  scope: ["GET /v1/apps?filter[platform]=IOS"],
});

Scoped tokens are GET-only by Apple's design. Apple ignores limit, cursor, and sort query params when matching scope entries.

Long-lived tokens (up to 6 months) are accepted only for scoped GET requests against these Xcode Cloud/CI resources: build actions, build runs, git references, issues, macOS versions, products, providers, power-and-performance-metrics-and-logs, pull requests, repositories, test results, workflows, and Xcode versions. All other resources reject exp - iat > 1200.

One-Shot Signing

For single-use tokens (e.g., pre-signing in CI):

import { signASCToken } from "@bradford-tech/asc-auth";

const token = await signASCToken({
  issuerId: "...",
  keyId: "...",
  privateKey: "...",
});

Clock Skew

Token timestamps use the local system clock. If your clock runs ahead of Apple's servers, freshly signed tokens may be rejected. Apple tolerates approximately 60 seconds of skew. On systems with unreliable NTP, set expiration: 1140 (19 minutes) rather than the full 1200 to leave margin.

Error Handling

import { ASCAuthError, ASCAuthPEMError } from "@bradford-tech/asc-auth";

try {
  const token = await auth();
} catch (err) {
  if (err instanceof ASCAuthPEMError) {
    // Key parsing failed — bad PEM format, corrupt key data
    console.error("Key error:", err.message);
  } else if (err instanceof ASCAuthError) {
    // Other auth error — missing options, crypto unavailable, signing failure
    console.error("Auth error:", err.message);
  }
}

Security

Private keys must never run in browser environments. This package is designed for server-side runtimes: Node.js 20+, Deno, Bun, Cloudflare Workers, and Vercel Edge. If crypto.subtle is not available, it throws immediately with a descriptive error.

Runtime Support

| Runtime | Status | | ------------------ | ----------------------------------------------------- | | Node.js 20+ | Supported | | Deno | Supported | | Bun | Supported | | Cloudflare Workers | Supported | | Vercel Edge | Supported | | Browsers | Not supported (private keys must not run client-side) |

License

MIT