@authress/login

中文文档
2.7.509发布于 2026/11/06Apache-2.0TypeScriptESM + CJS构建来源已验证近 30 天下载 6.6万

Universal login sdk for Authress authentication as a service. Provides managed authentication for user identity, authentication, and token verification.

原始使用文档
文档目录9 节
  1. Usage
  2. Troubleshooting usage
  3. Getting Started
  4. Part 0: Setup Authress Login
  5. Part 1: Web App UI
  6. Part 2: User Authentication in Service APIs
  7. Platform Extension Login
  8. Advanced
  9. Contributing

Authress media banner

Authress Login SDK for UIs

The Authress Universal Login SDK for javascript app websites and user identity authentication. Used to integrate with the authentication as a service provider Authress at https://authress.io.

Usage

npm install @authress/login

Then required the package:

import { LoginClient } from '@authress/login';

Troubleshooting usage

Troubles with esbuild or another bundler, checkout the build tools troubleshooting page.

Getting Started

Part 0: Setup Authress Login

You'll want to create:

  • at least one provider connection - https://authress.io/app/#/manage?focus=connections
  • an application which represents your web app - https://authress.io/app/#/manage?focus=applications

Part 1: Web App UI

On every route change check to see if the user exists, and if they don't redirect them to a login prompt.

import { LoginClient } from '@authress/login';

// What is my applicationId => https://authress.io/app/#/manage?focus=applications
// What is my authressApiUrl? => https://authress.io/app/#/setup?focus=domain
const loginClient = new LoginClient({ authressApiUrl: 'https://login.application.com', applicationId: 'YOUR_APPLICATION_ID' });
const isUserLoggedIn = await loginClient.userSessionExists();
if (!isUserLoggedIn) {
  window.location.assign('/login');
}

In your app's login screen when the user selects how they would like to login, direct them there. And also specify where you would like Authress to redirect the user to after login. By default this is the user's current location.

await loginClient.authenticate({ connectionId: 'SELECTED_CONNECTION_ID', redirectUrl: window.location.href });
// Or if you know which tenant the user wants to log in with:
await loginClient.authenticate({ tenantLookupIdentifier: 'tenant-subdomain.app.com', redirectUrl: window.location.href });
return;

Then get the user access token associated with the user's login to be used for authorization in the next part:

const userToken = await loginClient.ensureToken();

Part 2: User Authentication in Service APIs

To authenticate the user in your service API, the token generated by the library in Part 1 needs to be passed to your service. The standard is pulling it from the loginClient, and putting it into an Authorization header:

const userToken = await loginClient.ensureToken();
const result = await fetch('https://api.application.com/v1/route', {
  method: 'GET',
  headers: {
    'Authorization': `Bearer ${userToken}`
  }
})

On the service API side, pull in the Authress service client companion library, and then verify the access token.

  • First install the companion library: npm install authress-sdk
  • Then verify the incoming tokens from the Authorization header:
import { TokenVerifier } from '@authress/sdk';

try {
  // Grab authorization token from the request header, the best way to do this will be framework specific.
  const userToken = request.headers['Authorization'];
  // Specify your custom domain for tokens. Configurable at https://authress.io/app/#/manage?focus=applications
  const userIdentity = await TokenVerifier('https://login.application.com', userToken);
} catch (error) {
  console.log('User is unauthorized', error);
  return { statusCode: 401 };
}

Platform Extension Login

The goal of the platform extension is to make it easy for your platform extension developers to login with Authress. Embed the ExtensionClient in your javascript UI SDK, and pass in the extensionId.

import { ExtensionClient } from '@authress/login';

// What is my custom Domain? => https://authress.io/app/#/setup?focus=domain
// What is my extensionId => https://authress.io/app/#/manage?focus=extensions
const extensionClient = new ExtensionClient('https://login.application.io', extensionId);

// redirectUrl is where the extension would like to return the user to after login
// * This method will redirect the user to the Authress Login UI screen with an auth code
const { accessToken } = await extensionClient.login(redirectUrl);

// .... After login the user is redirected to the redirectUrl
// * So try the login again:
const { accessToken } = await extensionClient.login(redirectUrl);

// * Or get the user claims from the token
await userData = await this.getUserIdentity();

Advanced

Curious exactly how these methods work and when they should be used? We have some advanced guidance available for each of the methods on the:

Method documentation

Contributing

If you are interested in contributing to the @authress/login SDK, feel fere to read the contribution.md guide.

版本与发布记录

@authress/login 共发布 184 个版本,首次发布于 2023/03/16;过去 12 个月发布了 53 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.7.509latest2026/11/061 天前
2.7.5062026/11/061 天前
2.7.5042026/11/061 天前
2.7.5032026/11/061 天前
2.7.4992026/11/061 天前
2.7.4932026/11/061 天前

关于 @authress/login 的常见问题

@authress/login 是什么?

Universal login sdk for Authress authentication as a service. Provides managed authentication for user identity, authentication, and token verification.

如何安装 @authress/login?

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

@authress/login 支持 TypeScript 吗?

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

@authress/login 支持 ESM 还是 CommonJS?

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

@authress/login 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@authress/login 可以商用吗?

@authress/login 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@authress/login 的下载量有多少?

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

@authress/login 还在维护吗?

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