halo/ui/packages/api-client
guqing ae6724a2b6
feat: implement persistent token based remember me mechanism (#6131)
#### What type of PR is this?
/kind feature
/area core
/milestone 2.17.x

#### What this PR does / why we need it:
新增基于持久化 Token 的 RememberMe 机制

本次更新引入了一种新的 RememberMe 机制,该机制基于持久化 Token,以增强安全性和管理灵活性。在此之前,RememberMe 功能通过以下方式生成 Token,并将其作为 cookie 发送回客户端:
```
 username + ":" + expiryTime + ":" + algorithmName + ":"
   + algorithmHex(username + ":" + expiryTime + ":" + password + ":" + key)
```
此方法的优点在于无需存储 Token 就可以进行验证,并且用户密码的更改会自动使 Token 失效。然而,它的主要缺点是缺乏管理能力,例如无法手动撤销 Token。

鉴于最新的设备管理需求(见 PR #6100),我们需要一种支持设备撤销(revoke)的机制。因此,我们采用了持久化 Token 的方式,并通过随机生成的方法来提高安全性,而不将用户名和密码直接签名在 Token 中。新的 Token 格式如下:
```
base64(tokenValue:series)
```
此更改将为系统带来更高的安全保障和更灵活的管理选项,特别是在需要高度控制和监管设备访问时。

#### Does this PR introduce a user-facing change?
```release-note
引入基于持久化 Token 的新 RememberMe 机制以增强安全性和管理灵活性,升级后需要重新登录
```
2024-06-26 08:40:49 +00:00
..
entry fix: incorrect root path in API client requests (#6136) 2024-06-25 06:42:45 +00:00
src feat: implement persistent token based remember me mechanism (#6131) 2024-06-26 08:40:49 +00:00
.eslintignore Move folder console to ui 2024-02-02 22:22:51 +08:00
.eslintrc.js Move folder console to ui 2024-02-02 22:22:51 +08:00
.gitignore Move folder console to ui 2024-02-02 22:22:51 +08:00
.openapi_config.yaml Generate API docs and regenerate API client (#5742) 2024-04-19 02:34:07 +00:00
.prettierrc.js chore: bump vite to 5.x (#5920) 2024-05-16 06:18:36 +00:00
README.md feat: add requests library as a global shared dependency 2024-06-25 12:31:44 +08:00
build.config.ts Move folder console to ui 2024-02-02 22:22:51 +08:00
openapitools.json Generate API docs and regenerate API client (#5742) 2024-04-19 02:34:07 +00:00
package.json feat: add requests library as a global shared dependency 2024-06-25 12:31:44 +08:00
tsconfig.json feat: add requests library as a global shared dependency 2024-06-25 12:31:44 +08:00
vite.config.ts feat: add requests library as a global shared dependency 2024-06-25 12:31:44 +08:00

README.md

@halo-dev/api-client

Halo 2.0 的 JavaScript API 客户端请求库。使用 OpenAPI Generator 生成。

使用

import {
  coreApiClient,
  consoleApiClient,
  ucApiClient,
  publicApiClient,
  createCoreApiClient,
  createConsoleApiClient,
  createUcApiClient,
  createPublicApiClient,
  axiosInstance
} from "@halo-dev/api-client"
  • coreApiClient: 为 Halo 所有自定义模型的 CRUD 接口封装的 api client。
  • consoleApiClient: 为 Halo 针对 Console 提供的接口封装的 api client。
  • ucApiClient: 为 Halo 针对 UC 提供的接口封装的 api client。
  • publicApiClient: 为 Halo 所有公开访问的接口封装的 api client。
  • createCoreApiClient: 用于创建自定义模型的 CRUD 接口封装的 api client需要传入 baseURL 和 axios 实例。
  • createConsoleApiClient: 用于创建 Console 接口封装的 api client需要传入 baseURL 和 axios 实例。
  • createUcApiClient: 用于创建 UC 接口封装的 api client需要传入 baseURL 和 axios 实例。
  • createPublicApiClient: 用于创建公开访问接口封装的 api client需要传入 baseURL 和 axios 实例。
  • axiosInstance: 内部默认创建的 axios 实例。

在插件中使用

pnpm install @halo-dev/api-client axios

由于已经在 Console 和 UC 项目中引入并设置好了 Axios 拦截器,所以直接使用即可:

import { coreApiClient } from "@halo-dev/api-client"

coreApiClient.content.post.listContentHaloRunV1alpha1Post().then(response => {
  // handle response
})

此外,在最新的 @halo-dev/ui-plugin-bundler-kit@2.17.0 中,已经排除了 @halo-dev/api-clientaxios 依赖,所以最终产物中的相关依赖会自动使用 Halo 本身提供的依赖,无需关心最终产物大小。

在外部项目中使用

pnpm install @halo-dev/api-client axios
import axios from "axios"

const axiosInstance = axios.create({
  baseURL: "http://localhost:8090"
})

const coreApiClient = createCoreApiClient(axiosInstance)

coreApiClient.content.post.listContentHaloRunV1alpha1Post().then(response => {
  // handle response
})