{"_id":"@autolabz/service-auth-core","_rev":"8-edfaac6083791e2755cdb3e0e1496d9f","name":"@autolabz/service-auth-core","dist-tags":{"latest":"1.0.7"},"versions":{"1.0.0":{"name":"@autolabz/service-auth-core","version":"1.0.0","_id":"@autolabz/service-auth-core@1.0.0","maintainers":[{"name":"autolabz","email":"mzhh@mzhh.xyz"}],"dist":{"shasum":"b7b431e560cd446b6c0080695d3c4a69f8733774","tarball":"https://registry.npmjs.org/@autolabz/service-auth-core/-/service-auth-core-1.0.0.tgz","fileCount":8,"integrity":"sha512-Gnc0CV76SdDz4pNXMN23NzKc/mnWmMAj3kl416plUle1edYgR1k4MVwMfclogHtCDo6jvRV8PKXr2pgNCKHJBQ==","signatures":[{"sig":"MEUCIBn+RsYNjsZE52UZSioG9jseeWrJj58UHAxpwE3HJ9//AiEAhxH+83L67lZcB8GmHF9GeY4EOdljTMB4Yu1hoJQ/w+s=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":26459},"main":"dist/index.cjs","type":"module","types":"dist/index.d.ts","module":"dist/index.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"}},"gitHead":"7aaed46abb7b0c16716e887d0501aadcd4b00fa6","scripts":{"build":"npm run clean && tsup src/index.ts --format esm,cjs --dts --sourcemap --clean --target node18","clean":"rimraf dist","prepare":"npm run build","typecheck":"tsc -p tsconfig.json --noEmit"},"_npmUser":{"name":"autolabz","email":"mzhh@mzhh.xyz"},"_npmVersion":"10.8.2","description":"Framework-agnostic authentication core for AutoLab services","directories":{},"sideEffects":false,"_nodeVersion":"20.19.5","dependencies":{"jose":"^5.3.0"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.3.0","rimraf":"^5.0.5","typescript":"^5.6.3"},"_npmOperationalInternal":{"tmp":"tmp/service-auth-core_1.0.0_1763006879568_0.7398055327732698","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@autolabz/service-auth-core","version":"1.0.1","_id":"@autolabz/service-auth-core@1.0.1","maintainers":[{"name":"autolabz","email":"mzhh@mzhh.xyz"}],"dist":{"shasum":"9dac62526e072e326830ef3f194e781ec8de1280","tarball":"https://registry.npmjs.org/@autolabz/service-auth-core/-/service-auth-core-1.0.1.tgz","fileCount":8,"integrity":"sha512-XtiZumRFwBkL7zF22ya2sWXcqR1jtDJm+pKlCDMLfxv9FyZFc6dykNwoJEkT1mIbW46rhoLSyR3FShkX6b9CdQ==","signatures":[{"sig":"MEUCIAfb41eZUacH3nFmUx+pXc0367VnnXpi8be2gyxB4t2mAiEAtiBPUVR46SE7eHwgOPPxST6w4EfU/ZXjcrwpi6bRrcY=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":26458},"main":"dist/index.cjs","type":"module","types":"dist/index.d.ts","module":"dist/index.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"}},"gitHead":"7aaed46abb7b0c16716e887d0501aadcd4b00fa6","scripts":{"build":"npm run clean && tsup src/index.ts --format esm,cjs --dts --sourcemap --clean --target node18","clean":"rimraf dist","prepare":"npm run build","typecheck":"tsc -p tsconfig.json --noEmit"},"_npmUser":{"name":"autolabz","email":"mzhh@mzhh.xyz"},"_npmVersion":"10.8.2","description":"Framework-agnostic authentication core for AutoLab services","directories":{},"sideEffects":false,"_nodeVersion":"20.19.5","dependencies":{"jose":"^5.3.0"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.3.0","rimraf":"^5.0.5","typescript":"^5.6.3"},"_npmOperationalInternal":{"tmp":"tmp/service-auth-core_1.0.1_1763033907253_0.34281642183453354","host":"s3://npm-registry-packages-npm-production"}},"1.0.2":{"name":"@autolabz/service-auth-core","version":"1.0.2","_id":"@autolabz/service-auth-core@1.0.2","maintainers":[{"name":"autolabz","email":"mzhh@mzhh.xyz"}],"dist":{"shasum":"fdbb294f2c6747e7b5a23c446f5989a0827a652a","tarball":"https://registry.npmjs.org/@autolabz/service-auth-core/-/service-auth-core-1.0.2.tgz","fileCount":8,"integrity":"sha512-DsmdTd9A25pPp39nfMuF3D7NLIOn55gYeWQVUHsrWB54oRzHldo+EBTBOa1ocilX08hkeSD6YzQggz6OrBRMMg==","signatures":[{"sig":"MEUCIAdAz0RYjvbL1Vu4c52zYtqKFV/y+M7jMUUZaaqXlk1DAiEAql/CS3sIygZtqZO+r+vBu8LgCgth9fCwl7eR8Vd5f/U=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":26458},"main":"dist/index.cjs","type":"module","types":"dist/index.d.ts","module":"dist/index.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"}},"gitHead":"2100f007a4759a2b8c9aeb2c2591efcf93d5346f","scripts":{"build":"npm run clean && tsup src/index.ts --format esm,cjs --dts --sourcemap --clean --target node18","clean":"rimraf dist","prepare":"npm run build","typecheck":"tsc -p tsconfig.json --noEmit"},"_npmUser":{"name":"autolabz","email":"mzhh@mzhh.xyz"},"_npmVersion":"10.8.2","description":"Framework-agnostic authentication core for AutoLab services","directories":{},"sideEffects":false,"_nodeVersion":"20.19.5","dependencies":{"jose":"^5.3.0"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.3.0","rimraf":"^5.0.5","typescript":"^5.6.3"},"_npmOperationalInternal":{"tmp":"tmp/service-auth-core_1.0.2_1763372626808_0.14198341876338438","host":"s3://npm-registry-packages-npm-production"}},"1.0.3":{"name":"@autolabz/service-auth-core","version":"1.0.3","_id":"@autolabz/service-auth-core@1.0.3","maintainers":[{"name":"autolabz","email":"mzhh@mzhh.xyz"}],"dist":{"shasum":"ed42ab16f2afcc7f834e97d358330a389f29b302","tarball":"https://registry.npmjs.org/@autolabz/service-auth-core/-/service-auth-core-1.0.3.tgz","fileCount":8,"integrity":"sha512-4wYugYFClTkSAOzImmb6uDFV1cSk99rrj4IVvS/Cz/9nttROdnoLhB//8gn7jn923CeTWyw26KF/XZSRqSkGGw==","signatures":[{"sig":"MEQCICAYnxPhU8MQuqZoEvKv3oWBmbgX8tL6l9CQVncLipv1AiANx/ffi5ydwGR754sNfwWaVLEgVY3bxMJeCJuLA79gDg==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":27004},"main":"dist/index.cjs","type":"module","types":"dist/index.d.ts","module":"dist/index.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"}},"gitHead":"2100f007a4759a2b8c9aeb2c2591efcf93d5346f","scripts":{"build":"npm run clean && tsup src/index.ts --format esm,cjs --dts --sourcemap --clean --target node18","clean":"rimraf dist","prepare":"npm run build","typecheck":"tsc -p tsconfig.json --noEmit"},"_npmUser":{"name":"autolabz","email":"mzhh@mzhh.xyz"},"_npmVersion":"10.8.2","description":"Framework-agnostic authentication core for AutoLab services","directories":{},"sideEffects":false,"_nodeVersion":"20.19.5","dependencies":{"jose":"^5.3.0"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.3.0","rimraf":"^5.0.5","typescript":"^5.6.3"},"_npmOperationalInternal":{"tmp":"tmp/service-auth-core_1.0.3_1763372956916_0.2653184132245019","host":"s3://npm-registry-packages-npm-production"}},"1.0.4":{"name":"@autolabz/service-auth-core","version":"1.0.4","_id":"@autolabz/service-auth-core@1.0.4","maintainers":[{"name":"autolabz","email":"mzhh@mzhh.xyz"}],"dist":{"shasum":"4604d019d7fdaffef853a0f9ec002cae5852a771","tarball":"https://registry.npmjs.org/@autolabz/service-auth-core/-/service-auth-core-1.0.4.tgz","fileCount":8,"integrity":"sha512-8yrfeJnESkaY+3SVSEpG8Fc6iZpChKT4KFD90A1MaeR6e2d4Bgn3fQ/TSMV/MdBO/ZEGfmrOvLKLEqFcmGBXOQ==","signatures":[{"sig":"MEYCIQClPPDs6kfSB9rzOJf8INd2reVRJZFknDZCq7HC1pqjxAIhAJGlJptHR6MK5ZtmUrJTq5y+6Mdf5OvgevZsw5CzDXbg","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":27368},"main":"dist/index.cjs","type":"module","types":"dist/index.d.ts","module":"dist/index.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"}},"gitHead":"2100f007a4759a2b8c9aeb2c2591efcf93d5346f","scripts":{"build":"npm run clean && tsup src/index.ts --format esm,cjs --dts --sourcemap --clean --target node18","clean":"rimraf dist","prepare":"npm run build","typecheck":"tsc -p tsconfig.json --noEmit"},"_npmUser":{"name":"autolabz","email":"mzhh@mzhh.xyz"},"_npmVersion":"10.8.2","description":"Framework-agnostic authentication core for AutoLab services","directories":{},"sideEffects":false,"_nodeVersion":"20.19.5","dependencies":{"jose":"^5.3.0"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.3.0","rimraf":"^5.0.5","typescript":"^5.6.3"},"_npmOperationalInternal":{"tmp":"tmp/service-auth-core_1.0.4_1763373255034_0.6181161615264581","host":"s3://npm-registry-packages-npm-production"}},"1.0.5":{"name":"@autolabz/service-auth-core","version":"1.0.5","_id":"@autolabz/service-auth-core@1.0.5","maintainers":[{"name":"autolabz","email":"mzhh@mzhh.xyz"}],"dist":{"shasum":"67b802ad5915276e4f1dce0793d31a69a06ee85a","tarball":"https://registry.npmjs.org/@autolabz/service-auth-core/-/service-auth-core-1.0.5.tgz","fileCount":8,"integrity":"sha512-yi1n1tyrAky/UPCGomEpY1dTZ9VLlUMaPGhwRPpdBkOl65F0lA3T9Tj566kiEioKU1hrv0MOFf4MVZZbuNNcpA==","signatures":[{"sig":"MEUCIH5Hu02mVWNCg8008C36Gb6uVm6TrxFKAb5PCpH1VPwFAiEA2rUqy1zckALFEH3RJIjpkVHUuYGSHjnjc3xaQsrYl84=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":27684},"main":"dist/index.cjs","type":"module","types":"dist/index.d.ts","module":"dist/index.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"}},"gitHead":"2100f007a4759a2b8c9aeb2c2591efcf93d5346f","scripts":{"build":"npm run clean && tsup src/index.ts --format esm,cjs --dts --sourcemap --clean --target node18","clean":"rimraf dist","prepare":"npm run build","typecheck":"tsc -p tsconfig.json --noEmit"},"_npmUser":{"name":"autolabz","email":"mzhh@mzhh.xyz"},"_npmVersion":"10.8.2","description":"Framework-agnostic authentication core for AutoLab services","directories":{},"sideEffects":false,"_nodeVersion":"20.19.5","dependencies":{"jose":"^5.3.0"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.3.0","rimraf":"^5.0.5","typescript":"^5.6.3"},"_npmOperationalInternal":{"tmp":"tmp/service-auth-core_1.0.5_1763373520662_0.8236081846411705","host":"s3://npm-registry-packages-npm-production"}},"1.0.6":{"name":"@autolabz/service-auth-core","version":"1.0.6","_id":"@autolabz/service-auth-core@1.0.6","maintainers":[{"name":"autolabz","email":"mzhh@mzhh.xyz"}],"dist":{"shasum":"fe29a3706dc63cb19e28158b0839acac47258540","tarball":"https://registry.npmjs.org/@autolabz/service-auth-core/-/service-auth-core-1.0.6.tgz","fileCount":8,"integrity":"sha512-sftp7laKZ3xBcnphIn4kxXeWBQdSfSKHXYCjCp+TY9ktTydxtXRmj8l3lPPc5PV3cPHjZCrCEQW1gRhMByghHA==","signatures":[{"sig":"MEYCIQD5w150hhiyIfQe8YBJ/mePtzA0dmD9tl6VNfFYcVinbwIhAOLtXoNKLOiRlHub7AVXOTZdNWINhraP0ACzXdRKCDjh","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":27920},"main":"dist/index.cjs","type":"module","types":"dist/index.d.ts","module":"dist/index.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"}},"gitHead":"2100f007a4759a2b8c9aeb2c2591efcf93d5346f","scripts":{"build":"npm run clean && tsup src/index.ts --format esm,cjs --dts --sourcemap --clean --target node18","clean":"rimraf dist","prepare":"npm run build","typecheck":"tsc -p tsconfig.json --noEmit"},"_npmUser":{"name":"autolabz","email":"mzhh@mzhh.xyz"},"_npmVersion":"10.8.2","description":"Framework-agnostic authentication core for AutoLab services","directories":{},"sideEffects":false,"_nodeVersion":"20.19.5","dependencies":{"jose":"^5.3.0"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.3.0","rimraf":"^5.0.5","typescript":"^5.6.3"},"_npmOperationalInternal":{"tmp":"tmp/service-auth-core_1.0.6_1763373611458_0.9657514647371206","host":"s3://npm-registry-packages-npm-production"}},"1.0.7":{"name":"@autolabz/service-auth-core","version":"1.0.7","type":"module","description":"Framework-agnostic authentication core for AutoLab services","sideEffects":false,"main":"dist/index.cjs","module":"dist/index.js","types":"dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"}},"dependencies":{"jose":"^5.3.0"},"devDependencies":{"rimraf":"^5.0.5","tsup":"^8.3.0","typescript":"^5.6.3"},"scripts":{"clean":"rimraf dist","build":"npm run clean && tsup src/index.ts --format esm,cjs --dts --sourcemap --clean --target node18","prepare":"npm run build","typecheck":"tsc -p tsconfig.json --noEmit"},"_id":"@autolabz/service-auth-core@1.0.7","gitHead":"f1597a752ed7afb3db7156f0eb56f3c72f191283","_nodeVersion":"20.19.5","_npmVersion":"10.8.2","dist":{"integrity":"sha512-jagBemg38/qjrLkWkGDKiWb/3sK0o5NPSVXVBD8pHSMNOlmGZLEiiQanzWg29ReaeugdOrdlW9jX7FRXunadgg==","shasum":"b3dab355e78d4c9564080384bbbcfe79a21f02b4","tarball":"https://registry.npmjs.org/@autolabz/service-auth-core/-/service-auth-core-1.0.7.tgz","fileCount":8,"unpackedSize":28370,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIGOTy69iq5SGKqTG/QxG/+hzxCYFYnXE+1obllKqteI0AiEA9wgI0KhAvygjBkTRoRhN7WaORSpLyPMNFhtdbuF9434="}]},"_npmUser":{"name":"autolabz","email":"mzhh@mzhh.xyz"},"directories":{},"maintainers":[{"name":"autolabz","email":"mzhh@mzhh.xyz"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/service-auth-core_1.0.7_1771427071551_0.25524477634686704"},"_hasShrinkwrap":false}},"time":{"created":"2025-11-13T04:07:59.501Z","modified":"2026-02-18T15:04:31.795Z","1.0.0":"2025-11-13T04:07:59.731Z","1.0.1":"2025-11-13T11:38:27.455Z","1.0.2":"2025-11-17T09:43:46.983Z","1.0.3":"2025-11-17T09:49:17.095Z","1.0.4":"2025-11-17T09:54:15.209Z","1.0.5":"2025-11-17T09:58:40.863Z","1.0.6":"2025-11-17T10:00:11.706Z","1.0.7":"2026-02-18T15:04:31.684Z"},"description":"Framework-agnostic authentication core for AutoLab services","maintainers":[{"name":"autolabz","email":"mzhh@mzhh.xyz"}],"readme":"# @autolabz/service-auth-core\n\nFramework-agnostic authentication core for AutoLab services.\n\n## Overview\n\nThis package provides the core authentication logic for AutoLab services, including:\n\n- **JWT Verification**: Support for HS256 and RS256 algorithms\n- **OAuth Userinfo Fallback**: Fetch user information from OAuth server\n- **Scope Validation**: Check if token has required scopes\n- **Type Definitions**: Core types used across all auth packages\n\n## Installation\n\n```bash\nnpm install @autolabz/service-auth-core\n```\n\n## Usage\n\nThis package is designed to be used by framework-specific adapters (e.g., `@autolabz/service-auth-fastify`, `@autolabz/service-auth-nextjs`). However, you can use it directly if you need fine-grained control:\n\n```typescript\nimport { verifyJwt, fetchUserinfo, type AuthConfig } from '@autolabz/service-auth-core';\n\nconst config: AuthConfig = {\n  jwtAlg: 'HS256',\n  jwtAccessSecret: 'your-secret',\n  authBaseUrl: 'http://auth-service/api',\n  oauthUserinfoPath: '/oauth/userinfo',\n  oauthUserinfoTimeoutMs: 2000,\n};\n\n// Verify JWT\nconst token = 'eyJhbGc...';\nconst payload = await verifyJwt(token, config);\nif (payload) {\n  console.log('User ID:', payload.userId);\n}\n\n// Fallback to userinfo\nconst userinfo = await fetchUserinfo(token, config);\nif (userinfo) {\n  console.log('User from userinfo:', userinfo.userId);\n}\n```\n\n## API\n\n### Types\n\n#### `AuthConfig`\n\nConfiguration for authentication:\n\n```typescript\ninterface AuthConfig {\n  jwtAlg: 'HS256' | 'RS256';\n  jwtAccessSecret?: string;        // Required for HS256\n  jwksUrl?: string;                 // Required for RS256\n  authIssuer?: string;              // Optional issuer check\n  authBaseUrl: string;              // OAuth base URL\n  oauthUserinfoPath?: string;       // Default: 'oauth/userinfo'\n  oauthUserinfoTimeoutMs?: number;  // Default: 2000\n  oauthExpectedAudience?: string;   // Optional audience check\n}\n```\n\n#### `AuthPayload`\n\nAuthentication payload returned after successful verification:\n\n```typescript\ninterface AuthPayload {\n  userId: string;\n  sub?: string;\n  email?: string;\n  iat?: number;\n  exp?: number;\n  iss?: string;\n  aud?: string | string[];\n  azp?: string;\n  scope?: string;\n  tokenType?: string;\n}\n```\n\n#### `AuthBridgeLike`\n\nInterface for authentication bridge used by SDK clients:\n\n```typescript\ninterface AuthBridgeLike {\n  getAccessToken: () => string | null;\n  getClientId: () => string | null;\n  refreshAccessToken: () => Promise<never> | Promise<string>;\n  onUnauthorized?: () => void;\n}\n```\n\n### Functions\n\n#### `verifyJwt(token: string, config: AuthConfig): Promise<AuthPayload | null>`\n\nVerify a JWT token using the configured algorithm (HS256 or RS256).\n\nReturns `AuthPayload` on success, `null` on failure.\n\n#### `fetchUserinfo(token: string, config: AuthConfig): Promise<AuthPayload | null>`\n\nFetch user information from the OAuth server using the provided token.\n\nReturns `AuthPayload` on success, `null` on failure.\n\n#### `normalizeScopes(input: string | null | undefined): string[]`\n\nNormalize scope string into an array of lowercase scope strings.\n\n#### `isSubset(required: string[] | undefined, owned: string[]): boolean`\n\nCheck if all required scopes are present in the owned scopes array.\n\n## Framework Adapters\n\nFor framework-specific integration, use these packages:\n\n- **Fastify**: `@autolabz/service-auth-fastify`\n- **Next.js**: `@autolabz/service-auth-nextjs`\n\n## License\n\nMIT\n\n","readmeFilename":"README.md"}