nuxt-auth-utils 0.0.23 → 0.0.25

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/README.md CHANGED
@@ -146,6 +146,7 @@ It can also be set using environment variables:
146
146
  - AWS Cognito
147
147
  - Battle.net
148
148
  - Discord
149
+ - Facebook
149
150
  - GitHub
150
151
  - Google
151
152
  - Keycloak
package/dist/module.json CHANGED
@@ -1,5 +1,9 @@
1
1
  {
2
2
  "name": "auth-utils",
3
3
  "configKey": "auth",
4
- "version": "0.0.23"
4
+ "version": "0.0.25",
5
+ "builder": {
6
+ "@nuxt/module-builder": "0.6.0",
7
+ "unbuild": "2.0.0"
8
+ }
5
9
  }
package/dist/module.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { readFile, writeFile } from 'node:fs/promises';
2
- import { defineNuxtModule, createResolver, addImportsDir, addPlugin, addServerHandler } from '@nuxt/kit';
2
+ import { defineNuxtModule, createResolver, addImportsDir, addPlugin, addServerPlugin, addServerHandler } from '@nuxt/kit';
3
3
  import { join } from 'pathe';
4
4
  import { defu } from 'defu';
5
5
  import { randomUUID } from 'uncrypto';
@@ -37,6 +37,7 @@ const module = defineNuxtModule({
37
37
  ]
38
38
  });
39
39
  }
40
+ addServerPlugin(resolver.resolve("./runtime/server/plugins/oauth"));
40
41
  addServerHandler({
41
42
  handler: resolver.resolve("./runtime/server/api/session.delete"),
42
43
  route: "/api/_auth/session",
@@ -119,6 +120,10 @@ const module = defineNuxtModule({
119
120
  region: "",
120
121
  userPoolId: ""
121
122
  });
123
+ runtimeConfig.oauth.facebook = defu(runtimeConfig.oauth.facebook, {
124
+ clientId: "",
125
+ clientSecret: ""
126
+ });
122
127
  }
123
128
  });
124
129
 
@@ -1,2 +1,2 @@
1
- declare const _default: any;
1
+ declare const _default: import("#app").Plugin<Record<string, unknown>> & import("#app").ObjectPlugin<Record<string, unknown>>;
2
2
  export default _default;
@@ -1,2 +1,2 @@
1
- declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<UserSessionRequired>>;
1
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<import("../../types").UserSessionRequired>>;
2
2
  export default _default;
@@ -52,4 +52,4 @@ export interface OAuthAuth0Config {
52
52
  */
53
53
  authorizationParams?: Record<string, string>;
54
54
  }
55
- export declare function auth0EventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthAuth0Config>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
55
+ export declare function auth0EventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthAuth0Config>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<void>>;
@@ -40,4 +40,4 @@ export interface OAuthBattledotnetConfig {
40
40
  */
41
41
  authorizationParams?: Record<string, string>;
42
42
  }
43
- export declare function battledotnetEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthBattledotnetConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
43
+ export declare function battledotnetEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthBattledotnetConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<void>>;
@@ -31,4 +31,4 @@ export interface OAuthCognitoConfig {
31
31
  */
32
32
  authorizationParams?: Record<string, string>;
33
33
  }
34
- export declare function cognitoEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthCognitoConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
34
+ export declare function cognitoEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthCognitoConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<void>>;
@@ -45,4 +45,4 @@ export interface OAuthDiscordConfig {
45
45
  */
46
46
  authorizationParams?: Record<string, string>;
47
47
  }
