Skip to content

Commit 7a8ccc5

Browse files
committed
docs(readme): update readme
1 parent f72c6ab commit 7a8ccc5

File tree

2 files changed

+285
-42
lines changed

2 files changed

+285
-42
lines changed

README.ja.md

+145-23
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
- `code_challenge_method``S256` に固定される
2828
- `scope` には自動で `openid` が追加される
2929

30-
## Usage
30+
## 使用方法
3131

3232
```bash
33-
bun add elysia-openid-clitent
33+
bun add elysia-openid-client
3434
```
3535

3636
```typescript
@@ -66,7 +66,52 @@ new Elysia()
6666

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

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

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

@@ -79,6 +124,8 @@ const client = await OidcClient.create({
79124
```
80125

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

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

124171
### Lowdb
125172

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

128175
```bash
129176
bun add lowdb
130177
```
131178

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

134191
### Redis
135192

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

138195
```bash
139196
bun add ioredis
140197
```
141198

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

144-
### カスタムアダプター
207+
### カスタムデータアダプター
145208

146209
```typescript
147210
// MyDataAdapter.ts
@@ -159,6 +222,73 @@ const client = await OidcClient.create({
159222
})
160223
```
161224

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

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

206338
```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 = {
210342
scope: "scoped",
211343
loginRedirectUrl: "/auth/login",
212344
disableRedirect: false,
213345
autoRefresh: true,
214-
});
346+
}
215347

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);
227349
```
228350

229351
## Contributing

0 commit comments

Comments
 (0)