OpenCode Copilot Auth
raw JSON → 0.0.12 verified Sat Apr 25 auth: no javascript
Provides authentication utilities for OpenCode Copilot, an AI-powered code assistant. Version 0.0.12 is the latest. The package handles JWT token management and GitHub App authentication flows. It is designed for Node.js environments and supports both CommonJS and ESM. It simplifies the process of obtaining and validating access tokens for Copilot services.
Common errors
error Error: Unable to parse private key: openssl error ↓
cause Private key is not in correct PEM format or has incorrect line endings.
fix
Ensure private key is a valid RSA private key in PEM format with proper \n characters.
error TypeError: client.getToken is not a function ↓
cause AuthClient instance not properly initialized or wrong import.
fix
Use
new AuthClient(opts) and pass it as client parameter to getToken. error Error: Invalid JWT: jwt malformed ↓
cause Token string is not a valid JWT or is undefined.
fix
Check that
getToken returned a valid token and that it is passed correctly. Warnings
gotcha Requires Node.js 14 or higher due to use of ES2020 features. ↓
fix Ensure Node version is >=14.
gotcha Private key must be in PEM format with escaped newlines if passed as environment variable. ↓
fix Use `process.env.PRIVATE_KEY.replace(/\\n/g, '\n')` or store as base64.
deprecated The `getInstallationToken` method is deprecated in favor of `getToken`. ↓
fix Use `getToken({ installationId, client })` instead.
Install
npm install opencode-copilot-auth yarn add opencode-copilot-auth pnpm add opencode-copilot-auth Imports
- AuthClient
import { AuthClient } from 'opencode-copilot-auth' - getToken wrong
const getToken = require('opencode-copilot-auth').getTokencorrectimport { getToken } from 'opencode-copilot-auth' - verifyToken
import { verifyToken } from 'opencode-copilot-auth'
Quickstart
import { AuthClient, getToken } from 'opencode-copilot-auth';
const client = new AuthClient({
appId: process.env.APP_ID ?? '',
privateKey: process.env.PRIVATE_KEY ?? '',
});
const token = await getToken({
installationId: process.env.INSTALLATION_ID ?? '',
client,
});
console.log(token);