@nekm/svelte-core 1.7.11 → 1.7.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/protect/helper.d.ts +4 -3
- package/dist/protect/helper.js +8 -10
- package/dist/protect/protect.js +1 -1
- package/dist/protect/routes/login.d.ts +1 -1
- package/dist/protect/routes/logout.d.ts +1 -1
- package/dist/protect/routes/redirect-login.d.ts +1 -1
- package/dist/protect/routes/redirect-login.js +4 -1
- package/dist/protect/routes/redirect-logout.d.ts +1 -1
- package/dist/protect/routes/routes.d.ts +1 -1
- package/dist/protect/routes/routes.js +4 -4
- package/package.json +1 -1
package/dist/protect/helper.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { ProtectConfig } from "./contracts.
|
|
1
|
+
import type { ProtectConfig } from "./contracts.js";
|
|
2
|
+
import { type JWTVerifyGetKey } from "jose";
|
|
2
3
|
export declare function getRedirectUri(origin: string, path: string): string;
|
|
3
|
-
export declare function jwtVerifyIdToken(config: ProtectConfig, jwks:
|
|
4
|
-
export declare function jwtVerifyAccessToken(config: ProtectConfig, jwks:
|
|
4
|
+
export declare function jwtVerifyIdToken(config: ProtectConfig, jwks: JWTVerifyGetKey, idToken: string): Promise<import("jose").JWTPayload>;
|
|
5
|
+
export declare function jwtVerifyAccessToken(config: ProtectConfig, jwks: JWTVerifyGetKey, accessToken: string): Promise<import("jose").JWTPayload>;
|
package/dist/protect/helper.js
CHANGED
|
@@ -3,18 +3,16 @@ import { jwtVerify } from "jose";
|
|
|
3
3
|
export function getRedirectUri(origin, path) {
|
|
4
4
|
return `${strTrimEnd(origin, "/")}/${path}`;
|
|
5
5
|
}
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
// @ts-expect-error It's OK.
|
|
9
|
-
jwks, {
|
|
6
|
+
export function jwtVerifyIdToken(config, jwks, idToken) {
|
|
7
|
+
return jwtVerifyToken(jwks, {
|
|
10
8
|
issuer: config.oauth.issuer,
|
|
11
9
|
audience: config.oauth.clientId,
|
|
12
|
-
});
|
|
13
|
-
|
|
10
|
+
}, idToken);
|
|
11
|
+
}
|
|
12
|
+
export function jwtVerifyAccessToken(config, jwks, accessToken) {
|
|
13
|
+
return jwtVerifyToken(jwks, { issuer: config.oauth.issuer }, accessToken);
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
const { payload } = await jwtVerify(
|
|
17
|
-
// @ts-expect-error It's OK.
|
|
18
|
-
jwks, { issuer: config.oauth.issuer });
|
|
15
|
+
async function jwtVerifyToken(jwks, options, token) {
|
|
16
|
+
const { payload } = await jwtVerify(token, jwks, options);
|
|
19
17
|
return payload;
|
|
20
18
|
}
|
package/dist/protect/protect.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { error, redirect } from "@sveltejs/kit";
|
|
2
2
|
import { ROUTE_PATH_LOGIN } from "./routes/login.js";
|
|
3
3
|
import { ROUTE_PATH_LOGOUT } from "./routes/logout.js";
|
|
4
|
-
import { routeCreate } from "./routes/routes.
|
|
4
|
+
import { routeCreate } from "./routes/routes.js";
|
|
5
5
|
export const PROTECT_LOGIN = "/" + ROUTE_PATH_LOGIN;
|
|
6
6
|
export const PROTECT_LOGOUT = "/" + ROUTE_PATH_LOGOUT;
|
|
7
7
|
export function protect(config) {
|
|
@@ -20,13 +20,16 @@ export const routeRedirectLoginFactory = (config) => {
|
|
|
20
20
|
redirect_uri: getRedirectUri(origin, ROUTE_PATH_REDIRECT_LOGIN),
|
|
21
21
|
}).toString(),
|
|
22
22
|
});
|
|
23
|
+
if (!response.ok) {
|
|
24
|
+
const error = await response.text();
|
|
25
|
+
throw new Error(`Token exchange failed: ${error}`);
|
|
26
|
+
}
|
|
23
27
|
return await response.json();
|
|
24
28
|
}
|
|
25
29
|
return {
|
|
26
30
|
path: ROUTE_PATH_REDIRECT_LOGIN,
|
|
27
31
|
async handle({ event }) {
|
|
28
32
|
const state = event.url.searchParams.get("state") ?? undefined;
|
|
29
|
-
;
|
|
30
33
|
const stateSession = await config.session.stateGet(event);
|
|
31
34
|
if (state !== stateSession) {
|
|
32
35
|
throw new Error("State do not match");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { routeLoginFactory } from "./login.
|
|
2
|
-
import { routeLogoutFactory } from "./logout.
|
|
3
|
-
import { routeRedirectLogoutFactory } from "./redirect-logout.
|
|
4
|
-
import { routeRedirectLoginFactory } from "./redirect-login.
|
|
1
|
+
import { routeLoginFactory } from "./login.js";
|
|
2
|
+
import { routeLogoutFactory } from "./logout.js";
|
|
3
|
+
import { routeRedirectLogoutFactory } from "./redirect-logout.js";
|
|
4
|
+
import { routeRedirectLoginFactory } from "./redirect-login.js";
|
|
5
5
|
const routeFactories = Object.freeze([
|
|
6
6
|
routeLoginFactory,
|
|
7
7
|
routeLogoutFactory,
|
package/package.json
CHANGED