Skip to content

Commit a0fccf3

Browse files
authored
Merge pull request #5 from macropygia/feature/provenance-publish
Update docs
2 parents bc8f00e + e6afb2c commit a0fccf3

17 files changed

+270
-206
lines changed

.github/workflows/checks-pr.yml

+3-4
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@ on:
99
- 'biome.json'
1010
- 'package.json'
1111
- 'tsconfig.json'
12-
- '!**/.github/**'
13-
- '!**/.vscode/**'
14-
- '!**/examples/**'
1512
- '!**/*.config.ts'
16-
- '!./build.ts'
13+
- '!**/.*/**'
14+
- '!**/__*__/**'
15+
- '**/__test__/**'
1716
pull_request:
1817
branches:
1918
- main

.github/workflows/docs.yml

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ name: Deploy Docs
33
on:
44
workflow_dispatch:
55

6+
defaults:
7+
run:
8+
shell: bash
9+
610
jobs:
711
deploy_docs:
812
permissions:

.github/workflows/publish-dry-run.yml

-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ defaults:
77
run:
88
shell: bash
99

10-
permissions:
11-
contents: write
12-
1310
jobs:
1411
publish_dry_run:
1512
runs-on: ubuntu-latest

.github/workflows/publish.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ permissions:
1414
jobs:
1515
publish:
1616
runs-on: ubuntu-latest
17+
permissions:
18+
id-token: write
1719
steps:
1820
- uses: actions/checkout@v4
1921

@@ -39,7 +41,7 @@ jobs:
3941
with:
4042
node-version: 20
4143
registry-url: "https://registry.npmjs.org"
42-
- run: npm publish --access public
44+
- run: npm publish --provenance --access public
4345
env:
4446
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
4547

.github/workflows/release-drafter-pr.yml

-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ defaults:
1010
run:
1111
shell: bash
1212

13-
permissions:
14-
contents: read
15-
1613
jobs:
1714
update_release_draft:
1815
permissions:

.github/workflows/release-drafter-sync-manual.yml

-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ defaults:
77
run:
88
shell: bash
99

10-
permissions:
11-
contents: read
12-
1310
jobs:
1411
update_release_draft_and_version_sync:
1512
env:

.github/workflows/release-drafter-sync-push.yml

-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ defaults:
99
run:
1010
shell: bash
1111

12-
permissions:
13-
contents: read
14-
1512
jobs:
1613
update_release_draft_and_version_sync:
1714
env:

README.ja.md

