# @curvenote/remix-auth-okta 中文文档

规范地址：https://npmcn.com/package/%40curvenote/remix-auth-okta/

版本：3\.0\.0
npm 元数据更新时间：2025-06-12T10:57:06.637Z
中文译文更新时间：2026-11-11T05:11:00.988Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40curvenote/remix-auth-okta
原文对照：https://npmcn.com/package/%40curvenote/remix-auth-okta/?lang=original
项目主页：https://github.com/curvenote/remix-auth-okta#readme
源码仓库：https://github.com/curvenote/remix-auth-okta

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：12.5 kB，9 个文件
- 模块格式：ES Module
- TypeScript 类型：包内自带
- 运行依赖：3 个
- peer 依赖：remix-auth ^4\.1\.0
- 首次发布：2025-02-05T21:08:21.362Z
- 最新版本发布：2025-06-12T10:57:06.431Z
- 近 30 天下载量：9609（2026-10-11 至 2026-11-09，npm 官方下载统计）
- 已发布版本数：2（近 12 个月 0 个）

## 中文简介

![CI](https://img.shields.io/github/actions/workflow/status/jrakotoharisoa/remix-auth-okta/main.yml?branch=main&style=flat-square) ![npm](https://img.shields.io/npm/v/remix-auth-okta?style=flat-square) (奥克塔战略)

## 安装

```sh
npm install @curvenote/remix-auth-okta
```

也可以使用：`pnpm add @curvenote/remix-auth-okta`、`yarn add @curvenote/remix-auth-okta`、`bun add @curvenote/remix-auth-okta`

## README

![CI](https://img.shields.io/github/actions/workflow/status/jrakotoharisoa/remix-auth-okta/main.yml?branch=main&style=flat-square) ![npm](https://img.shields.io/npm/v/remix-auth-okta?style=flat-square)

# 奥克塔战略

Okta策略用于验证用户对一个okta账户的认证. 它扩展了OAuth2战略.

## 先决条件

### 创建 Okta 网络应用程序

继续前进 [okta 文档](https://developer.okta.com/docs/guides/sign-into-web-app/nodeexpress/main/#understand-the-callback-route) 创建 Okta 网络应用程序并获取客户端身份、客户端秘密和发行者

## 如何使用

#### 创建策略实例

```typescript
// app/utils/auth.server.ts
import { Authenticator } from "remix-auth";
import { OktaStrategy } from "remix-auth-okta";
import type { OktaProfile } from "remix-auth-okta";

type User = {
  id: string;
  profile: OktaProfile;
}

// Create an instance of the authenticator, pass a generic with what your
// strategies will return and will be stored in the session
export const authenticator = new Authenticator<User>(sessionStorage);

let oktaStrategy = new OktaStrategy<User>(
  {
    // example of issuer: https://dev-1234.okta.com/oauth2/default
    issuer: "YOUR_OKTA_ISSUER", 
    clientId: "YOUR_OKTA_CLIENT_ID",
    clientSecret: "YOUR_OKTA_CLIENT_SECRET",
    redirectURI: "https://your-app-domain.com/auth/okta/callback",
  },
  async ({ tokens }) => {
    const { id_token, access_token } = tokens.data as { id_token: string; access_token: string };
    const idClaims = jwt.decode(id_token) as OktaIdTokenClaims;
    // check idClaims.exp
    const profile = await OktaStrategy.userProfile(access_token);

    // Get/verify the user data
    return User.findOrCreate({ email: profile.email });
  }
);

authenticator.use(oktaStrategy);
```

### 设置路线

```typescript
// app/routes/login.tsx
export default function Login() {
  return (
    <Form action="/auth/okta" method="post">
      <button>Login with Okta</button>
    </Form>
  );
}
```

```typescript
// app/routes/auth/okta.tsx
import type { ActionFunction, LoaderFunction } from "remix";

import { authenticator } from "~/utils/auth.server";

export let loader: LoaderFunction = () => redirect("/login");

export let action: ActionFunction = ({ request }) => {
  return authenticator.authenticate("okta", request);
};

```

```typescript
// app/routes/auth/okta/callback.tsx
import type { ActionFunction, LoaderFunction } from "remix";

import { authenticator } from "~/utils/auth.server";

export let loader: LoaderFunction = ({ request }) => {
  const user = await authenticator.authenticate('okta', request);
  if (!user) {
    throw redirect('/login');
  }

  const session = await sessionStorage.getSession(request.headers.get('Cookie'));
  session.set('user', user);

  return redirect('/success', {
    headers: { 'Set-Cookie': await sessionStorage.commitSession(session) },
  });
};
```

## 伪造

这个策略最初来自 [jrakotoharisoa/ remix-auth-okta (英语)](https://github.com/jrakotoharisoa/remix-auth-okta) 但后来修改为使用 `remix-auth@4.*` 财务报告和审定财务报表 修剪回放基于窗体的登录符 .

-   [麻省理工学院许可证原件](https://github.com/jrakotoharisoa/remix-auth-okta)
-   准备了 [242a1f3 (韩语)](https://github.com/jrakotoharisoa/remix-auth-okta/commit/242a1f37f87da278790f039d7b51c01fcd985e79)

## 常见问题

### @curvenote/remix-auth-okta 是什么？

\(奥克塔战略\)

### 如何安装 @curvenote/remix-auth-okta？

在项目目录运行 npm install @curvenote/remix-auth-okta，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：remix-auth（^4\.1\.0）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @curvenote/remix-auth-okta 支持 TypeScript 吗？

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

### @curvenote/remix-auth-okta 支持 ESM 还是 CommonJS？

以 ES Module 形式发布，推荐使用 import 引入。在 CommonJS 项目中，Node\.js 20\.19\+ / 22\.12\+ 可以直接 require\(\) 不含顶层 await 的 ES Module，更早的版本需要改用动态 import\(\)。

### @curvenote/remix-auth-okta 可以商用吗？

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

### @curvenote/remix-auth-okta 的下载量有多少？

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

### @curvenote/remix-auth-okta 还在维护吗？

最新版本 3\.0\.0 发布于 2025/06/12（1\.4 年前）；至今共发布 2 个版本，其中过去 12 个月发布了 0 个；首次发布于 2025/02/06。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

