27
27
- ` code_challenge_method ` は ` S256 ` に固定される
28
28
- ` scope ` には自動で ` openid ` が追加される
29
29
30
- ## Usage
30
+ ## 使用方法
31
31
32
32
``` bash
33
- bun add elysia-openid-clitent
33
+ bun add elysia-openid-client
34
34
```
35
35
36
36
``` typescript
@@ -66,7 +66,52 @@ new Elysia()
66
66
67
67
- [ その他のサンプル] ( https://github.com/macropygia/elysia-openid-client/tree/main/examples )
68
68
69
- ## 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
+ ## データアダプター
70
115
71
116
セッション情報の保存方法を定義したもの。
72
117
@@ -79,6 +124,8 @@ const client = await OidcClient.create({
79
124
```
80
125
81
126
- 本パッケージにはSQLite/LokiJS/Lowdb/Redisを使用したデータアダプターが含まれる
127
+ - カスタムデータアダプターを作成可能
128
+ - 参照: [ OIDCClientDataAdapter] ( https://macropygia.github.io/elysia-openid-client/interfaces/types.OIDCClientDataAdapter.html )
82
129
- 既定ではSQLiteのインメモリーモードが使用される
83
130
- 複数のOPを使用する場合は一つのデータアダプターを共有する
84
131
@@ -123,25 +170,41 @@ const fileAdapter = await LokiFileAdapter.create({
123
170
124
171
### Lowdb
125
172
126
- Use [ Lowdb] ( https://github.com/typicode/lowdb ) .
173
+ [ Lowdb] ( https://github.com/typicode/lowdb ) を使用する。
127
174
128
175
``` bash
129
176
bun add lowdb
130
177
```
131
178
132
- 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
+ ```
133
190
134
191
### Redis
135
192
136
- Use [ Redis] ( https://redis.io/ ) with [ ioredis] ( https://github.com/redis/ioredis ) .
193
+ [ Redis] ( https://redis.io/ ) を [ ioredis] ( https://github.com/redis/ioredis ) で使用する。
137
194
138
195
``` bash
139
196
bun add ioredis
140
197
```
141
198
142
- 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
+ ```
143
206
144
- ### カスタムアダプター
207
+ ### カスタムデータアダプター
145
208
146
209
``` typescript
147
210
// MyDataAdapter.ts
@@ -159,6 +222,73 @@ const client = await OidcClient.create({
159
222
})
160
223
```
161
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
+
162
292
## エンドポイント
163
293
164
294
- Login (GET: ` /auth/login ` )
@@ -202,28 +332,20 @@ const client = await OidcClient.create({
202
332
- セッションが無効な場合
203
333
- ` loginRedirectUrl ` にリダイレクト
204
334
- ` disableRedirect ` が ` false ` の場合は ` sessionStatus ` , ` sessionClaims ` 共に ` null `
335
+ - 設定
336
+ - [ AuthHookOptions] ( https://macropygia.github.io/elysia-openid-client/interfaces/types.AuthHookOptions.html ) .
205
337
206
338
``` typescript
207
- const rp = await OidcClient .create ({ ... } );
208
- const endpoints = rp . getEndpoints ();
209
- const hook = rp . getAuthHook ( {
339
+ const rp = await OidcClient .create (clientOptions );
340
+
341
+ const hookOptions : AuthHookOptions = {
210
342
scope: " scoped" ,
211
343
loginRedirectUrl: " /auth/login" ,
212
344
disableRedirect: false ,
213
345
autoRefresh: true ,
214
- });
346
+ }
215
347
216
- new Elysia ()
217
- .use (endpoints )
218
- .guard ((app ) =>
219
- app
220
- .use (hook )
221
- .get (" /" , ({
222
- sessionStatus ,
223
- sessionClaims ,
224
- }) => sessionStatus ? " Logged in" : " Not logged in" )
225
- )
226
- .listen (80 );
348
+ const hook = rp .getAuthHook (hookOptions );
227
349
```
228
350
229
351
## Contributing
0 commit comments