lxns-rhythm-api 0.1.8 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -0
- package/dist/index.cjs +1508 -0
- package/dist/index.d.ts +239 -59
- package/dist/index.js +260 -84
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -72,6 +72,45 @@ const jacket = await client.maimai.getAsset("jacket", 114);
|
|
|
72
72
|
const icon = await client.chunithm.getAsset("icon", 1);
|
|
73
73
|
```
|
|
74
74
|
|
|
75
|
+
## OAuth 流程
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
import { LxnsOAuthClient } from "lxns-rhythm-api";
|
|
79
|
+
|
|
80
|
+
const client = new LxnsOAuthClient({
|
|
81
|
+
clientId: "<your-client-id>",
|
|
82
|
+
redirectURI: "https://example.com/callback",
|
|
83
|
+
clientSecret: "<your-client-secret>", // PKCE 可不传
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// 1) 生成授权链接,跳转给用户
|
|
87
|
+
const authorizeURL = client.createAuthorizeURL({
|
|
88
|
+
scope: ["read_user_profile", "read_player"],
|
|
89
|
+
state: "nonce", // 可选
|
|
90
|
+
codeChallenge: "<code-challenge>", // PKCE 可选
|
|
91
|
+
codeChallengeMethod: "S256",
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// 2) 回调拿到 code 后换 token
|
|
95
|
+
const token = await client.exchangeCodeForToken({
|
|
96
|
+
code: "<auth-code>",
|
|
97
|
+
codeVerifier: "<code-verifier>", // PKCE 模式传这个
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
// 3) 用 access_token 创建授权态客户端
|
|
101
|
+
const authorized = client.createAuthorizedClient(token.access_token);
|
|
102
|
+
|
|
103
|
+
// 4) 调用 OAuth 用户接口和 personal 接口
|
|
104
|
+
const profile = await authorized.user.getProfile();
|
|
105
|
+
const maimaiPlayer = await authorized.maimai.getPlayer();
|
|
106
|
+
const chunithmPlayer = await authorized.chunithm.getPlayer();
|
|
107
|
+
|
|
108
|
+
// 5) 刷新 token
|
|
109
|
+
const nextToken = await client.refreshAccessToken({
|
|
110
|
+
refreshToken: token.refresh_token,
|
|
111
|
+
});
|
|
112
|
+
```
|
|
113
|
+
|
|
75
114
|
## 错误处理
|
|
76
115
|
|
|
77
116
|
SDK 会将 API 错误统一抛为 `LxnsApiError`。
|
|
@@ -112,6 +151,7 @@ try {
|
|
|
112
151
|
```ts
|
|
113
152
|
import {
|
|
114
153
|
LxnsApiClient,
|
|
154
|
+
LxnsOAuthClient,
|
|
115
155
|
LxnsApiError,
|
|
116
156
|
isLxnsApiError,
|
|
117
157
|
MaimaiModels,
|
|
@@ -123,6 +163,8 @@ import {
|
|
|
123
163
|
|
|
124
164
|
- [Lxns maimai API](https://maimai.lxns.net/docs/api/maimai)
|
|
125
165
|
- [Lxns chunithm API](https://maimai.lxns.net/docs/api/chunithm)
|
|
166
|
+
- [Lxns OAuth API](https://maimai.lxns.net/docs/api/oauth)
|
|
167
|
+
- [Lxns OAuth 接入指南](https://maimai.lxns.net/docs/oauth-guide)
|
|
126
168
|
|
|
127
169
|
## 构建与测试
|
|
128
170
|
|