@thecodeorigin/auth 0.0.2 → 0.0.3
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/module.json +1 -1
- package/dist/runtime/server/api/_auth/impersonate.post.js +1 -0
- package/dist/runtime/server/api/_auth/stop-impersonating.post.js +1 -2
- package/dist/runtime/server/routes/callback.get.js +1 -0
- package/dist/runtime/server/routes/sign-out.get.js +22 -10
- package/dist/runtime/server/utils/session.d.ts +1 -0
- package/dist/runtime/server/utils/session.js +1 -2
- package/package.json +28 -27
package/dist/module.json
CHANGED
|
@@ -26,6 +26,7 @@ export default defineEventHandler(async (event) => {
|
|
|
26
26
|
entitlement: res.claims.entitlement,
|
|
27
27
|
accessToken: res.accessToken,
|
|
28
28
|
refreshToken: null,
|
|
29
|
+
idToken: null,
|
|
29
30
|
accessExpiresAt: res.expiresAt,
|
|
30
31
|
isImpersonation: true,
|
|
31
32
|
impersonator: { sub: s.rec.user.sub, email: s.rec.user.email, name: s.rec.user.name, picture: s.rec.user.picture },
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { createError, defineEventHandler } from "h3";
|
|
2
|
-
import { useRuntimeConfig } from "nitropack/runtime";
|
|
3
|
-
import { useStorage } from "nitropack/runtime";
|
|
2
|
+
import { useRuntimeConfig, useStorage } from "nitropack/runtime";
|
|
4
3
|
import { idpFetch } from "../../utils/idp.js";
|
|
5
4
|
import { readSessionRecord, readSessionRecordById, toPublicSession, writeSessionRecord } from "../../utils/session.js";
|
|
6
5
|
export default defineEventHandler(async (event) => {
|
|
@@ -52,6 +52,7 @@ export default defineEventHandler(async (event) => {
|
|
|
52
52
|
entitlement: u.entitlement,
|
|
53
53
|
accessToken: tokens.access_token,
|
|
54
54
|
refreshToken: tokens.refresh_token ?? null,
|
|
55
|
+
idToken: tokens.id_token ?? null,
|
|
55
56
|
accessExpiresAt: Date.now() + (tokens.expires_in ?? 3600) * 1e3,
|
|
56
57
|
isImpersonation: false,
|
|
57
58
|
impersonator: null,
|
|
@@ -1,19 +1,31 @@
|
|
|
1
|
-
import { defineEventHandler, sendRedirect } from "h3";
|
|
1
|
+
import { defineEventHandler, getRequestHost, getRequestProtocol, sendRedirect } from "h3";
|
|
2
2
|
import { useRuntimeConfig } from "nitropack/runtime";
|
|
3
3
|
import { $fetch } from "ofetch";
|
|
4
|
+
import { withQuery } from "ufo";
|
|
4
5
|
import { destroySession } from "../utils/session.js";
|
|
5
6
|
export default defineEventHandler(async (event) => {
|
|
6
|
-
const { public: { auth: publicRuntimeConfig } } = useRuntimeConfig();
|
|
7
|
+
const { auth: runtimeConfig, public: { auth: publicRuntimeConfig } } = useRuntimeConfig();
|
|
7
8
|
const rec = await destroySession(event);
|
|
8
9
|
if (rec?.accessToken) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
await $fetch(`https://${publicRuntimeConfig.domain}/api/auth/oauth2/revoke`, {
|
|
11
|
+
method: "POST",
|
|
12
|
+
body: new URLSearchParams({
|
|
13
|
+
token: rec.refreshToken ?? rec.accessToken,
|
|
14
|
+
token_type_hint: rec.refreshToken ? "refresh_token" : "access_token",
|
|
15
|
+
client_id: publicRuntimeConfig.clientId,
|
|
16
|
+
client_secret: runtimeConfig.clientSecret
|
|
17
|
+
}).toString(),
|
|
18
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" }
|
|
19
|
+
}).catch(() => {
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
const postLogoutRedirectUri = `${getRequestProtocol(event)}://${getRequestHost(event)}${publicRuntimeConfig.routes.home}`;
|
|
23
|
+
if (rec?.idToken) {
|
|
24
|
+
return sendRedirect(event, withQuery(`https://${publicRuntimeConfig.domain}/api/auth/oauth2/end-session`, {
|
|
25
|
+
id_token_hint: rec.idToken,
|
|
26
|
+
client_id: publicRuntimeConfig.clientId,
|
|
27
|
+
post_logout_redirect_uri: postLogoutRedirectUri
|
|
28
|
+
}));
|
|
17
29
|
}
|
|
18
30
|
return sendRedirect(event, publicRuntimeConfig.routes.home);
|
|
19
31
|
});
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { deleteCookie, getCookie, setCookie } from "h3";
|
|
2
|
-
import { useRuntimeConfig } from "nitropack/runtime";
|
|
3
|
-
import { useStorage } from "nitropack/runtime";
|
|
2
|
+
import { useRuntimeConfig, useStorage } from "nitropack/runtime";
|
|
4
3
|
function key(id) {
|
|
5
4
|
return `session:${id}`;
|
|
6
5
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thecodeorigin/auth",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.3",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "THECODEORIGIN Authentication Portal client module",
|
|
7
7
|
"repository": "https://github.com/thecodeorigin/auth",
|
|
@@ -39,32 +39,8 @@
|
|
|
39
39
|
"workspaces": [
|
|
40
40
|
"playground"
|
|
41
41
|
],
|
|
42
|
-
"dependencies": {
|
|
43
|
-
"@casl/ability": "^6.8.1",
|
|
44
|
-
"@casl/vue": "^2.2.6",
|
|
45
|
-
"@nuxt/kit": "^4.4.8",
|
|
46
|
-
"defu": "^6.1.4",
|
|
47
|
-
"h3": "^1.14.0",
|
|
48
|
-
"ofetch": "^1.4.1",
|
|
49
|
-
"ufo": "^1.5.4",
|
|
50
|
-
"zod": "^4.3.6"
|
|
51
|
-
},
|
|
52
|
-
"devDependencies": {
|
|
53
|
-
"@nuxt/devtools": "^3.2.4",
|
|
54
|
-
"@nuxt/eslint-config": "^1.15.2",
|
|
55
|
-
"@nuxt/module-builder": "^1.0.2",
|
|
56
|
-
"@nuxt/schema": "^4.4.8",
|
|
57
|
-
"@nuxt/test-utils": "^4.0.3",
|
|
58
|
-
"@types/node": "latest",
|
|
59
|
-
"changelogen": "^0.6.2",
|
|
60
|
-
"eslint": "^10.4.1",
|
|
61
|
-
"nuxt": "^4.4.8",
|
|
62
|
-
"typescript": "~6.0.3",
|
|
63
|
-
"unbuild": "^3.6.1",
|
|
64
|
-
"vitest": "^4.1.8",
|
|
65
|
-
"vue-tsc": "^3.3.3"
|
|
66
|
-
},
|
|
67
42
|
"scripts": {
|
|
43
|
+
"prepack": "nuxt-module-build build",
|
|
68
44
|
"dev": "npm run dev:prepare && nuxt dev playground",
|
|
69
45
|
"dev:build": "nuxt build playground",
|
|
70
46
|
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxt prepare playground",
|
|
@@ -73,5 +49,30 @@
|
|
|
73
49
|
"test": "vitest run",
|
|
74
50
|
"test:watch": "vitest watch",
|
|
75
51
|
"test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit"
|
|
52
|
+
},
|
|
53
|
+
"dependencies": {
|
|
54
|
+
"@casl/ability": "catalog:",
|
|
55
|
+
"@casl/vue": "catalog:",
|
|
56
|
+
"@nuxt/kit": "catalog:",
|
|
57
|
+
"defu": "catalog:",
|
|
58
|
+
"h3": "catalog:",
|
|
59
|
+
"ofetch": "catalog:",
|
|
60
|
+
"ufo": "catalog:",
|
|
61
|
+
"zod": "catalog:"
|
|
62
|
+
},
|
|
63
|
+
"devDependencies": {
|
|
64
|
+
"@nuxt/devtools": "catalog:",
|
|
65
|
+
"@nuxt/eslint-config": "catalog:",
|
|
66
|
+
"@nuxt/module-builder": "catalog:",
|
|
67
|
+
"@nuxt/schema": "catalog:",
|
|
68
|
+
"@nuxt/test-utils": "catalog:",
|
|
69
|
+
"@types/node": "catalog:",
|
|
70
|
+
"changelogen": "catalog:",
|
|
71
|
+
"eslint": "catalog:",
|
|
72
|
+
"nuxt": "catalog:",
|
|
73
|
+
"typescript": "catalog:",
|
|
74
|
+
"unbuild": "catalog:",
|
|
75
|
+
"vitest": "catalog:",
|
|
76
|
+
"vue-tsc": "catalog:"
|
|
76
77
|
}
|
|
77
|
-
}
|
|
78
|
+
}
|