+88-85
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
- **このパッケージは不安定版です**
88
- パッチリリースを含め予告なく破壊的変更が行われる場合があります
9-
- [TypeDoc](https://macropygia.github.io/elysia-openid-client/)
9+
- Links: [GitHub](https://github.com/macropygia/elysia-openid-client) / [npm](https://www.npmjs.com/package/elysia-openid-client) / [TypeDoc](https://macropygia.github.io/elysia-openid-client/)
1010

1111
## 仕様・制限事項
1212

@@ -38,23 +38,26 @@ import Elysia from "elysia";
3838
import { OidcClient } from "elysia-openid-client";
3939

4040
const rp = await OidcClient.create({
41-
baseUrl: "https://app.example.com",
42-
issuerUrl: "https://issuer.example.com",
41+
baseUrl: "https://app.example.com", // RPのURL
42+
issuerUrl: "https://issuer.example.com", // OPのURL
4343
clientMetadata: {
4444
client_id: "client-id",
4545
client_secret: "client-secret",
4646
},
4747
});
48-
const endpoints = rp.getEndpoints();
49-
const hook = rp.getAuthHook();
48+
const endpoints = rp.getEndpoints(); // エンドポイントプラグイン
49+
const hook = rp.getAuthHook(); // フックプラグイン
5050

51-
console.log(rp.issuerMetadata);
51+
console.log(rp.issuerMetadata); // OPのメタデータを表示
5252

5353
new Elysia()
54-
.use(endpoints)
55-
.guard((app) =>
54+
.use(endpoints) // エンドポイントを挿入
55+
.guard((app) => // この内側が要認証エリア
5656
app
57-
.use(hook)
57+
.use(hook) // 認証・認可用のonBeforeHandleフックを挿入
58+
.onBeforeHandle(({ sessionStatus, sessionClaims }) => {
59+
// ユーザー名・メール・グループ等による認可処理
60+
})
5861
.get("/", ({ sessionStatus }) => sessionStatus ? "Logged in" : "Restricted")
5962
.get("/status", ({ sessionStatus }) => sessionStatus)
6063
.get("/claims", ({ sessionClaims }) => sessionClaims),
@@ -64,7 +67,7 @@ new Elysia()
6467
.listen(80);
6568
```
6669

67-
- [その他のサンプル](https://github.com/macropygia/elysia-openid-client/tree/main/examples)
70+
- [その他のサンプル](https://github.com/macropygia/elysia-openid-client/tree/main/__examples__)
6871

6972
## 設定
7073

@@ -105,29 +108,87 @@ const rp = await OidcClient.create(options);
105108
- [OIDCClientLogger](https://macropygia.github.io/elysia-openid-client/interfaces/types.OIDCClientLogger.html)
106109
- 本文書の `ロガー` の項を参照
107110
- `ClientMetadata`
108-
- `openid-client`[型定義](https://github.com/panva/node-openid-client/blob/main/types/index.d.ts)
111+
- `openid-client`[`ClientMetadata` の型定義](https://github.com/panva/node-openid-client/blob/main/types/index.d.ts)
109112
- および `OpenID Connect Dynamic Client Registration 1.0`[Client Metadata](https://openid.net/specs/openid-connect-registration-1_0.html#ClientMetadata) の章を参照
110113
- `AuthorizationParameters`
111-
- `openid-client`[型定義](https://github.com/panva/node-openid-client/blob/main/types/index.d.ts)
114+
- `openid-client`[`AuthorizationParameters` の型定義](https://github.com/panva/node-openid-client/blob/main/types/index.d.ts)
112115
- および `OpenID Connect Core 1.0`[Authentication Request](https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest) の章を参照
113116

117+
## エンドポイント
118+
119+
- ElysiaJSプラグインとしてのメタデータ
120+
- 名称: `elysia-openid-client-endpoints`
121+
- [シード](https://elysiajs.com/essential/plugin#plugin-deduplication): `settings.pluginSeed` 、未指定なら `issuerUrl`
122+
- 参照: [openid-client API Documentation - Client](https://github.com/panva/node-openid-client/blob/main/docs/README.md#client)
123+
124+
### 内訳
125+
126+
- Login (GET: `/auth/login` )
127+
- `openid-client``client.authorizationUrl` を呼び出す
128+
- OPの認証エンドポイントにリダイレクトする
129+
- Callback (GET: `/auth/callback` )
130+
- `openid-client``client.callbackParams``client.callback` を呼び出す
131+
- OPからリダイレクトされた後、ログイン完了ページにリダイレクトする
132+
- Logout (GET: `/auth/logout` )
133+
- `openid-client``client.endSessionUrl` を呼び出す
134+
- OPのログアウトエンドポイントにリダイレクトする
135+
- UserInfo (ALL: `/auth/userinfo` )
136+
- `openid-client``client.userinfo` を呼び出す
137+
- レスポンス(ユーザー情報)をそのまま返す
138+
- Introspect (ALL: `/auth/introspect` )
139+
- `openid-client``client.introspect` を呼び出す
140+
- レスポンスをそのまま返す
141+
- Refresh (ALL: `/auth/refresh` )
142+
- `openid-client``client.refresh` を呼び出す
143+
- ID Tokenに含まれるクレームを返す
144+
- Resource (GET: `/auth/resource?url=<resource-url>`)
145+
- `openid-client``client.requestResource` を呼び出す
146+
- リソースプロバイダーからのレスポンスを返す
147+
- Revoke (ALL: `/auth/revoke` )
148+
- `openid-client``client.revoke` を呼び出す
149+
- `204` を返す
150+
- Status (ALL: `/auth/status` )
151+
- 内部データベースからセッションステータスを取得する
152+
- OPにはアクセスしない
153+
- Claims (ALL: `/auth/claims` )
154+
- ID Tokenに含まれるクレームを取得する
155+
- OPにはアクセスしない
156+
157+
## フック
158+
159+
`onBeforeHandle` フックでCookieを元にセッションが有効かどうかを判断し、 [`resolve` フック](https://elysiajs.com/life-cycle/before-handle.html#resolve)から `sessionStatus``sessionClaims` を返す。
160+
161+
- セッションが有効な場合
162+
- `sessionStatus` : セッションステータス
163+
- 参照: [OIDCClientSessionStatus](https://macropygia.github.io/elysia-openid-client/interfaces/types.OIDCClientSessionStatus.html)
164+
- `sessionClaims` : ID Token Claims
165+
- 参照: [`IdTokenClaims` type definition](https://github.com/panva/node-openid-client/blob/main/types/index.d.ts) of `openid-client`.
166+
- 参照: `OpenID Connect Core 1.0`[Claims](https://openid.net/specs/openid-connect-core-1_0.html#Claims) 及び [IDToken](https://openid.net/specs/openid-connect-core-1_0.html#IDToken) の章
167+
- セッションが無効な場合
168+
- `loginRedirectUrl` にリダイレクト
169+
- `disableRedirect``true` の場合は `sessionStatus` , `sessionClaims` 共に `null` になる
170+
- ElysiaJSプラグインとしてのメタデータ
171+
- 名称: `elysia-openid-client-auth-hook`
172+
- [シード](https://elysiajs.com/essential/plugin#plugin-deduplication): `settings.pluginSeed` 、未指定なら `issuerUrl`
173+
- 参照: [AuthHookOptions](https://macropygia.github.io/elysia-openid-client/interfaces/types.AuthHookOptions.html)
174+
114175
## データアダプター
115176

116177
セッション情報の保存方法を定義したもの。
117178

118179
```typescript
119-
const client = await OidcClient.create({
180+
const rp = await OidcClient.create({
120181
//...
121-
dataAdapter: <data-adapter>,
182+
dataAdapter: OIDCClientDataAdapter,
122183
//...
123184
})
124185
```
125186

126187
- 本パッケージにはSQLite/LokiJS/Lowdb/Redisを使用したデータアダプターが含まれる
127188
- カスタムデータアダプターを作成可能
128-
- 参照: [OIDCClientDataAdapter](https://macropygia.github.io/elysia-openid-client/interfaces/types.OIDCClientDataAdapter.html)
129189
- 既定ではSQLiteのインメモリーモードが使用される
130190
- 複数のOPを使用する場合は一つのデータアダプターを共有する
191+
- 参照: [OIDCClientDataAdapter](https://macropygia.github.io/elysia-openid-client/interfaces/types.OIDCClientDataAdapter.html)
131192

132193
### SQLite
133194

@@ -215,7 +276,7 @@ export class MyDataAdapter implements OIDCClientDataAdapter {
215276

216277
// app.ts
217278
import { MyDataAdapter } from 'path/to/MyDataAdapter';
218-
const client = await OidcClient.create({
279+
const rp = await OidcClient.create({
219280
//...
220281
dataAdapter: new MyDataAdapter(),
221282
//...
@@ -227,9 +288,9 @@ const client = await OidcClient.create({
227288
ロガーを定義する。
228289

229290
```typescript
230-
const client = await OidcClient.create({
291+
const rp = await OidcClient.create({
231292
//...
232-
logger: <logger>,
293+
logger: OIDCClientLogger | null,
233294
//...
234295
})
235296
```
@@ -238,6 +299,7 @@ const client = await OidcClient.create({
238299
- 変換すれば任意のロガーを使用可能
239300
- 省略すると `consoleLogger("info")` を使用する
240301
- `null` に設定するとログを出力しない
302+
- 参照: [OIDCClientLogger](https://macropygia.github.io/elysia-openid-client/interfaces/types.OIDCClientLogger.html)
241303

242304
### ログレベルポリシー
243305

@@ -257,16 +319,17 @@ const client = await OidcClient.create({
257319

258320
### pinoの使用
259321

322+
直接[pino](https://getpino.io/)を割り当てられる
323+
260324
```bash
261325
bun add pino
262326
```
263327

264328
```typescript
265329
import pino from "pino";
266-
const logger = pino();
267-
const client = await OidcClient.create({
330+
const rp = await OidcClient.create({
268331
//...
269-
logger,
332+
logger: pino(),
270333
//...
271334
})
272335
```
@@ -277,8 +340,8 @@ const client = await OidcClient.create({
277340

278341
```typescript
279342
import { consoleLogger } from "elysia-openid-client/loggers/consoleLogger";
280-
const minimumLogLevel = "debug";
281-
const client = await OidcClient.create({
343+
const minimumLogLevel = "debug"; // pinoと同様
344+
const rp = await OidcClient.create({
282345
//...
283346
logger: consoleLogger(minimumLogLevel),
284347
//...
@@ -287,68 +350,8 @@ const client = await OidcClient.create({
287350

288351
### カスタムロガー
289352

290-
`consoleLogger` の実装を参照のこと。
291-
292-
## エンドポイント
293-
294-
- Login (GET: `/auth/login` )
295-
- `openid-client``client.authorizationUrl` を呼び出す
296-
- OPの認証エンドポイントにリダイレクトする
297-
- Callback (GET: `/auth/callback` )
298-
- `openid-client``client.callbackParams``client.callback` を呼び出す
299-
- OPからリダイレクトされた後、ログイン完了ページにリダイレクトする
300-
- Logout (GET: `/auth/logout` )
301-
- `openid-client``client.endSessionUrl` を呼び出す
302-
- OPのログアウトエンドポイントにリダイレクトする
303-
- UserInfo (ALL: `/auth/userinfo` )
304-
- `openid-client``client.userinfo` を呼び出す
305-
- レスポンス(ユーザー情報)をそのまま返す
306-
- Introspect (ALL: `/auth/introspect` )
307-
- `openid-client``client.introspect` を呼び出す
308-
- レスポンスをそのまま返す
309-
- Refresh (ALL: `/auth/refresh` )
310-
- `openid-client``client.refresh` を呼び出す
311-
- ID Tokenに含まれるクレームを返す
312-
- Resouce (GET: `/auth/resource?url=<resource-url>`)
313-
- `openid-client``client.requestResource` を呼び出す
314-
- リソースプロバイダーからのレスポンスを返す
315-
- Revoke (ALL: `/auth/revoke` )
316-
- `openid-client``client.revoke` を呼び出す
317-
- `204` を返す
318-
- Status (ALL: `/auth/status` )
319-
- 内部データベースからセッションステータスを取得する
320-
- OPにはアクセスしない
321-
- Claims (ALL: `/auth/claims` )
322-
- ID Tokenに含まれるクレームを取得する
323-
- OPにはアクセスしない
324-
325-
## フック
326-
327-
`onBeforeHook` フックでCookieを元にセッションが有効かどうかを判断し、 [`resolve` フック](https://elysiajs.com/life-cycle/before-handle.html#resolve)から `sessionStatus``sessionClaims` を返す。
328-
329-
- セッションが有効な場合
330-
- `sessionStatus` : セッションステータス
331-
- `sessionClaims` : ID Token Claims
332-
- セッションが無効な場合
333-
- `loginRedirectUrl` にリダイレクト
334-
- `disableRedirect``false` の場合は `sessionStatus` , `sessionClaims` 共に `null`
335-
- 設定
336-
- [AuthHookOptions](https://macropygia.github.io/elysia-openid-client/interfaces/types.AuthHookOptions.html).
337-
338-
```typescript
339-
const rp = await OidcClient.create(clientOptions);
340-
341-
const hookOptions: AuthHookOptions = {
342-
scope: "scoped",
343-
loginRedirectUrl: "/auth/login",
344-
disableRedirect: false,
345-
autoRefresh: true,
346-
}
347-
348-
const hook = rp.getAuthHook(hookOptions);
349-
```
353+
[OIDCClientLogger](https://macropygia.github.io/elysia-openid-client/interfaces/types.OIDCClientLogger.html)の型定義と `consoleLogger` の実装を参照のこと。
350354

351355
## Contributing
352356

353-
本リポジトリに提供するコードを `GitHub Copilot` で生成する場合、必ず `Suggestions matching public code` オプションを `Block` に設定すること。
354-
同様のオプションが存在する類似のサービスを使用する場合も同様。
357+
本リポジトリに提供するコードを `GitHub Copilot` で生成する場合、必ず `Suggestions matching public code` オプションを `Block` に設定すること。同様のオプションが存在する類似のサービスを使用する場合も同様。

0 commit comments

Comments
 (0)