nuxt-auth-utils 0.5.12 → 0.5.14

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": "auth-utils",
3
3
  "configKey": "auth",
4
- "version": "0.5.12",
4
+ "version": "0.5.14",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "0.8.4",
7
7
  "unbuild": "2.0.0"
package/dist/module.mjs CHANGED
@@ -3,26 +3,7 @@ import { defineNuxtModule, createResolver, addComponentsDir, addImports, addPlug
3
3
  import { join } from 'pathe';
4
4
  import { defu } from 'defu';
5
5
  import { randomUUID } from 'uncrypto';
6
-
7
- const atprotoProviders = ["bluesky"];
8
- const atprotoProviderDefaultClientMetadata = {
9
- clientMetadataFilename: "",
10
- clientName: "",
11
- clientUri: "",
12
- logoUri: "",
13
- policyUri: "",
14
- tosUri: "",
15
- scope: ["atproto"],
16
- grantTypes: ["authorization_code"],
17
- responseTypes: ["code"],
18
- applicationType: "web",
19
- redirectUris: [],
20
- dpopBoundAccessTokens: true,
21
- tokenEndpointAuthMethod: "none"
22
- };
23
- function getClientMetadataFilename(provider, config) {
24
- return config?.clientMetadataFilename || provider + "/client-metadata.json";
25
- }
6
+ import { atprotoProviders, atprotoProviderDefaultClientMetadata, getClientMetadataFilename } from '../dist/runtime/utils/atproto.js';
26
7
 
27
8
  const module = defineNuxtModule({
28
9
  meta: {
@@ -203,7 +184,7 @@ const module = defineNuxtModule({
203
184
  }
204
185
  for (const provider of atprotoProviders) {
205
186
  addServerHandler({
206
- handler: resolver.resolve("./runtime/server/routes/atproto/client-metadata.json.get.ts"),
187
+ handler: resolver.resolve("./runtime/server/routes/atproto/client-metadata.json.get"),
207
188
  route: "/" + getClientMetadataFilename(provider, runtimeConfig.oauth[provider]),
208
189
  method: "get"
209
190
  });
@@ -1,5 +1,5 @@
1
1
  declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<{
2
- id: string;
2
+ id: any;
3
3
  user?: import("../../types").User;
4
4
  }>>;
5
5
  export default _default;
@@ -29,11 +29,9 @@ export declare class StateStore implements NodeSavedStateStore {
29
29
  del(): Promise<void>;
30
30
  }
31
31
  export declare class SessionStore implements NodeSavedSessionStore {
32
- private event;
33
- private readonly sessionKey;
34
- constructor(event: H3Event);
35
- get(): Promise<NodeSavedSession | undefined>;
32
+ private store;
33
+ get(key: string): Promise<NodeSavedSession | undefined>;
36
34
  set(key: string, val: NodeSavedSession): Promise<void>;
37
- del(): Promise<void>;
35
+ del(key: string): Promise<void>;
38
36
  }
39
37
  export {};
@@ -6,7 +6,7 @@ export function defineOAuthBlueskyEventHandler({ config, onSuccess, onError }) {
6
6
  return eventHandler(async (event) => {
7
7
  const clientMetadata = getAtprotoClientMetadata(event, "bluesky", config);
8
8
  const scopes = clientMetadata.scope?.split(" ") ?? [];
9
- const sessionStore = new SessionStore(event);
9
+ const sessionStore = new SessionStore();
10
10
  const stateStore = new StateStore(event);
11
11
  const client = new NodeOAuthClient({
12
12
  stateStore,
@@ -47,9 +47,9 @@ export function defineOAuthBlueskyEventHandler({ config, onSuccess, onError }) {
47
47
  }
48
48
  try {
49
49
  const { session } = await client.callback(new URLSearchParams(query));
50
- const sessionInfo = await sessionStore.get();
50
+ const sessionInfo = await sessionStore.get(session.did);
51
51
  const profile = scopes.includes("transition:generic") ? (await new Agent(session).getProfile({ actor: session.did })).data : null;
52
- sessionStore.del();
52
+ sessionStore.del(session.did);
53
53
  return onSuccess(event, {
54
54
  user: profile ?? { did: session.did },
55
55
  tokens: sessionInfo.tokenSet
@@ -69,33 +69,33 @@ export class StateStore {
69
69
  constructor(event) {
70
70
  this.event = event;
71
71
  }
72
- stateKey = "oauth:bluesky:stat";
72
+ stateKey = "oauth-bluesky-state";
73
73
  async get() {
74
74
  const result = getCookie(this.event, this.stateKey);
75
75
  if (!result) return;
76
76
  return JSON.parse(atob(result));
77
77
  }
78
78
  async set(key, val) {
79
- setCookie(this.event, this.stateKey, btoa(JSON.stringify(val)));
79
+ setCookie(this.event, this.stateKey, btoa(JSON.stringify(val)), {
80
+ path: "/",
81
+ httpOnly: true,
82
+ secure: true,
83
+ sameSite: "lax"
84
+ });
80
85
  }
81
86
  async del() {
82
87
  deleteCookie(this.event, this.stateKey);
83
88
  }
84
89
  }
85
90
  export class SessionStore {
86
- constructor(event) {
87
- this.event = event;
88
- }
89
- sessionKey = "oauth:bluesky:session";
90
- async get() {
91
- const result = getCookie(this.event, this.sessionKey);
92
- if (!result) return;
93
- return JSON.parse(atob(result));
91
+ store = {};
92
+ async get(key) {
93
+ return this.store[key];
94
94
  }
95
95
  async set(key, val) {
96
- setCookie(this.event, this.sessionKey, btoa(JSON.stringify(val)));
96
+ this.store[key] = val;
97
97
  }
98
- async del() {
99
- deleteCookie(this.event, this.sessionKey);
98
+ async del(key) {
99
+ delete this.store[key];
100
100
  }
101
101
  }
@@ -1,6 +1,6 @@
1
1
  import { defineEventHandler, createError } from "h3";
2
2
  import { getAtprotoClientMetadata } from "../../utils/atproto.js";
3
- import { atprotoProviders, getClientMetadataFilename } from "../../../../utils/atproto";
3
+ import { atprotoProviders, getClientMetadataFilename } from "../../../utils/atproto.js";
4
4
  import { useRuntimeConfig } from "#imports";
5
5
  export default defineEventHandler((event) => {
6
6
  const path = event.path.slice(1);
@@ -1,5 +1,5 @@
1
1
  import type { H3Event } from 'h3';
2
2
  import type { OAuthClientMetadataInput } from '@atproto/oauth-client-node';
3
- import type { OAuthBlueskyConfig } from '../lib/oauth/bluesky.js';
3
+ import type { OAuthBlueskyConfig } from '../lib/atproto/bluesky.js';
4
4
  import type { ATProtoProvider, OAuthConfig } from '#auth-utils';
5
5
  export declare function getAtprotoClientMetadata(event: H3Event, provider: ATProtoProvider, config?: OAuthConfig<OAuthBlueskyConfig>['config']): OAuthClientMetadataInput;
@@ -1,5 +1,5 @@
1
1
  import { getOAuthRedirectURL } from "../lib/utils.js";
2
- import { getClientMetadataFilename } from "../../../utils/atproto";
2
+ import { getClientMetadataFilename } from "../../utils/atproto.js";
3
3
  import { getRequestURL, useRuntimeConfig } from "#imports";
4
4
  export function getAtprotoClientMetadata(event, provider, config) {
5
5
  const providerRuntimeConfig = useRuntimeConfig(event).oauth[provider];
@@ -21,7 +21,7 @@ export declare const sessionHooks: import("hookable").Hookable<SessionHooks, imp
21
21
  * @returns The user session
22
22
  */
23
23
  export declare function getUserSession(event: UseSessionEvent): Promise<{
24
- id: string;
24
+ id: any;
25
25
  user?: import("#auth-utils").User;
26
26
  secure?: import("#auth-utils").SecureSessionData;
27
27
  }>;
@@ -7,7 +7,7 @@ export interface UserSession {
7
7
  /**
8
8
  * Session ID
9
9
  */
10
- id: string;
10
+ id?: string;
11
11
  /**
12
12
  * User session data, available on client and server
13
13
  */
@@ -22,6 +22,7 @@ export interface UserSession {
22
22
  [key: string]: unknown;
23
23
  }
24
24
  export interface UserSessionRequired extends UserSession {
25
+ id: string;
25
26
  user: User;
26
27
  }
27
28
  export interface UserSessionComposable {
@@ -0,0 +1,5 @@
1
+ import type { OAuthProvider } from '../types/index.js';
2
+ import type { AtprotoProviderClientMetadata } from '../types/atproto.js';
3
+ export declare const atprotoProviders: "bluesky"[];
4
+ export declare const atprotoProviderDefaultClientMetadata: AtprotoProviderClientMetadata;
5
+ export declare function getClientMetadataFilename(provider: OAuthProvider, config?: AtprotoProviderClientMetadata): string;
@@ -0,0 +1,19 @@
1
+ export const atprotoProviders = ["bluesky"];
2
+ export const atprotoProviderDefaultClientMetadata = {
3
+ clientMetadataFilename: "",
4
+ clientName: "",
5
+ clientUri: "",
6
+ logoUri: "",
7
+ policyUri: "",
8
+ tosUri: "",
9
+ scope: ["atproto"],
10
+ grantTypes: ["authorization_code"],
11
+ responseTypes: ["code"],
12
+ applicationType: "web",
13
+ redirectUris: [],
14
+ dpopBoundAccessTokens: true,
15
+ tokenEndpointAuthMethod: "none"
16
+ };
17
+ export function getClientMetadataFilename(provider, config) {
18
+ return config?.clientMetadataFilename || provider + "/client-metadata.json";
19
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-auth-utils",
3
- "version": "0.5.12",
3
+ "version": "0.5.14",
4
4
  "description": "Add Authentication to Nuxt applications with secured & sealed cookies sessions.",
5
5
  "repository": {
6
6
  "type": "git",