Skip to content

Commit fcb188f

Browse files
authored
Merge pull request #3 from macropygia/feature/docs
Update docs
2 parents c778ba4 + 7a8ccc5 commit fcb188f

File tree

3 files changed

+297
-42
lines changed

3 files changed

+297
-42
lines changed

README.ja.md

+149-22
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

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

1011
## 仕様・制限事項
1112

@@ -26,7 +27,11 @@
2627
- `code_challenge_method``S256` に固定される
2728
- `scope` には自動で `openid` が追加される
2829

29-
## Usage
30+
## 使用方法
31+
32+
```bash
33+
bun add elysia-openid-client
34+
```
3035

3136
```typescript
3237
import Elysia from "elysia";
@@ -61,7 +66,52 @@ new Elysia()
6166

6267
- [その他のサンプル](https://github.com/macropygia/elysia-openid-client/tree/main/examples)
6368

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+
## データアダプター
65115

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

@@ -74,6 +124,8 @@ const client = await OidcClient.create({
74124
```
75125

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

@@ -118,25 +170,41 @@ const fileAdapter = await LokiFileAdapter.create({
118170

119171
### Lowdb
120172

121-
Use [Lowdb](https://github.com/typicode/lowdb).
173+
[Lowdb](https://github.com/typicode/lowdb)を使用する。
122174

123175
```bash
124176
bun add lowdb
125177
```
126178

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+
```
128190

129191
### Redis
130192

131-
Use [Redis](https://redis.io/) with [ioredis](https://github.com/redis/ioredis).
193+
[Redis](https://redis.io/)[ioredis](https://github.com/redis/ioredis)で使用する。
132194

133195
```bash
134196
bun add ioredis
135197
```
136198

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+
```
138206

139-
### カスタムアダプター
207+
### カスタムデータアダプター
140208

141209
```typescript
142210
// MyDataAdapter.ts
@@ -154,6 +222,73 @@ const client = await OidcClient.create({
154222
})
155223
```
156224

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+
157292
## エンドポイント
158293

159294
- Login (GET: `/auth/login` )
@@ -197,28 +332,20 @@ const client = await OidcClient.create({
197332
- セッションが無効な場合
198333
- `loginRedirectUrl` にリダイレクト
199334
- `disableRedirect``false` の場合は `sessionStatus` , `sessionClaims` 共に `null`
335+
- 設定
336+
- [AuthHookOptions](https://macropygia.github.io/elysia-openid-client/interfaces/types.AuthHookOptions.html).
200337

201338
```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 = {
205342
scope: "scoped",
206343
loginRedirectUrl: "/auth/login",
207344
disableRedirect: false,
208345
autoRefresh: true,
209-
});
346+
}
210347

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);
222349
```
223350

224351
## Contributing

0 commit comments

Comments
 (0)