6
6
7
7
- ** このパッケージは不安定版です**
8
8
- パッチリリースを含め予告なく破壊的変更が行われる場合があります
9
+ - [ TypeDoc] ( https://macropygia.github.io/elysia-openid-client/ )
9
10
10
11
## 仕様・制限事項
11
12
26
27
- ` code_challenge_method ` は ` S256 ` に固定される
27
28
- ` scope ` には自動で ` openid ` が追加される
28
29
29
- ## Usage
30
+ ## 使用方法
31
+
32
+ ``` bash
33
+ bun add elysia-openid-client
34
+ ```
30
35
31
36
``` typescript
32
37
import Elysia from " elysia" ;
@@ -61,7 +66,52 @@ new Elysia()
61
66
62
67
- [ その他のサンプル] ( https://github.com/macropygia/elysia-openid-client/tree/main/examples )
63
68
64
- ## Data Adapter
69
+ ## 設定
70
+
71
+ ``` typescript
72
+ interface OIDCClientOptions {
73
+ issuerUrl: string ;
74
+ baseUrl: string ;
75
+ settings? : Partial <OIDCClientSettings >;
76
+ cookieSettings? : Partial <OIDCClientCookieSettings >;
77
+ dataAdapter? : OIDCClientDataAdapter ;
78
+ logger? : OIDCClientLogger | null ;
79
+ clientMetadata: ClientMetadata & {
80
+ client_secret: string ;
81
+ };
82
+ authParams? : AuthorizationParameters ;
83
+ }
84
+
85
+ const options: OIDCClientOptions = {
86
+ // ...
87
+ }
88
+
89
+ const rp = await OidcClient .create (options );
90
+ ```
91
+
92
+ - [ OIDCClientOptions] ( https://macropygia.github.io/elysia-openid-client/interfaces/types.OIDCClientOptions.html )
93
+ - ` issuerUrl `
94
+ - OpenID ProviderのURL
95
+ - 例: ` https://github.com `
96
+ - ` baseUrl `
97
+ - このプラグインを使用するWebサイト/WebサービスのURL(OpenID Relying Partyとして機能する)
98
+ - 例: ` https:/your-service.example.com `
99
+ - [ OIDCClientSettings] ( https://macropygia.github.io/elysia-openid-client/interfaces/types.OIDCClientSettings.html )
100
+ - 全般設定(パスや有効期限など)
101
+ - [ OIDCClientCookieSettings] ( https://macropygia.github.io/elysia-openid-client/interfaces/types.OIDCClientCookieSettings.html )
102
+ - セッションIDを保管するCookieの設定
103
+ - [ OIDCClientDataAdapter] ( https://macropygia.github.io/elysia-openid-client/interfaces/types.OIDCClientDataAdapter.html )
104
+ - 本文書の ` データアダプター ` の項を参照
105
+ - [ OIDCClientLogger] ( https://macropygia.github.io/elysia-openid-client/interfaces/types.OIDCClientLogger.html )
106
+ - 本文書の ` ロガー ` の項を参照
107
+ - ` ClientMetadata `
108
+ - ` openid-client ` の [ 型定義] ( https://github.com/panva/node-openid-client/blob/main/types/index.d.ts )
109
+ - および ` OpenID Connect Dynamic Client Registration 1.0 ` の [ Client Metadata] ( https://openid.net/specs/openid-connect-registration-1_0.html#ClientMetadata ) の章を参照
110
+ - ` AuthorizationParameters `
111
+ - ` openid-client ` の [ 型定義] ( https://github.com/panva/node-openid-client/blob/main/types/index.d.ts )
112
+ - および ` OpenID Connect Core 1.0 ` の [ Authentication Request] ( https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest ) の章を参照
113
+
114
+ ## データアダプター
65
115
66
116
セッション情報の保存方法を定義したもの。
67
117
@@ -74,6 +124,8 @@ const client = await OidcClient.create({
74
124
```
75
125
76
126
- 本パッケージにはSQLite/LokiJS/Lowdb/Redisを使用したデータアダプターが含まれる
127
+ - カスタムデータアダプターを作成可能
128
+ - 参照: [ OIDCClientDataAdapter] ( https://macropygia.github.io/elysia-openid-client/interfaces/types.OIDCClientDataAdapter.html )
77
129
- 既定ではSQLiteのインメモリーモードが使用される
78
130
- 複数のOPを使用する場合は一つのデータアダプターを共有する
79
131
@@ -118,25 +170,41 @@ const fileAdapter = await LokiFileAdapter.create({
118
170
119
171
### Lowdb
120
172
121
- Use [ Lowdb] ( https://github.com/typicode/lowdb ) .
173
+ [ Lowdb] ( https://github.com/typicode/lowdb ) を使用する。
122
174
123
175
``` bash
124
176
bun add lowdb
125
177
```
126
178
127
- Currently experimental. No information provided.
179
+ ``` typescript
180
+ import { LowdbAdapter } from ' elysia-openid-client/dataAdapters/LowdbAdapter' ;
181
+
182
+ // インメモリーモード
183
+ const memoryAdapter = new LowdbAdapter ();
184
+
185
+ // 永続化モード
186
+ const fileAdapter = new LowdbAdapter ({
187
+ filename: " sessions.json" ,
188
+ })
189
+ ```
128
190
129
191
### Redis
130
192
131
- Use [ Redis] ( https://redis.io/ ) with [ ioredis] ( https://github.com/redis/ioredis ) .
193
+ [ Redis] ( https://redis.io/ ) を [ ioredis] ( https://github.com/redis/ioredis ) で使用する。
132
194
133
195
``` bash
134
196
bun add ioredis
135
197
```
136
198
137
- Currently experimental. No information provided.
199
+ ``` typescript
200
+ import { RedisAdapter } from ' elysia-openid-client/dataAdapters/RedisAdapter' ;
201
+ const redisAdapter = new RedisAdapter ({
202
+ port: 6379 ,
203
+ host: " localhost" ,
204
+ });
205
+ ```
138
206
139
- ### カスタムアダプター
207
+ ### カスタムデータアダプター
140
208
141
209
``` typescript
142
210
// MyDataAdapter.ts
@@ -154,6 +222,73 @@ const client = await OidcClient.create({
154
222
})
155
223
```
156
224
225
+ ## ロガー
226
+
227
+ ロガーを定義する。
228
+
229
+ ``` typescript
230
+ const client = await OidcClient .create ({
231
+ // ...
232
+ logger: <logger >,
233
+ // ...
234
+ })
235
+ ```
236
+
237
+ - [ pino] ( https://getpino.io/ ) に最適化されている
238
+ - 変換すれば任意のロガーを使用可能
239
+ - 省略すると ` consoleLogger("info") ` を使用する
240
+ - ` null ` に設定するとログを出力しない
241
+
242
+ ### ログレベルポリシー
243
+
244
+ - ` silent ` :
245
+ - トークン等のセンシティブ情報のデバッグ用出力
246
+ - 使用時は明示的に表示させる必要がある
247
+ - ` trace ` :
248
+ - 関数やメソッドの呼び出し時に名称を表示
249
+ - ` debug ` :
250
+ - デバッグ情報
251
+ - ` warn ` :
252
+ - 予期しない呼び出し・不正な操作・攻撃などの可能性がある操作の情報
253
+ - ` error ` :
254
+ - キャッチした例外などの情報
255
+ - ` fatal ` :
256
+ - 現状では不使用
257
+
258
+ ### pinoの使用
259
+
260
+ ``` bash
261
+ bun add pino
262
+ ```
263
+
264
+ ``` typescript
265
+ import pino from " pino" ;
266
+ const logger = pino ();
267
+ const client = await OidcClient .create ({
268
+ // ...
269
+ logger ,
270
+ // ...
271
+ })
272
+ ```
273
+
274
+ ### Console logger
275
+
276
+ [ Console] ( https://bun.sh/docs/api/console ) を使用するロガー。
277
+
278
+ ``` typescript
279
+ import { consoleLogger } from " elysia-openid-client/loggers/consoleLogger" ;
280
+ const minimumLogLevel = " debug" ;
281
+ const client = await OidcClient .create ({
282
+ // ...
283
+ logger: consoleLogger (minimumLogLevel ),
284
+ // ...
285
+ })
286
+ ```
287
+
288
+ ### カスタムロガー
289
+
290
+ ` consoleLogger ` の実装を参照のこと。
291
+
157
292
## エンドポイント
158
293
159
294
- Login (GET: ` /auth/login ` )
@@ -197,28 +332,20 @@ const client = await OidcClient.create({
197
332
- セッションが無効な場合
198
333
- ` loginRedirectUrl ` にリダイレクト
199
334
- ` disableRedirect ` が ` false ` の場合は ` sessionStatus ` , ` sessionClaims ` 共に ` null `
335
+ - 設定
336
+ - [ AuthHookOptions] ( https://macropygia.github.io/elysia-openid-client/interfaces/types.AuthHookOptions.html ) .
200
337
201
338
``` typescript
202
- const rp = await OidcClient .create ({ ... } );
203
- const endpoints = rp . getEndpoints ();
204
- const hook = rp . getAuthHook ( {
339
+ const rp = await OidcClient .create (clientOptions );
340
+
341
+ const hookOptions : AuthHookOptions = {
205
342
scope: " scoped" ,
206
343
loginRedirectUrl: " /auth/login" ,
207
344
disableRedirect: false ,
208
345
autoRefresh: true ,
209
- });
346
+ }
210
347
211
- new Elysia ()
212
- .use (endpoints )
213
- .guard ((app ) =>
214
- app
215
- .use (hook )
216
- .get (" /" , ({
217
- sessionStatus ,
218
- sessionClaims ,
219
- }) => sessionStatus ? " Logged in" : " Not logged in" )
220
- )
221
- .listen (80 );
348
+ const hook = rp .getAuthHook (hookOptions );
222
349
```
223
350
224
351
## Contributing
0 commit comments