48
- export declare function discordEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthDiscordConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
48
+ export declare function discordEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthDiscordConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<void>>;
@@ -0,0 +1,43 @@
1
+ import type { OAuthConfig } from '#auth-utils';
2
+ export interface OAuthFacebookConfig {
3
+ /**
4
+ * Facebook OAuth Client ID
5
+ * @default process.env.NUXT_OAUTH_FACEBOOK_CLIENT_ID
6
+ */
7
+ clientId?: string;
8
+ /**
9
+ * Facebook OAuth Client Secret
10
+ * @default process.env.NUXT_OAUTH_FACEBOOK_CLIENT_SECRET
11
+ */
12
+ clientSecret?: string;
13
+ /**
14
+ * Facebook OAuth Scope
15
+ * @default []
16
+ * @see https://developers.facebook.com/docs/permissions
17
+ * @example [ 'email' ],
18
+ */
19
+ scope?: string[];
20
+ /**
21
+ * Facebook OAuth User Fields
22
+ * @default [ 'id', 'name'],
23
+ * @see https://developers.facebook.com/docs/graph-api/guides/field-expansion
24
+ * @example [ 'id', 'name', 'email' ],
25
+ */
26
+ fields?: string[];
27
+ /**
28
+ * Facebook OAuth Authorization URL
29
+ * @default 'https://www.facebook.com/v19.0/dialog/oauth'
30
+ */
31
+ authorizationURL?: string;
32
+ /**
33
+ * Facebook OAuth Token URL
34
+ * @default 'https://graph.facebook.com/v19.0/oauth/access_token'
35
+ */
36
+ tokenURL?: string;
37
+ /**
38
+ * Extra authorization parameters to provide to the authorization URL
39
+ * @see https://developers.facebook.com/docs/facebook-login/guides/advanced/manual-flow/
40
+ */
41
+ authorizationParams?: Record<string, string>;
42
+ }
43
+ export declare function facebookEventHandler({ config, onSuccess, onError, }: OAuthConfig<OAuthFacebookConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<void>>;
@@ -0,0 +1,88 @@
1
+ import {
2
+ eventHandler,
3
+ createError,
4
+ getQuery,
5
+ getRequestURL,
6
+ sendRedirect
7
+ } from "h3";
8
+ import { ofetch } from "ofetch";
9
+ import { withQuery } from "ufo";
10
+ import { defu } from "defu";
11
+ import { useRuntimeConfig } from "#imports";
12
+ export function facebookEventHandler({
13
+ config,
14
+ onSuccess,
15
+ onError
16
+ }) {
17
+ return eventHandler(async (event) => {
18
+ config = defu(config, useRuntimeConfig(event).oauth?.facebook, {
19
+ authorizationURL: "https://www.facebook.com/v19.0/dialog/oauth",
20
+ tokenURL: "https://graph.facebook.com/v19.0/oauth/access_token",
21
+ authorizationParams: {}
22
+ });
23
+ const query = getQuery(event);
24
+ if (query.error) {
25
+ const error = createError({
26
+ statusCode: 401,
27
+ message: `Facebook login failed: ${query.error || "Unknown error"}`,
28
+ data: query
29
+ });
30
+ if (!onError)
31
+ throw error;
32
+ return onError(event, error);
33
+ }
34
+ if (!config.clientId) {
35
+ const error = createError({
36
+ statusCode: 500,
37
+ message: "Missing NUXT_OAUTH_FACEBOOK_CLIENT_ID or NUXT_OAUTH_FACEBOOK_CLIENT_SECRET env variables."
38
+ });
39
+ if (!onError)
40
+ throw error;
41
+ return onError(event, error);
42
+ }
43
+ const redirectUrl = getRequestURL(event).href;
44
+ if (!query.code) {
45
+ config.scope = config.scope || [];
46
+ return sendRedirect(
47
+ event,
48
+ withQuery(config.authorizationURL, {
49
+ client_id: config.clientId,
50
+ redirect_uri: redirectUrl,
51
+ scope: config.scope.join(" ")
52
+ })
53
+ );
54
+ }
55
+ const tokens = await $fetch(config.tokenURL, {
56
+ method: "POST",
57
+ body: {
58
+ client_id: config.clientId,
59
+ client_secret: config.clientSecret,
60
+ redirect_uri: redirectUrl,
61
+ code: query.code
62
+ }
63
+ });
64
+ if (tokens.error) {
65
+ const error = createError({
66
+ statusCode: 401,
67
+ message: `Facebook login failed: ${tokens.error || "Unknown error"}`,
68
+ data: tokens
69
+ });
70
+ if (!onError)
71
+ throw error;
72
+ return onError(event, error);
73
+ }
74
+ const accessToken = tokens.access_token;
75
+ config.fields = config.fields || ["id", "name"];
76
+ const fields = config.fields.join(",");
77
+ const user = await ofetch(
78
+ `https://graph.facebook.com/v19.0/me?fields=${fields}&access_token=${accessToken}`
79
+ );
80
+ if (!user) {
81
+ throw new Error("Facebook login failed: no user found");
82
+ }
83
+ return onSuccess(event, {
84
+ user,
85
+ tokens
86
+ });
87
+ });
88
+ }
@@ -39,4 +39,4 @@ export interface OAuthGitHubConfig {
39
39
  */
40
40
  authorizationParams?: Record<string, string>;
41
41
  }
42
- export declare function githubEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthGitHubConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
42
+ export declare function githubEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthGitHubConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<void>>;
@@ -39,4 +39,4 @@ export interface OAuthGoogleConfig {
39
39
  */
40
40
  authorizationParams?: Record<string, string>;
41
41
  }
42
- export declare function googleEventHandler({ config, onSuccess, onError, }: OAuthConfig<OAuthGoogleConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
42
+ export declare function googleEventHandler({ config, onSuccess, onError, }: OAuthConfig<OAuthGoogleConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<void>>;
@@ -33,4 +33,4 @@ export interface OAuthKeycloakConfig {
33
33
  */
34
34
  authorizationParams?: Record<string, string>;
35
35
  }
36
- export declare function keycloakEventHandler({ config, onSuccess, onError, }: OAuthConfig<OAuthKeycloakConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
36
+ export declare function keycloakEventHandler({ config, onSuccess, onError, }: OAuthConfig<OAuthKeycloakConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<void>>;
@@ -39,4 +39,4 @@ export interface OAuthSpotifyConfig {
39
39
  */
40
40
  authorizationParams?: Record<string, string>;
41
41
  }
42
- export declare function spotifyEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthSpotifyConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
42
+ export declare function spotifyEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthSpotifyConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<void>>;
@@ -39,4 +39,4 @@ export interface OAuthTwitchConfig {
39
39
  */
40
40
  authorizationParams?: Record<string, string>;
41
41
  }
42
- export declare function twitchEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthTwitchConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
42
+ export declare function twitchEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthTwitchConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<void>>;
@@ -0,0 +1,2 @@
1
+ declare const _default: import("nitropack").NitroAppPlugin;
2
+ export default _default;
@@ -0,0 +1,16 @@
1
+ import { defineNitroPlugin } from "nitropack/runtime";
2
+ export default defineNitroPlugin((nitroApp) => {
3
+ if (process.env.NUXT_OAUTH_FACEBOOK_CLIENT_ID && process.env.NUXT_OAUTH_FACEBOOK_CLIENT_SECRET) {
4
+ nitroApp.hooks.hook("render:html", (html) => {
5
+ html.head.unshift(`
6
+ <script>
7
+ if (window.location.hash === "#_=_"){
8
+ history.replaceState
9
+ ? history.replaceState(null, null, window.location.href.split("#")[0])
10
+ : window.location.hash = "";
11
+ }
12
+ <\/script>
13
+ `);
14
+ });
15
+ }
16
+ });
@@ -9,6 +9,7 @@ import { battledotnetEventHandler } from '../lib/oauth/battledotnet';
9
9
  import { keycloakEventHandler } from '../lib/oauth/keycloak';
10
10
  import { linkedinEventHandler } from '../lib/oauth/linkedin';
11
11
  import { cognitoEventHandler } from '../lib/oauth/cognito';
12
+ import { facebookEventHandler } from '../lib/oauth/facebook';
12
13
  export declare const oauth: {
13
14
  githubEventHandler: typeof githubEventHandler;
14
15
  spotifyEventHandler: typeof spotifyEventHandler;
@@ -21,4 +22,5 @@ export declare const oauth: {
21
22
  keycloakEventHandler: typeof keycloakEventHandler;
22
23
  linkedinEventHandler: typeof linkedinEventHandler;
23
24
  cognitoEventHandler: typeof cognitoEventHandler;
25
+ facebookEventHandler: typeof facebookEventHandler;
24
26
  };
@@ -9,6 +9,7 @@ import { battledotnetEventHandler } from "../lib/oauth/battledotnet.mjs";
9
9
  import { keycloakEventHandler } from "../lib/oauth/keycloak.mjs";
10
10
  import { linkedinEventHandler } from "../lib/oauth/linkedin.mjs";
11
11
  import { cognitoEventHandler } from "../lib/oauth/cognito.mjs";
12
+ import { facebookEventHandler } from "../lib/oauth/facebook.mjs";
12
13
  export const oauth = {
13
14
  githubEventHandler,
14
15
  spotifyEventHandler,
@@ -20,5 +21,6 @@ export const oauth = {
20
21
  battledotnetEventHandler,
21
22
  keycloakEventHandler,
22
23
  linkedinEventHandler,
23
- cognitoEventHandler
24
+ cognitoEventHandler,
25
+ facebookEventHandler
24
26
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-auth-utils",
3
- "version": "0.0.23",
3
+ "version": "0.0.25",
4
4
  "description": "Minimalist Auth module for Nuxt with SSR",
5
5
  "repository": "Atinux/nuxt-auth-utils",
6
6
  "license": "MIT",
@@ -41,8 +41,8 @@
41
41
  "devDependencies": {
42
42
  "@iconify-json/simple-icons": "^1.1.99",
43
43
  "@nuxt/devtools": "latest",
44
- "@nuxt/eslint-config": "^0.3.7",
45
- "@nuxt/module-builder": "^0.5.5",
44
+ "@nuxt/eslint-config": "^0.3.8",
45
+ "@nuxt/module-builder": "^0.6.0",
46
46
  "@nuxt/schema": "^3.11.2",
47
47
  "@nuxt/test-utils": "^3.12.1",
48
48
  "@nuxt/ui": "^2.15.2",