@autional/core

中文文档
0.4.2发布于 2026/11/06MITTypeScriptESM + CJS零依赖近 30 天下载 2275

Autional Core SDK — framework-agnostic token management, API client, and auth flows

原始使用文档
文档目录10 节
  1. What's Inside
  2. Install
  3. Quick Start
  4. Password Transmission
  5. Sessions & Account Self-service
  6. Multi-tab Sessions & Pre-refresh
  7. Device Flow (RFC 8628)
  8. DPoP (RFC 9449 — opt-in)
  9. Tenant Slug & Portal URLs
  10. Project Setup

@autional/core

Autional Core SDK — framework-agnostic token management, API client, and authentication flows.

What's Inside

  • Autional — main client: login, register, logout, OAuth, token refresh, device flow, session management, step-up, portal URLs, tenant switching, event system
  • ApiClient — HTTP client with auto token injection, pre-request refresh, refresh on 401, and snake_case/camelCase conversion
  • AuthClient — authentication calls with password transmission preprocessing and PoW captcha solving
  • Discovery — OIDC discovery document fetching
  • TokenManager — access/refresh token storage, JWT decoding, expiry tracking
  • TabSync — cross-tab session synchronization via BroadcastChannel
  • browserPlatform / sessionStoragePlatform / memoryPlatform — ready-made platform bindings (localStorage / sessionStorage / memory)
  • DpopManager — opt-in DPoP (RFC 9449) proof generation for the OAuth token endpoints
  • buildPortalUrl / extractTenantSlugFromIssuer — tenant slug and console-portal URL helpers

Install

npm install @autional/core

Quick Start

import { Autional, browserPlatform } from '@autional/core';

const autional = new Autional({
  appId: 'my-app',
  issuer: 'https://auth.example.com',
  platform: browserPlatform,
});

await autional.initialize();

await autional.login({ email: '[email protected]', password: 's3cret' });

const profile = await autional.api.get('/profile/api/v1/profiles/me');
console.log(profile);

Password Transmission

processPasswordForTransmission preprocesses passwords based on tenant policy with 4 modes:

ModeTransportDescription
plainRaw passwordNo processing
hashSHA-256(password + "" + tenantId)
symmetricECDH + AES-256-GCMKey exchange, encrypted
asymmetricRSA-OAEPPublic-key encrypted

The SDK reads the mode from TenantAuthConfig.passwordPolicy.mode and applies it automatically on login/register/change-password.

Sessions & Account Self-service

Same calls on Autional and AuthClient:

CallPurpose
getSessions() / revokeSession(id) / revokeOtherSessions()List / revoke my sessions (isCurrentSession is marked from the JWT sid)
reauthenticate(password)Step-up token for sensitive operations (single-use, 5 min)
deleteAccount(password)GDPR erasure — runs step-up internally and sends X-StepUp-Token
forgotPassword() / resetPassword() / sendVerificationEmail() / verifyEmail()Password reset and email verification
updateProfile({ username?, mfaEnabled?, metadata? })Partial profile update
revokeTokens()RFC 7009 revocation of the access/refresh token (SSO logout() revokes automatically before redirecting, time-boxed at 1.5 s)

Sensitive endpoints (step-up, account deletion) currently support plain and hash transmission modes only.

Multi-tab Sessions & Pre-refresh

syncTabs is on by default. A successful refresh broadcasts TOKEN_REFRESHED so other tabs re-read storage — a stale refresh token would trip the server's token-reuse detection and revoke the whole token family. Logout and TOKEN_REUSE broadcast LOGOUT to sign out every tab. tokenExpirySkew (seconds, default 30, 0 disables) refreshes before a request when the access token is about to expire; a failed pre-refresh keeps the session intact — only a server-reported reuse (identity 40000502 / OAuth invalid_grant with a reused description) still clears it and broadcasts LOGOUT.

Device Flow (RFC 8628)

loginWithDeviceCode({ onUserCode }) covers device-constrained environments: it shows the user code and verification URI, polls at the server interval, backs off on slow_down, and accepts an AbortSignal. requestDeviceCode() is the two-stage variant. The verification page is served by the auth domain (/device).

DPoP (RFC 9449 — opt-in)

new Autional({ dpop: true }) binds tokens to a P-256 key (persisted via the platform storage, DpopManager). Proofs go to the OAuth token-family endpoints only: token / refresh / revoke / userinfo (the client-credentials grant of loginWithClientCredentials is not DPoP-bound in this release). Requires WebCrypto and server-side DPoP support.

Tenant Slug & Portal URLs

tenantSlug drives tenant-scoped portal links: getPortalUrl('admin' | 'user' | 'security' | 'platform' | 'authenticator') appends /<slug>/; developer and status are global. createTrialTenant() returns the slug; buildPortalUrl / extractTenantSlugFromIssuer are exported for custom use — buildPortalUrl supports shared bases only (api./auth.-prefixed hosts); tenant-subdomain or IP bases return null.

Project Setup

For framework integration, pick the example for your framework: examples/react-autional.ts, examples/vue-autional.ts, or examples/next-autional.ts. Copy to src/autional.ts, edit appId and issuer.

See the root SDK README for full documentation.

版本与发布记录

@autional/core 共发布 15 个版本,首次发布于 2026/06/28;过去 12 个月发布了 15 个版本。

版本发布日期距今
0.4.2latest2026/11/061 天前
0.4.12026/10/317 天前
0.4.02026/10/308 天前
0.3.82026/10/308 天前
0.3.72026/10/2810 天前
0.3.62026/10/2810 天前

关于 @autional/core 的常见问题

@autional/core 是什么?

Autional Core SDK — framework-agnostic token management, API client, and auth flows

如何安装 @autional/core?

在项目目录运行 npm install @autional/core,或使用 pnpm add / yarn add / bun add。

@autional/core 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@autional/core 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@autional/core 可以商用吗?

@autional/core 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@autional/core 的下载量有多少?

根据 npm 官方下载统计,@autional/core 在 2026/10/07 – 2026/11/05 这 30 天内被下载 2,275 次,日均约 76 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@autional/core 还在维护吗?

最新版本 0.4.2 发布于 2026/11/06(1 天前);至今共发布 15 个版本,其中过去 12 个月发布了 15 个;首次发布于 2026/06/28。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。