nuxt-auth-utils 0.4.2 → 0.4.4
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 +1 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +5 -0
- package/dist/runtime/server/api/session.get.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/linear.d.ts +41 -0
- package/dist/runtime/server/lib/oauth/linear.js +80 -0
- package/dist/runtime/server/utils/session.d.ts +2 -2
- package/dist/runtime/server/utils/session.js +2 -2
- package/dist/runtime/types/oauth-config.d.ts +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -147,6 +147,11 @@ const module = defineNuxtModule({
|
|
|
147
147
|
realm: "",
|
|
148
148
|
redirectURL: ""
|
|
149
149
|
});
|
|
150
|
+
runtimeConfig.oauth.linear = defu(runtimeConfig.oauth.linear, {
|
|
151
|
+
clientId: "",
|
|
152
|
+
clientSecret: "",
|
|
153
|
+
redirectURL: ""
|
|
154
|
+
});
|
|
150
155
|
runtimeConfig.oauth.linkedin = defu(runtimeConfig.oauth.linkedin, {
|
|
151
156
|
clientId: "",
|
|
152
157
|
clientSecret: "",
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { OAuthConfig } from '#auth-utils';
|
|
2
|
+
export interface OAuthLinearConfig {
|
|
3
|
+
/**
|
|
4
|
+
* Linear OAuth Client ID
|
|
5
|
+
* @default process.env.NUXT_OAUTH_LINEAR_CLIENT_ID
|
|
6
|
+
*/
|
|
7
|
+
clientId?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Linear OAuth Client Secret
|
|
10
|
+
* @default process.env.NUXT_OAUTH_LINEAR_CLIENT_SECRET
|
|
11
|
+
*/
|
|
12
|
+
clientSecret?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Linear OAuth Scope
|
|
15
|
+
* @default ['read']
|
|
16
|
+
* @see https://developers.linear.app/docs/oauth/authentication#scopes
|
|
17
|
+
* @example ['read', 'write', 'issues:create', 'comments:create', 'timeSchedule:write', 'admin']
|
|
18
|
+
*/
|
|
19
|
+
scope?: string[];
|
|
20
|
+
/**
|
|
21
|
+
* Linear OAuth Authorization URL
|
|
22
|
+
* @default 'https://linear.app/oauth/authorize'
|
|
23
|
+
*/
|
|
24
|
+
authorizationURL?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Linear OAuth Token URL
|
|
27
|
+
* @default 'https://api.linear.app/oauth/token'
|
|
28
|
+
*/
|
|
29
|
+
tokenURL?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Extra authorization parameters to provide to the authorization URL
|
|
32
|
+
* @see https://developers.linear.app/docs/oauth/authentication#id-2.-redirect-user-access-requests-to-linear
|
|
33
|
+
*/
|
|
34
|
+
authorizationParams?: Record<string, string>;
|
|
35
|
+
/**
|
|
36
|
+
* Redirect URL to allow overriding for situations like prod failing to determine public hostname
|
|
37
|
+
* @default process.env.NUXT_OAUTH_LINEAR_REDIRECT_URL or current URL
|
|
38
|
+
*/
|
|
39
|
+
redirectURL?: string;
|
|
40
|
+
}
|
|
41
|
+
export declare function defineOAuthLinearEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthLinearConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<void>>;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { eventHandler, getQuery, sendRedirect } from "h3";
|
|
2
|
+
import { withQuery } from "ufo";
|
|
3
|
+
import { defu } from "defu";
|
|
4
|
+
import { handleMissingConfiguration, handleAccessTokenErrorResponse, getOAuthRedirectURL, requestAccessToken } from "../utils.js";
|
|
5
|
+
import { useRuntimeConfig, createError } from "#imports";
|
|
6
|
+
export function defineOAuthLinearEventHandler({ config, onSuccess, onError }) {
|
|
7
|
+
return eventHandler(async (event) => {
|
|
8
|
+
config = defu(config, useRuntimeConfig(event).oauth?.linear, {
|
|
9
|
+
authorizationURL: "https://linear.app/oauth/authorize",
|
|
10
|
+
tokenURL: "https://api.linear.app/oauth/token",
|
|
11
|
+
authorizationParams: {}
|
|
12
|
+
});
|
|
13
|
+
const query = getQuery(event);
|
|
14
|
+
if (query.error) {
|
|
15
|
+
const error = createError({
|
|
16
|
+
statusCode: 401,
|
|
17
|
+
message: `Linear login failed: ${query.error || "Unknown error"}`,
|
|
18
|
+
data: query
|
|
19
|
+
});
|
|
20
|
+
if (!onError) throw error;
|
|
21
|
+
return onError(event, error);
|
|
22
|
+
}
|
|
23
|
+
if (!config.clientId || !config.clientSecret) {
|
|
24
|
+
return handleMissingConfiguration(event, "linear", ["clientId", "clientSecret"], onError);
|
|
25
|
+
}
|
|
26
|
+
const redirectURL = config.redirectURL || getOAuthRedirectURL(event);
|
|
27
|
+
if (!query.code) {
|
|
28
|
+
config.scope = config.scope || ["read"];
|
|
29
|
+
return sendRedirect(
|
|
30
|
+
event,
|
|
31
|
+
withQuery(config.authorizationURL, {
|
|
32
|
+
response_type: "code",
|
|
33
|
+
client_id: config.clientId,
|
|
34
|
+
redirect_uri: redirectURL,
|
|
35
|
+
scope: config.scope.join(" "),
|
|
36
|
+
...config.authorizationParams
|
|
37
|
+
})
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
const tokens = await requestAccessToken(config.tokenURL, {
|
|
41
|
+
headers: {
|
|
42
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
43
|
+
},
|
|
44
|
+
body: {
|
|
45
|
+
grant_type: "authorization_code",
|
|
46
|
+
client_id: config.clientId,
|
|
47
|
+
client_secret: config.clientSecret,
|
|
48
|
+
redirect_uri: redirectURL,
|
|
49
|
+
code: query.code
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
if (tokens.error) {
|
|
53
|
+
return handleAccessTokenErrorResponse(event, "linear", tokens, onError);
|
|
54
|
+
}
|
|
55
|
+
const accessToken = tokens.access_token;
|
|
56
|
+
const user = await $fetch("https://api.linear.app/graphql", {
|
|
57
|
+
method: "POST",
|
|
58
|
+
headers: {
|
|
59
|
+
"Authorization": `Bearer ${accessToken}`,
|
|
60
|
+
"Content-Type": "application/json"
|
|
61
|
+
},
|
|
62
|
+
body: JSON.stringify({
|
|
63
|
+
query: "{ viewer { id name email } }"
|
|
64
|
+
})
|
|
65
|
+
});
|
|
66
|
+
if (!user.data || !user.data.viewer) {
|
|
67
|
+
const error = createError({
|
|
68
|
+
statusCode: 500,
|
|
69
|
+
message: "Could not get Linear user",
|
|
70
|
+
data: tokens
|
|
71
|
+
});
|
|
72
|
+
if (!onError) throw error;
|
|
73
|
+
return onError(event, error);
|
|
74
|
+
}
|
|
75
|
+
return onSuccess(event, {
|
|
76
|
+
tokens,
|
|
77
|
+
user: user.data.viewer
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
}
|
|
@@ -6,7 +6,7 @@ export interface SessionHooks {
|
|
|
6
6
|
* - Add extra properties to the session
|
|
7
7
|
* - Throw an error if the session could not be verified (with a database for example)
|
|
8
8
|
*/
|
|
9
|
-
fetch: (session:
|
|
9
|
+
fetch: (session: UserSession, event: H3Event) => void | Promise<void>;
|
|
10
10
|
/**
|
|
11
11
|
* Called before clearing the session
|
|
12
12
|
*/
|
|
@@ -37,7 +37,7 @@ export declare function replaceUserSession(event: H3Event, data: UserSession, co
|
|
|
37
37
|
* @param event The Request (h3) event
|
|
38
38
|
* @returns true if the session was cleared
|
|
39
39
|
*/
|
|
40
|
-
export declare function clearUserSession(event: H3Event): Promise<boolean>;
|
|
40
|
+
export declare function clearUserSession(event: H3Event, config?: Partial<SessionConfig>): Promise<boolean>;
|
|
41
41
|
/**
|
|
42
42
|
* Require a user session, throw a 401 error if the user is not logged in
|
|
43
43
|
* @param event
|
|
@@ -17,8 +17,8 @@ export async function replaceUserSession(event, data, config) {
|
|
|
17
17
|
await session.update(data);
|
|
18
18
|
return session.data;
|
|
19
19
|
}
|
|
20
|
-
export async function clearUserSession(event) {
|
|
21
|
-
const session = await _useSession(event);
|
|
20
|
+
export async function clearUserSession(event, config) {
|
|
21
|
+
const session = await _useSession(event, config);
|
|
22
22
|
await sessionHooks.callHookParallel("clear", session.data, event);
|
|
23
23
|
await session.clear();
|
|
24
24
|
return true;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { H3Event, H3Error } from 'h3';
|
|
2
|
-
export type OAuthProvider = 'auth0' | 'battledotnet' | 'cognito' | 'discord' | 'dropbox' | 'facebook' | 'github' | 'gitlab' | 'google' | 'instagram' | 'keycloak' | 'linkedin' | 'microsoft' | 'paypal' | 'polar' | 'spotify' | 'steam' | 'tiktok' | 'twitch' | 'vk' | 'x' | 'xsuaa' | 'yandex' | (string & {});
|
|
2
|
+
export type OAuthProvider = 'auth0' | 'battledotnet' | 'cognito' | 'discord' | 'dropbox' | 'facebook' | 'github' | 'gitlab' | 'google' | 'instagram' | 'keycloak' | 'linear' | 'linkedin' | 'microsoft' | 'paypal' | 'polar' | 'spotify' | 'steam' | 'tiktok' | 'twitch' | 'vk' | 'x' | 'xsuaa' | 'yandex' | (string & {});
|
|
3
3
|
export type OnError = (event: H3Event, error: H3Error) => Promise<void> | void;
|
|
4
4
|
export interface OAuthConfig<TConfig, TUser = any, TTokens = any> {
|
|
5
5
|
config?: TConfig;
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-auth-utils",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.4",
|
|
4
4
|
"description": "Add Authentication to Nuxt applications with secured & sealed cookies sessions.",
|
|
5
5
|
"repository": "atinux/nuxt-auth-utils",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
8
|
-
"packageManager": "pnpm@9.
|
|
8
|
+
"packageManager": "pnpm@9.12.0",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
11
|
"types": "./dist/types.d.ts",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
}
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@iconify-json/simple-icons": "^1.2.
|
|
58
|
+
"@iconify-json/simple-icons": "^1.2.6",
|
|
59
59
|
"@nuxt/devtools": "latest",
|
|
60
60
|
"@nuxt/eslint-config": "^0.5.7",
|
|
61
61
|
"@nuxt/module-builder": "^0.8.4",
|
|
@@ -65,10 +65,10 @@
|
|
|
65
65
|
"@nuxt/ui-pro": "^1.4.3",
|
|
66
66
|
"@simplewebauthn/types": "^10.0.0",
|
|
67
67
|
"changelogen": "^0.5.7",
|
|
68
|
-
"eslint": "^9.
|
|
68
|
+
"eslint": "^9.12.0",
|
|
69
69
|
"nuxt": "^3.13.2",
|
|
70
70
|
"typescript": "^5.6.2",
|
|
71
|
-
"vitest": "^2.1.
|
|
71
|
+
"vitest": "^2.1.2",
|
|
72
72
|
"vue-tsc": "^2.1.6"
|
|
73
73
|
}
|
|
74
74
|
}
|