@thecodeorigin/auth 0.0.5 → 0.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@thecodeorigin/auth",
3
3
  "configKey": "auth",
4
- "version": "0.0.5",
4
+ "version": "0.0.6",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
@@ -1,4 +1,5 @@
1
1
  import type { ImpersonationCandidate, RpOrganization } from '../../../contract/index.js';
2
+ export type SignInPrompt = 'login' | 'select_account' | 'consent' | 'none';
2
3
  export declare function useAuth(): {
3
4
  session: import("vue").Ref<{
4
5
  user: {
@@ -100,7 +101,9 @@ export declare function useAuth(): {
100
101
  }>;
101
102
  impersonate: (userId: string) => Promise<void>;
102
103
  stopImpersonating: () => Promise<void>;
103
- signIn: (redirect?: string) => string | false | void | import("vue-router").RouteLocationAsRelativeGeneric | import("vue-router").RouteLocationAsPathGeneric | Promise<false | void | import("vue-router").NavigationFailure>;
104
+ signIn: (redirect?: string, options?: {
105
+ prompt?: SignInPrompt;
106
+ }) => string | false | void | import("vue-router").RouteLocationAsRelativeGeneric | import("vue-router").RouteLocationAsPathGeneric | Promise<false | void | import("vue-router").NavigationFailure>;
104
107
  signOut: () => Promise<void>;
105
108
  refresh: () => Promise<void>;
106
109
  };
@@ -32,11 +32,14 @@ export function useAuth() {
32
32
  async function stopImpersonating() {
33
33
  session.value = await $fetch("/api/_auth/stop-impersonating", { method: "POST" });
34
34
  }
35
- function signIn(redirect) {
36
- return navigateTo(
37
- redirect ? `${routes.signIn}?redirect=${encodeURIComponent(redirect)}` : routes.signIn,
38
- { external: true }
39
- );
35
+ function signIn(redirect, options) {
36
+ const params = new URLSearchParams();
37
+ if (redirect)
38
+ params.set("redirect", redirect);
39
+ if (options?.prompt)
40
+ params.set("prompt", options.prompt);
41
+ const qs = params.toString();
42
+ return navigateTo(qs ? `${routes.signIn}?${qs}` : routes.signIn, { external: true });
40
43
  }
41
44
  async function signOut() {
42
45
  await $fetch("/api/_auth/sign-out", { method: "POST" }).catch(() => {
@@ -2,13 +2,16 @@ import { createError, defineEventHandler, getQuery, sendRedirect, setCookie } fr
2
2
  import { useRuntimeConfig } from "nitropack/runtime";
3
3
  import { withQuery } from "ufo";
4
4
  import { callbackRedirectUri, pkceChallenge, randomString, safePath } from "../utils/oidc.js";
5
+ const ALLOWED_PROMPTS = /* @__PURE__ */ new Set(["login", "select_account", "consent", "none"]);
5
6
  export default defineEventHandler(async (event) => {
6
7
  const { auth: runtimeConfig, public: { auth: publicRuntimeConfig } } = useRuntimeConfig();
7
8
  if (!publicRuntimeConfig.domain || !publicRuntimeConfig.clientId || !runtimeConfig.clientSecret)
8
9
  throw createError({ statusCode: 503, statusMessage: "Auth not configured" });
10
+ const query = getQuery(event);
9
11
  const state = randomString(32);
10
12
  const verifier = randomString(64);
11
- const redirectTo = safePath(getQuery(event).redirect, publicRuntimeConfig.routes.home);
13
+ const redirectTo = safePath(query.redirect, publicRuntimeConfig.routes.home);
14
+ const prompt = typeof query.prompt === "string" && ALLOWED_PROMPTS.has(query.prompt) ? query.prompt : void 0;
12
15
  const opts = { httpOnly: true, secure: !import.meta.dev, sameSite: "lax", maxAge: 600, path: publicRuntimeConfig.routes.callback };
13
16
  setCookie(event, "tco_state", state, opts);
14
17
  setCookie(event, "tco_verifier", verifier, opts);
@@ -20,6 +23,7 @@ export default defineEventHandler(async (event) => {
20
23
  scope: publicRuntimeConfig.scopes.join(" "),
21
24
  state,
22
25
  code_challenge: await pkceChallenge(verifier),
23
- code_challenge_method: "S256"
26
+ code_challenge_method: "S256",
27
+ ...prompt ? { prompt } : {}
24
28
  }));
25
29
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@thecodeorigin/auth",
3
3
  "type": "module",
4
- "version": "0.0.5",
4
+ "version": "0.0.6",
5
5
  "private": false,
6
6
  "description": "THECODEORIGIN Authentication Portal client module",
7
7
  "repository": "https://github.com/thecodeorigin/auth",