Skip to content

Commit 775f1fd

Browse files
committed
feat: change to retreive plugins with getter
1 parent 8d04ef1 commit 775f1fd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+937
-395
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"elysia-openid-client": patch
3+
---
4+
5+
Add auto refresh to `userinfo`, `introspect`, `resource`, `status` and `claims` endpoints

.changeset/friendly-planes-greet.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"elysia-openid-client": patch
3+
---
4+
5+
(Breaking) Changed `getEndpoints()` and `getAuthHook()` to getter methods `endpoints` and `authHook`

.changeset/large-donuts-hope.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"elysia-openid-client": patch
3+
---
4+
5+
(Breaking) Move hook settings to client options

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
### Patch Changes
66

77
- 05731b2: Add defineConfig
8-
- 05731b2: Change factory method name from create to factory
8+
- 05731b2: (Breaking) Change factory method name from `create` to `factory`
99
- 6797fa2: Update docs

README.ja.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
詳しい情報は[公式ドキュメント](https://macropygia.github.io/elysia-openid-client/ja/getting-started/)を参照
2323

2424
- 仕様・機能・特徴: [Introduction](https://macropygia.github.io/elysia-openid-client/ja/getting-started/)
25-
- 出力サンプル: [Sample Output](https://macropygia.github.io/elysia-openid-client/ja/sample-output/)
2625
- クイックスタートガイド: [Getting Started](https://macropygia.github.io/elysia-openid-client/ja/getting-started/)
2726

2827
## Contributing

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
- All authentication/authorization information is stored on the server side.
1212
- The status is passed to routing using the [resolve](https://elysiajs.com/life-cycle/before-handle.html#resolve) hook.
13-
- Use cookies to identify users.
13+
- Use Cookie to identify users.
1414
- Depends on [Bun](https://bun.sh/).
1515
- Only TypeScript files included.
1616
- [Only works as ESM](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).
@@ -22,7 +22,6 @@
2222
Detailed information can be found in the [official documentation](https://macropygia.github.io/elysia-openid-client/).
2323

2424
- List of features and specifications: [Introduction](https://macropygia.github.io/elysia-openid-client/)
25-
- [Sample Output](https://macropygia.github.io/elysia-openid-client/ja/sample-output/)
2625
- Quick start guide: [Getting Started](https://macropygia.github.io/elysia-openid-client/getting-started/)
2726

2827
## Contributing

__mock__/const.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { mock } from "bun:test";
2-
import { defaultCookieSettings, defaultSettings } from "@/const";
2+
import {
3+
defaultAuthHookSettings,
4+
defaultCookieSettings,
5+
defaultSettings,
6+
} from "@/const";
37
import type { OidcClient } from "@/core/OidcClient";
48
import { consoleLogger } from "@/loggers/consoleLogger";
59
import type {
@@ -8,6 +12,7 @@ import type {
812
OIDCClientSession,
913
} from "@/types";
1014
import type { Cookie } from "elysia";
15+
import { t } from "elysia";
1116
import type { IdTokenClaims } from "openid-client";
1217

1318
export type DeepPartial<T> = T extends object
@@ -46,6 +51,7 @@ export const mockBaseOptions = {
4651
},
4752
authParams: {},
4853
settings: defaultSettings,
54+
authHookSettings: defaultAuthHookSettings,
4955
cookieSettings: {
5056
...defaultCookieSettings,
5157
secure: false,
@@ -107,13 +113,18 @@ export const mockActiveSessionWithRealIdToken: OIDCClientActiveSession = {
107113
sessionExpiresAt: 5000000000000,
108114
};
109115

116+
export const mockActiveSessionWithRealIdTokenRefreshed: OIDCClientActiveSession =
117+
{
118+
...mockActiveSessionWithRealIdToken,
119+
accessToken: "mock-access-token-refreshed",
120+
refreshToken: "mock-refresh-token-refreshed",
121+
sessionExpiresAt: 5000000000001,
122+
};
123+
110124
export const mockActiveSessionWithRealIdTokenExpired: OIDCClientActiveSession =
111125
{
112-
sessionId: "mock-session-id",
126+
...mockActiveSessionWithRealIdToken,
113127
idToken: mockIdTokenExpired,
114-
accessToken: "mock-access-token",
115-
refreshToken: "mock-refresh-token",
116-
sessionExpiresAt: 5000000000000,
117128
};
118129

119130
export const mockPostInit = (sid?: string): RequestInit => ({
@@ -153,10 +164,9 @@ export const mockBaseClient = {
153164
updateSession: mock(),
154165
fetchSession: mock(),
155166
deleteSession: mock(),
156-
getSessionIdCookieType: mock(),
157-
getCookieDefinition: mock(),
158-
getAuthHook: mock(),
159-
getEndpoints: mock(),
167+
cookieTypeBox: t.Cookie({ "mock-cookie-name": t.String() }),
168+
createAuthHook: mock(),
169+
createEndpoints: mock(),
160170
logger: mockLogger,
161171
initialized: true,
162172
client: {},

__test__/general.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe("Integration/general", async () => {
2626
},
2727
authParams: {},
2828
});
29-
const endpoints = oidcClient.getEndpoints();
29+
const endpoints = oidcClient.endpoints;
3030
const app = new Elysia()
3131
.get("/", () => "home")
3232
.use(endpoints)
@@ -128,6 +128,6 @@ describe("Integration/general", async () => {
128128
});
129129

130130
test("beforeHandle", () => {
131-
expect(oidcClient.getAuthHook({ scope: "scoped" })).toBeTruthy();
131+
expect(oidcClient.authHook).toBeTruthy();
132132
});
133133
});

biome.json

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,21 @@
3333
},
3434
"javascript": {
3535
"globals": ["Astro", "Bun"]
36-
}
36+
},
37+
"overrides": [
38+
{
39+
"include": ["*.test.ts"],
40+
"linter": {
41+
"rules": {
42+
"suspicious": {
43+
"noEmptyBlockStatements": "off",
44+
"noExplicitAny": "off"
45+
},
46+
"performance": {
47+
"noDelete": "off"
48+
}
49+
}
50+
}
51+
}
52+
]
3753
}

src/const.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import type { OIDCClientCookieSettings, OIDCClientSettings } from "@/types";
1+
import type {
2+
OIDCClientAuthHookSettings,
3+
OIDCClientCookieSettings,
4+
OIDCClientSettings,
5+
} from "@/types";
6+
import { t } from "elysia";
27
import type { LoggerOptions } from "pino";
38

49
/**
@@ -33,6 +38,19 @@ export const defaultCookieSettings: OIDCClientCookieSettings = {
3338
path: "/",
3439
};
3540

41+
/**
42+
* Auth hook settings
43+
*/
44+
export const defaultAuthHookSettings: Omit<
45+
OIDCClientAuthHookSettings,
46+
"loginRedirectUrl"
47+
> = {
48+
scope: "scoped",
49+
// loginRedirectUrl: `${pathPrefix}${loginPath}`,
50+
disableRedirect: false,
51+
autoRefresh: true,
52+
};
53+
3654
/**
3755
* Default pino options
3856
* - Do not add `never`
@@ -66,3 +84,11 @@ export const defaultLoggerOptions: Record<string, LoggerOptions> = {
6684
},
6785
},
6886
};
87+
88+
export const sessionDataTypeBox = t.Object({
89+
sessionId: t.String(),
90+
sessionExpiresAt: t.Number(),
91+
idToken: t.String(),
92+
accessToken: t.String(),
93+
refreshToken: t.Optional(t.String()),
94+
});

0 commit comments

Comments
 (0)