nuxt-auth-utils 0.5.29 → 0.5.30
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 -1
- package/dist/module.json +1 -1
- package/dist/runtime/app/plugins/session.client.js +1 -1
- package/dist/runtime/server/lib/oauth/apple.js +12 -3
- package/dist/runtime/server/lib/oauth/atlassian.js +7 -4
- package/dist/runtime/server/lib/oauth/auth0.js +7 -2
- package/dist/runtime/server/lib/oauth/authentik.js +7 -2
- package/dist/runtime/server/lib/oauth/azureb2c.js +2 -2
- package/dist/runtime/server/lib/oauth/battledotnet.js +7 -5
- package/dist/runtime/server/lib/oauth/box.js +2 -2
- package/dist/runtime/server/lib/oauth/cognito.js +7 -2
- package/dist/runtime/server/lib/oauth/discord.js +7 -2
- package/dist/runtime/server/lib/oauth/dropbox.js +7 -2
- package/dist/runtime/server/lib/oauth/facebook.js +7 -3
- package/dist/runtime/server/lib/oauth/gitea.js +8 -1
- package/dist/runtime/server/lib/oauth/github.js +2 -2
- package/dist/runtime/server/lib/oauth/gitlab.js +8 -1
- package/dist/runtime/server/lib/oauth/google.js +7 -3
- package/dist/runtime/server/lib/oauth/heroku.js +2 -2
- package/dist/runtime/server/lib/oauth/hubspot.js +8 -1
- package/dist/runtime/server/lib/oauth/instagram.js +7 -2
- package/dist/runtime/server/lib/oauth/keycloak.js +7 -2
- package/dist/runtime/server/lib/oauth/kick.js +6 -3
- package/dist/runtime/server/lib/oauth/line.js +7 -3
- package/dist/runtime/server/lib/oauth/linear.js +7 -2
- package/dist/runtime/server/lib/oauth/linkedin.js +7 -2
- package/dist/runtime/server/lib/oauth/livechat.js +9 -5
- package/dist/runtime/server/lib/oauth/microsoft.js +7 -3
- package/dist/runtime/server/lib/oauth/oidc.js +2 -2
- package/dist/runtime/server/lib/oauth/okta.js +3 -4
- package/dist/runtime/server/lib/oauth/ory.js +2 -2
- package/dist/runtime/server/lib/oauth/osu.js +2 -2
- package/dist/runtime/server/lib/oauth/paypal.js +7 -2
- package/dist/runtime/server/lib/oauth/polar.js +7 -2
- package/dist/runtime/server/lib/oauth/riotgames.js +2 -2
- package/dist/runtime/server/lib/oauth/roblox.js +7 -2
- package/dist/runtime/server/lib/oauth/salesforce.js +2 -2
- package/dist/runtime/server/lib/oauth/seznam.js +6 -2
- package/dist/runtime/server/lib/oauth/shopifyCustomer.js +4 -1
- package/dist/runtime/server/lib/oauth/slack.js +2 -2
- package/dist/runtime/server/lib/oauth/spotify.js +7 -2
- package/dist/runtime/server/lib/oauth/steam.js +6 -2
- package/dist/runtime/server/lib/oauth/strava.js +8 -1
- package/dist/runtime/server/lib/oauth/tiktok.js +7 -2
- package/dist/runtime/server/lib/oauth/twitch.js +7 -2
- package/dist/runtime/server/lib/oauth/vk.js +7 -1
- package/dist/runtime/server/lib/oauth/workos.js +7 -2
- package/dist/runtime/server/lib/oauth/xsuaa.js +7 -2
- package/dist/runtime/server/lib/oauth/yandex.js +8 -1
- package/dist/runtime/server/lib/oauth/zitadel.js +2 -2
- package/dist/runtime/server/lib/utils.d.ts +5 -1
- package/dist/runtime/server/lib/utils.js +11 -9
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { eventHandler, getQuery, sendRedirect, createError } from "h3";
|
|
2
2
|
import { withQuery } from "ufo";
|
|
3
3
|
import { defu } from "defu";
|
|
4
|
-
import { handleMissingConfiguration, handleAccessTokenErrorResponse, getOAuthRedirectURL, requestAccessToken } from "../utils.js";
|
|
4
|
+
import { handleMissingConfiguration, handleAccessTokenErrorResponse, getOAuthRedirectURL, handleInvalidState, handleState, requestAccessToken } from "../utils.js";
|
|
5
5
|
import { useRuntimeConfig } from "#imports";
|
|
6
6
|
export function defineOAuthLineEventHandler({
|
|
7
7
|
config,
|
|
@@ -29,6 +29,7 @@ export function defineOAuthLineEventHandler({
|
|
|
29
29
|
return handleMissingConfiguration(event, "line", ["clientId", "clientSecret"], onError);
|
|
30
30
|
}
|
|
31
31
|
const redirectURL = config.redirectURL || getOAuthRedirectURL(event);
|
|
32
|
+
const state = await handleState(event);
|
|
32
33
|
if (!query.code) {
|
|
33
34
|
config.scope = config.scope || ["profile", "openid"];
|
|
34
35
|
return sendRedirect(
|
|
@@ -38,11 +39,14 @@ export function defineOAuthLineEventHandler({
|
|
|
38
39
|
client_id: config.clientId,
|
|
39
40
|
redirect_uri: redirectURL,
|
|
40
41
|
scope: config.scope.join(" "),
|
|
41
|
-
|
|
42
|
-
|
|
42
|
+
...config.authorizationParams,
|
|
43
|
+
state
|
|
43
44
|
})
|
|
44
45
|
);
|
|
45
46
|
}
|
|
47
|
+
if (query.state !== state) {
|
|
48
|
+
return handleInvalidState(event, "line", onError);
|
|
49
|
+
}
|
|
46
50
|
const tokens = await requestAccessToken(config.tokenURL, {
|
|
47
51
|
body: {
|
|
48
52
|
grant_type: "authorization_code",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { eventHandler, getQuery, sendRedirect } from "h3";
|
|
2
2
|
import { withQuery } from "ufo";
|
|
3
3
|
import { defu } from "defu";
|
|
4
|
-
import { handleMissingConfiguration, handleAccessTokenErrorResponse, getOAuthRedirectURL, requestAccessToken } from "../utils.js";
|
|
4
|
+
import { handleMissingConfiguration, handleAccessTokenErrorResponse, getOAuthRedirectURL, handleInvalidState, handleState, requestAccessToken } from "../utils.js";
|
|
5
5
|
import { useRuntimeConfig, createError } from "#imports";
|
|
6
6
|
export function defineOAuthLinearEventHandler({ config, onSuccess, onError }) {
|
|
7
7
|
return eventHandler(async (event) => {
|
|
@@ -24,6 +24,7 @@ export function defineOAuthLinearEventHandler({ config, onSuccess, onError }) {
|
|
|
24
24
|
return handleMissingConfiguration(event, "linear", ["clientId", "clientSecret"], onError);
|
|
25
25
|
}
|
|
26
26
|
const redirectURL = config.redirectURL || getOAuthRedirectURL(event);
|
|
27
|
+
const state = await handleState(event);
|
|
27
28
|
if (!query.code) {
|
|
28
29
|
config.scope = config.scope || ["read"];
|
|
29
30
|
return sendRedirect(
|
|
@@ -33,10 +34,14 @@ export function defineOAuthLinearEventHandler({ config, onSuccess, onError }) {
|
|
|
33
34
|
client_id: config.clientId,
|
|
34
35
|
redirect_uri: redirectURL,
|
|
35
36
|
scope: config.scope.join(" "),
|
|
36
|
-
...config.authorizationParams
|
|
37
|
+
...config.authorizationParams,
|
|
38
|
+
state
|
|
37
39
|
})
|
|
38
40
|
);
|
|
39
41
|
}
|
|
42
|
+
if (query.state !== state) {
|
|
43
|
+
return handleInvalidState(event, "linear", onError);
|
|
44
|
+
}
|
|
40
45
|
const tokens = await requestAccessToken(config.tokenURL, {
|
|
41
46
|
headers: {
|
|
42
47
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { eventHandler, getQuery, sendRedirect } from "h3";
|
|
2
2
|
import { withQuery } from "ufo";
|
|
3
3
|
import { defu } from "defu";
|
|
4
|
-
import { handleMissingConfiguration, handleAccessTokenErrorResponse, getOAuthRedirectURL, requestAccessToken } from "../utils.js";
|
|
4
|
+
import { handleMissingConfiguration, handleAccessTokenErrorResponse, getOAuthRedirectURL, handleInvalidState, handleState, requestAccessToken } from "../utils.js";
|
|
5
5
|
import { useRuntimeConfig } from "#imports";
|
|
6
6
|
export function defineOAuthLinkedInEventHandler({ config, onSuccess, onError }) {
|
|
7
7
|
return eventHandler(async (event) => {
|
|
@@ -15,6 +15,7 @@ export function defineOAuthLinkedInEventHandler({ config, onSuccess, onError })
|
|
|
15
15
|
return handleMissingConfiguration(event, "linkedin", ["clientId", "clientSecret"], onError);
|
|
16
16
|
}
|
|
17
17
|
const redirectURL = config.redirectURL || getOAuthRedirectURL(event);
|
|
18
|
+
const state = await handleState(event);
|
|
18
19
|
if (!query.code) {
|
|
19
20
|
config.scope = config.scope || [];
|
|
20
21
|
if (!config.scope.length) {
|
|
@@ -30,10 +31,14 @@ export function defineOAuthLinkedInEventHandler({ config, onSuccess, onError })
|
|
|
30
31
|
client_id: config.clientId,
|
|
31
32
|
redirect_uri: redirectURL,
|
|
32
33
|
scope: config.scope.join(" "),
|
|
33
|
-
...config.authorizationParams
|
|
34
|
+
...config.authorizationParams,
|
|
35
|
+
state
|
|
34
36
|
})
|
|
35
37
|
);
|
|
36
38
|
}
|
|
39
|
+
if (query.state !== state) {
|
|
40
|
+
return handleInvalidState(event, "linkedin", onError);
|
|
41
|
+
}
|
|
37
42
|
const tokens = await requestAccessToken(config.tokenURL, {
|
|
38
43
|
body: {
|
|
39
44
|
grant_type: "authorization_code",
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { eventHandler, getQuery, sendRedirect } from "h3";
|
|
2
2
|
import { defu } from "defu";
|
|
3
3
|
import { withQuery } from "ufo";
|
|
4
|
-
import { randomUUID } from "uncrypto";
|
|
5
4
|
import {
|
|
6
5
|
getOAuthRedirectURL,
|
|
7
6
|
handleAccessTokenErrorResponse,
|
|
7
|
+
handleInvalidState,
|
|
8
8
|
handleMissingConfiguration,
|
|
9
|
+
handleState,
|
|
9
10
|
requestAccessToken
|
|
10
11
|
} from "../utils.js";
|
|
11
12
|
import { useRuntimeConfig } from "#imports";
|
|
@@ -19,9 +20,7 @@ export function defineOAuthLiveChatEventHandler({
|
|
|
19
20
|
authorizationURL: "https://accounts.livechat.com",
|
|
20
21
|
tokenURL: "https://accounts.livechat.com/v2/token",
|
|
21
22
|
userURL: "https://accounts.livechat.com/v2/accounts/me",
|
|
22
|
-
authorizationParams: {
|
|
23
|
-
state: randomUUID()
|
|
24
|
-
}
|
|
23
|
+
authorizationParams: {}
|
|
25
24
|
});
|
|
26
25
|
if (!config.clientId || !config.clientSecret) {
|
|
27
26
|
return handleMissingConfiguration(
|
|
@@ -33,6 +32,7 @@ export function defineOAuthLiveChatEventHandler({
|
|
|
33
32
|
}
|
|
34
33
|
const query = getQuery(event);
|
|
35
34
|
const redirectURL = config.redirectURL || getOAuthRedirectURL(event);
|
|
35
|
+
const state = await handleState(event);
|
|
36
36
|
if (!query.code) {
|
|
37
37
|
return sendRedirect(
|
|
38
38
|
event,
|
|
@@ -41,10 +41,14 @@ export function defineOAuthLiveChatEventHandler({
|
|
|
41
41
|
redirect_uri: redirectURL,
|
|
42
42
|
response_type: "code",
|
|
43
43
|
scope: config.scope?.length ? config.scope.join(" ") : void 0,
|
|
44
|
-
...config.authorizationParams
|
|
44
|
+
...config.authorizationParams,
|
|
45
|
+
state
|
|
45
46
|
})
|
|
46
47
|
);
|
|
47
48
|
}
|
|
49
|
+
if (query.state !== state) {
|
|
50
|
+
return handleInvalidState(event, "livechat", onError);
|
|
51
|
+
}
|
|
48
52
|
const tokens = await requestAccessToken(config.tokenURL, {
|
|
49
53
|
params: {
|
|
50
54
|
grant_type: "authorization_code",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { eventHandler, getQuery, sendRedirect } from "h3";
|
|
2
2
|
import { withQuery } from "ufo";
|
|
3
3
|
import { defu } from "defu";
|
|
4
|
-
import { handleMissingConfiguration, handleAccessTokenErrorResponse, getOAuthRedirectURL, requestAccessToken } from "../utils.js";
|
|
4
|
+
import { handleMissingConfiguration, handleAccessTokenErrorResponse, getOAuthRedirectURL, handleInvalidState, handleState, requestAccessToken } from "../utils.js";
|
|
5
5
|
import { useRuntimeConfig, createError } from "#imports";
|
|
6
6
|
export function defineOAuthMicrosoftEventHandler({ config, onSuccess, onError }) {
|
|
7
7
|
return eventHandler(async (event) => {
|
|
@@ -15,6 +15,7 @@ export function defineOAuthMicrosoftEventHandler({ config, onSuccess, onError })
|
|
|
15
15
|
const authorizationURL = config.authorizationURL || `https://login.microsoftonline.com/${config.tenant}/oauth2/v2.0/authorize`;
|
|
16
16
|
const tokenURL = config.tokenURL || `https://login.microsoftonline.com/${config.tenant}/oauth2/v2.0/token`;
|
|
17
17
|
const redirectURL = config.redirectURL || getOAuthRedirectURL(event);
|
|
18
|
+
const state = await handleState(event);
|
|
18
19
|
if (!query.code) {
|
|
19
20
|
config.scope = config.scope && config.scope.length > 0 ? config.scope : ["User.Read"];
|
|
20
21
|
config.scope = [...new Set(config.scope)];
|
|
@@ -25,11 +26,14 @@ export function defineOAuthMicrosoftEventHandler({ config, onSuccess, onError })
|
|
|
25
26
|
response_type: "code",
|
|
26
27
|
redirect_uri: redirectURL,
|
|
27
28
|
scope: config.scope.join(" "),
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
...config.authorizationParams,
|
|
30
|
+
state
|
|
30
31
|
})
|
|
31
32
|
);
|
|
32
33
|
}
|
|
34
|
+
if (query.state !== state) {
|
|
35
|
+
return handleInvalidState(event, "microsoft", onError);
|
|
36
|
+
}
|
|
33
37
|
const tokens = await requestAccessToken(tokenURL, {
|
|
34
38
|
body: {
|
|
35
39
|
grant_type: "authorization_code",
|
|
@@ -32,10 +32,10 @@ export function defineOAuthOidcEventHandler({ config, onSuccess, onError }) {
|
|
|
32
32
|
client_id: config.clientId,
|
|
33
33
|
redirect_uri: redirectURL,
|
|
34
34
|
scope: config.scope.join(" "),
|
|
35
|
-
state,
|
|
36
35
|
nonce,
|
|
37
36
|
response_type: "code",
|
|
38
|
-
...config.params?.authorization_endpoint
|
|
37
|
+
...config.params?.authorization_endpoint,
|
|
38
|
+
state
|
|
39
39
|
};
|
|
40
40
|
authQuery.code_challenge = verifier.code_challenge;
|
|
41
41
|
authQuery.code_challenge_method = verifier.code_challenge_method;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { eventHandler, getQuery, sendRedirect, createError
|
|
1
|
+
import { eventHandler, getQuery, sendRedirect, createError } from "h3";
|
|
2
2
|
import { withQuery } from "ufo";
|
|
3
3
|
import { defu } from "defu";
|
|
4
4
|
import { handleMissingConfiguration, handleState, handleInvalidState, handleAccessTokenErrorResponse, getOAuthRedirectURL, requestAccessToken } from "../utils.js";
|
|
@@ -108,13 +108,12 @@ export function defineOAuthOktaEventHandler({ config, onSuccess, onError }) {
|
|
|
108
108
|
audience: config.audience || "",
|
|
109
109
|
max_age: config.maxAge || 0,
|
|
110
110
|
connection: config.connection || "",
|
|
111
|
-
|
|
112
|
-
|
|
111
|
+
...config.authorizationParams,
|
|
112
|
+
state
|
|
113
113
|
})
|
|
114
114
|
);
|
|
115
115
|
}
|
|
116
116
|
if (query.state !== state) {
|
|
117
|
-
deleteCookie(event, "nuxt-auth-state");
|
|
118
117
|
return handleInvalidState(event, "okta", onError);
|
|
119
118
|
}
|
|
120
119
|
const tokens = await requestAccessToken(tokenURL, {
|
|
@@ -49,10 +49,10 @@ export function defineOAuthOryEventHandler({ config, onSuccess, onError }) {
|
|
|
49
49
|
response_type: "code",
|
|
50
50
|
redirect_uri: redirectURL,
|
|
51
51
|
scope: config.scope,
|
|
52
|
-
state,
|
|
53
52
|
code_challenge: verifier.code_challenge,
|
|
54
53
|
code_challenge_method: verifier.code_challenge_method,
|
|
55
|
-
...config.authorizationParams
|
|
54
|
+
...config.authorizationParams,
|
|
55
|
+
state
|
|
56
56
|
})
|
|
57
57
|
);
|
|
58
58
|
}
|
|
@@ -28,8 +28,8 @@ export function defineOAuthOsuEventHandler({ config, onSuccess, onError }) {
|
|
|
28
28
|
client_id: config.clientId,
|
|
29
29
|
redirect_uri: redirectURL,
|
|
30
30
|
scope: config.scope.join(" "),
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
...config.authorizationParams,
|
|
32
|
+
state
|
|
33
33
|
})
|
|
34
34
|
);
|
|
35
35
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { eventHandler, getQuery, sendRedirect } from "h3";
|
|
2
2
|
import { withQuery } from "ufo";
|
|
3
3
|
import { defu } from "defu";
|
|
4
|
-
import { handleMissingConfiguration, handleAccessTokenErrorResponse, getOAuthRedirectURL, requestAccessToken } from "../utils.js";
|
|
4
|
+
import { handleMissingConfiguration, handleAccessTokenErrorResponse, getOAuthRedirectURL, handleInvalidState, handleState, requestAccessToken } from "../utils.js";
|
|
5
5
|
import { useRuntimeConfig, createError } from "#imports";
|
|
6
6
|
export function defineOAuthPaypalEventHandler({ config, onSuccess, onError }) {
|
|
7
7
|
return eventHandler(async (event) => {
|
|
@@ -22,6 +22,7 @@ export function defineOAuthPaypalEventHandler({ config, onSuccess, onError }) {
|
|
|
22
22
|
config.tokenURL = `https://${paypalAPI}/v1/oauth2/token`;
|
|
23
23
|
}
|
|
24
24
|
const redirectURL = config.redirectURL || getOAuthRedirectURL(event);
|
|
25
|
+
const state = await handleState(event);
|
|
25
26
|
if (!query.code) {
|
|
26
27
|
config.scope = config.scope || [];
|
|
27
28
|
if (!config.scope.includes("openid")) {
|
|
@@ -38,10 +39,14 @@ export function defineOAuthPaypalEventHandler({ config, onSuccess, onError }) {
|
|
|
38
39
|
redirect_uri: redirectURL,
|
|
39
40
|
scope: config.scope.join(" "),
|
|
40
41
|
flowEntry: "static",
|
|
41
|
-
...config.authorizationParams
|
|
42
|
+
...config.authorizationParams,
|
|
43
|
+
state
|
|
42
44
|
})
|
|
43
45
|
);
|
|
44
46
|
}
|
|
47
|
+
if (query.state !== state) {
|
|
48
|
+
return handleInvalidState(event, "paypal", onError);
|
|
49
|
+
}
|
|
45
50
|
const tokens = await requestAccessToken(config.tokenURL, {
|
|
46
51
|
headers: {
|
|
47
52
|
Authorization: `Basic ${Buffer.from(`${config.clientId}:${config.clientSecret}`).toString("base64")}`
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { eventHandler, getQuery, sendRedirect } from "h3";
|
|
2
2
|
import { withQuery } from "ufo";
|
|
3
3
|
import { defu } from "defu";
|
|
4
|
-
import { handleAccessTokenErrorResponse, handleMissingConfiguration, getOAuthRedirectURL, requestAccessToken } from "../utils.js";
|
|
4
|
+
import { handleAccessTokenErrorResponse, handleInvalidState, handleMissingConfiguration, getOAuthRedirectURL, handleState, requestAccessToken } from "../utils.js";
|
|
5
5
|
import { useRuntimeConfig, createError } from "#imports";
|
|
6
6
|
export function defineOAuthPolarEventHandler({ config, onSuccess, onError }) {
|
|
7
7
|
return eventHandler(async (event) => {
|
|
@@ -14,6 +14,7 @@ export function defineOAuthPolarEventHandler({ config, onSuccess, onError }) {
|
|
|
14
14
|
return handleMissingConfiguration(event, "polar", ["clientId", "clientSecret"], onError);
|
|
15
15
|
}
|
|
16
16
|
const redirectURL = config.redirectURL || getOAuthRedirectURL(event);
|
|
17
|
+
const state = await handleState(event);
|
|
17
18
|
if (!query.code) {
|
|
18
19
|
config.scope = config.scope || [];
|
|
19
20
|
if (!config.scope.includes("openid"))
|
|
@@ -27,10 +28,14 @@ export function defineOAuthPolarEventHandler({ config, onSuccess, onError }) {
|
|
|
27
28
|
client_id: config.clientId,
|
|
28
29
|
redirect_uri: redirectURL,
|
|
29
30
|
scope: config.scope.join(" "),
|
|
30
|
-
...config.authorizationParams
|
|
31
|
+
...config.authorizationParams,
|
|
32
|
+
state
|
|
31
33
|
})
|
|
32
34
|
);
|
|
33
35
|
}
|
|
36
|
+
if (query.state !== state) {
|
|
37
|
+
return handleInvalidState(event, "polar", onError);
|
|
38
|
+
}
|
|
34
39
|
const tokens = await requestAccessToken(config.tokenURL, {
|
|
35
40
|
body: {
|
|
36
41
|
grant_type: "authorization_code",
|
|
@@ -38,8 +38,8 @@ export function defineOAuthRiotGamesEventHandler({ config, onSuccess, onError })
|
|
|
38
38
|
redirect_uri: redirectURL,
|
|
39
39
|
response_type: "code",
|
|
40
40
|
scope: config.scope.join(" "),
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
...config.authorizationParams,
|
|
42
|
+
state
|
|
43
43
|
})
|
|
44
44
|
);
|
|
45
45
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { eventHandler, getQuery, sendRedirect } from "h3";
|
|
2
2
|
import { withQuery } from "ufo";
|
|
3
3
|
import { defu } from "defu";
|
|
4
|
-
import { handleMissingConfiguration, handleAccessTokenErrorResponse, getOAuthRedirectURL, requestAccessToken } from "../utils.js";
|
|
4
|
+
import { handleMissingConfiguration, handleAccessTokenErrorResponse, getOAuthRedirectURL, handleInvalidState, handleState, requestAccessToken } from "../utils.js";
|
|
5
5
|
import { useRuntimeConfig } from "#imports";
|
|
6
6
|
export function defineOAuthRobloxEventHandler({ config, onSuccess, onError }) {
|
|
7
7
|
return eventHandler(async (event) => {
|
|
@@ -18,6 +18,7 @@ export function defineOAuthRobloxEventHandler({ config, onSuccess, onError }) {
|
|
|
18
18
|
return handleAccessTokenErrorResponse(event, "roblox", query, onError);
|
|
19
19
|
}
|
|
20
20
|
const redirectURL = config.redirectURL || getOAuthRedirectURL(event);
|
|
21
|
+
const state = await handleState(event);
|
|
21
22
|
if (!query.code) {
|
|
22
23
|
config.scope = config.scope || [];
|
|
23
24
|
return sendRedirect(
|
|
@@ -27,10 +28,14 @@ export function defineOAuthRobloxEventHandler({ config, onSuccess, onError }) {
|
|
|
27
28
|
client_id: config.clientId,
|
|
28
29
|
redirect_uri: redirectURL,
|
|
29
30
|
scope: config.scope.join(" "),
|
|
30
|
-
...config.authorizationParams
|
|
31
|
+
...config.authorizationParams,
|
|
32
|
+
state
|
|
31
33
|
})
|
|
32
34
|
);
|
|
33
35
|
}
|
|
36
|
+
if (query.state !== state) {
|
|
37
|
+
return handleInvalidState(event, "roblox", onError);
|
|
38
|
+
}
|
|
34
39
|
const tokens = await requestAccessToken(config.tokenURL, {
|
|
35
40
|
body: {
|
|
36
41
|
client_id: config.clientId,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import defu from "defu";
|
|
2
2
|
import { eventHandler, getQuery, sendRedirect } from "h3";
|
|
3
3
|
import { withQuery } from "ufo";
|
|
4
|
-
import { getOAuthRedirectURL, handleAccessTokenErrorResponse, handleMissingConfiguration, requestAccessToken } from "../utils.js";
|
|
4
|
+
import { getOAuthRedirectURL, handleAccessTokenErrorResponse, handleInvalidState, handleMissingConfiguration, handleState, requestAccessToken } from "../utils.js";
|
|
5
5
|
import { useRuntimeConfig } from "#imports";
|
|
6
6
|
export function defineOAuthSeznamEventHandler({ config, onSuccess, onError }) {
|
|
7
7
|
return eventHandler(async (event) => {
|
|
@@ -15,6 +15,7 @@ export function defineOAuthSeznamEventHandler({ config, onSuccess, onError }) {
|
|
|
15
15
|
return handleMissingConfiguration(event, "seznam", ["clientId", "clientSecret"], onError);
|
|
16
16
|
}
|
|
17
17
|
const redirectURL = config.redirectURL || getOAuthRedirectURL(event);
|
|
18
|
+
const state = await handleState(event);
|
|
18
19
|
if (!query.code) {
|
|
19
20
|
config.scope = config.scope || ["identity"];
|
|
20
21
|
return sendRedirect(
|
|
@@ -24,10 +25,13 @@ export function defineOAuthSeznamEventHandler({ config, onSuccess, onError }) {
|
|
|
24
25
|
client_id: config.clientId,
|
|
25
26
|
redirect_uri: redirectURL,
|
|
26
27
|
scope: config.scope.join(","),
|
|
27
|
-
state
|
|
28
|
+
state
|
|
28
29
|
})
|
|
29
30
|
);
|
|
30
31
|
}
|
|
32
|
+
if (query.state !== state) {
|
|
33
|
+
return handleInvalidState(event, "seznam", onError);
|
|
34
|
+
}
|
|
31
35
|
const tokens = await requestAccessToken(config.tokenURL, {
|
|
32
36
|
body: {
|
|
33
37
|
grant_type: "authorization_code",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createError, eventHandler, getQuery, sendRedirect } from "h3";
|
|
2
2
|
import { withQuery } from "ufo";
|
|
3
3
|
import { defu } from "defu";
|
|
4
|
-
import { getOAuthRedirectURL, handleAccessTokenErrorResponse, handleMissingConfiguration, handlePkceVerifier, handleState, requestAccessToken } from "../utils.js";
|
|
4
|
+
import { getOAuthRedirectURL, handleAccessTokenErrorResponse, handleInvalidState, handleMissingConfiguration, handlePkceVerifier, handleState, requestAccessToken } from "../utils.js";
|
|
5
5
|
import { useRuntimeConfig } from "#imports";
|
|
6
6
|
export function defineOAuthShopifyCustomerEventHandler({
|
|
7
7
|
config,
|
|
@@ -42,6 +42,9 @@ export function defineOAuthShopifyCustomerEventHandler({
|
|
|
42
42
|
})
|
|
43
43
|
);
|
|
44
44
|
}
|
|
45
|
+
if (query.state !== state) {
|
|
46
|
+
return handleInvalidState(event, "shopifyCustomer", onError);
|
|
47
|
+
}
|
|
45
48
|
const tokens = await requestAccessToken(discoveryResponse.token_endpoint, {
|
|
46
49
|
body: {
|
|
47
50
|
grant_type: "authorization_code",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { eventHandler, getQuery, sendRedirect } from "h3";
|
|
2
2
|
import { withQuery } from "ufo";
|
|
3
3
|
import { defu } from "defu";
|
|
4
|
-
import { handleMissingConfiguration, handleAccessTokenErrorResponse, getOAuthRedirectURL, requestAccessToken } from "../utils.js";
|
|
4
|
+
import { handleMissingConfiguration, handleAccessTokenErrorResponse, getOAuthRedirectURL, handleInvalidState, handleState, requestAccessToken } from "../utils.js";
|
|
5
5
|
import { useRuntimeConfig } from "#imports";
|
|
6
6
|
export function defineOAuthSpotifyEventHandler({ config, onSuccess, onError }) {
|
|
7
7
|
return eventHandler(async (event) => {
|
|
@@ -15,6 +15,7 @@ export function defineOAuthSpotifyEventHandler({ config, onSuccess, onError }) {
|
|
|
15
15
|
return handleMissingConfiguration(event, "spotify", ["clientId", "clientSecret"], onError);
|
|
16
16
|
}
|
|
17
17
|
const redirectURL = config.redirectURL || getOAuthRedirectURL(event);
|
|
18
|
+
const state = await handleState(event);
|
|
18
19
|
if (!query.code) {
|
|
19
20
|
config.scope = config.scope || [];
|
|
20
21
|
if (config.emailRequired && !config.scope.includes("user-read-email")) {
|
|
@@ -27,10 +28,14 @@ export function defineOAuthSpotifyEventHandler({ config, onSuccess, onError }) {
|
|
|
27
28
|
client_id: config.clientId,
|
|
28
29
|
redirect_uri: redirectURL,
|
|
29
30
|
scope: config.scope.join(" "),
|
|
30
|
-
...config.authorizationParams
|
|
31
|
+
...config.authorizationParams,
|
|
32
|
+
state
|
|
31
33
|
})
|
|
32
34
|
);
|
|
33
35
|
}
|
|
36
|
+
if (query.state !== state) {
|
|
37
|
+
return handleInvalidState(event, "spotify", onError);
|
|
38
|
+
}
|
|
34
39
|
const tokens = await requestAccessToken(config.tokenURL, {
|
|
35
40
|
headers: {
|
|
36
41
|
Authorization: `Basic ${Buffer.from(`${config.clientId}:${config.clientSecret}`).toString("base64")}`
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { eventHandler, createError, getQuery, getRequestURL, sendRedirect } from "h3";
|
|
2
2
|
import { withQuery } from "ufo";
|
|
3
3
|
import { defu } from "defu";
|
|
4
|
-
import { handleMissingConfiguration } from "../utils.js";
|
|
4
|
+
import { handleInvalidState, handleMissingConfiguration, handleState } from "../utils.js";
|
|
5
5
|
import { useRuntimeConfig } from "#imports";
|
|
6
6
|
export function defineOAuthSteamEventHandler({ config, onSuccess, onError }) {
|
|
7
7
|
return eventHandler(async (event) => {
|
|
@@ -13,8 +13,9 @@ export function defineOAuthSteamEventHandler({ config, onSuccess, onError }) {
|
|
|
13
13
|
return handleMissingConfiguration(event, "steam", ["apiKey"], onError);
|
|
14
14
|
}
|
|
15
15
|
const url = getRequestURL(event);
|
|
16
|
+
const state = await handleState(event, { isCallback: Boolean(query["openid.claimed_id"]) });
|
|
16
17
|
if (!query["openid.claimed_id"]) {
|
|
17
|
-
const redirectURL = config.redirectURL || getRequestURL(event).href;
|
|
18
|
+
const redirectURL = withQuery(config.redirectURL || getRequestURL(event).href, { state });
|
|
18
19
|
const realm = url.port ? `${url.protocol}//${url.hostname}:${url.port}` : `${url.protocol}//${url.hostname}`;
|
|
19
20
|
const steamOpenIdParams = {
|
|
20
21
|
"openid.ns": "http://specs.openid.net/auth/2.0",
|
|
@@ -26,6 +27,9 @@ export function defineOAuthSteamEventHandler({ config, onSuccess, onError }) {
|
|
|
26
27
|
};
|
|
27
28
|
return sendRedirect(event, withQuery(config.authorizationURL, steamOpenIdParams));
|
|
28
29
|
}
|
|
30
|
+
if (query.state !== state) {
|
|
31
|
+
return handleInvalidState(event, "steam", onError);
|
|
32
|
+
}
|
|
29
33
|
if (!query["openid.signed"] || !query["openid.sig"]) {
|
|
30
34
|
const error = createError({
|
|
31
35
|
statusCode: 400,
|
|
@@ -4,7 +4,9 @@ import { defu } from "defu";
|
|
|
4
4
|
import {
|
|
5
5
|
getOAuthRedirectURL,
|
|
6
6
|
handleAccessTokenErrorResponse,
|
|
7
|
+
handleInvalidState,
|
|
7
8
|
handleMissingConfiguration,
|
|
9
|
+
handleState,
|
|
8
10
|
requestAccessToken
|
|
9
11
|
} from "../utils.js";
|
|
10
12
|
import { useRuntimeConfig, createError } from "#imports";
|
|
@@ -36,6 +38,7 @@ export function defineOAuthStravaEventHandler({
|
|
|
36
38
|
const authorizationURL = "https://www.strava.com/oauth/authorize";
|
|
37
39
|
const tokenURL = "https://www.strava.com/oauth/token";
|
|
38
40
|
const redirectURL = config.redirectURL || getOAuthRedirectURL(event);
|
|
41
|
+
const state = await handleState(event);
|
|
39
42
|
if (!query.code) {
|
|
40
43
|
return sendRedirect(
|
|
41
44
|
event,
|
|
@@ -44,10 +47,14 @@ export function defineOAuthStravaEventHandler({
|
|
|
44
47
|
redirect_uri: redirectURL,
|
|
45
48
|
response_type: "code",
|
|
46
49
|
approval_prompt: config.approvalPrompt || "auto",
|
|
47
|
-
scope: config.scope
|
|
50
|
+
scope: config.scope,
|
|
51
|
+
state
|
|
48
52
|
})
|
|
49
53
|
);
|
|
50
54
|
}
|
|
55
|
+
if (query.state !== state) {
|
|
56
|
+
return handleInvalidState(event, "strava", onError);
|
|
57
|
+
}
|
|
51
58
|
const tokens = await requestAccessToken(tokenURL, {
|
|
52
59
|
body: {
|
|
53
60
|
client_id: config.clientId,
|
|
@@ -2,7 +2,7 @@ import crypto from "node:crypto";
|
|
|
2
2
|
import { eventHandler, getQuery, sendRedirect } from "h3";
|
|
3
3
|
import { withQuery } from "ufo";
|
|
4
4
|
import { defu } from "defu";
|
|
5
|
-
import { handleAccessTokenErrorResponse, handleMissingConfiguration, getOAuthRedirectURL, requestAccessToken } from "../utils.js";
|
|
5
|
+
import { handleAccessTokenErrorResponse, handleInvalidState, handleMissingConfiguration, getOAuthRedirectURL, handleState, requestAccessToken } from "../utils.js";
|
|
6
6
|
import { useRuntimeConfig, createError } from "#imports";
|
|
7
7
|
export function defineOAuthTikTokEventHandler({ config, onSuccess, onError }) {
|
|
8
8
|
return eventHandler(async (event) => {
|
|
@@ -17,6 +17,7 @@ export function defineOAuthTikTokEventHandler({ config, onSuccess, onError }) {
|
|
|
17
17
|
}
|
|
18
18
|
const codeVerifier = "verify";
|
|
19
19
|
const redirectURL = config.redirectURL || getOAuthRedirectURL(event);
|
|
20
|
+
const state = await handleState(event);
|
|
20
21
|
if (!query.code) {
|
|
21
22
|
config.scope = config.scope || [];
|
|
22
23
|
if (!config.scope.includes("user.info.basic")) {
|
|
@@ -33,10 +34,14 @@ export function defineOAuthTikTokEventHandler({ config, onSuccess, onError }) {
|
|
|
33
34
|
code_verifier: codeVerifier,
|
|
34
35
|
code_challenge: crypto.createHash("sha256").update(codeVerifier).digest("hex"),
|
|
35
36
|
code_challenge_method: "S256"
|
|
36
|
-
} : {}
|
|
37
|
+
} : {},
|
|
38
|
+
state
|
|
37
39
|
})
|
|
38
40
|
);
|
|
39
41
|
}
|
|
42
|
+
if (query.state !== state) {
|
|
43
|
+
return handleInvalidState(event, "tiktok", onError);
|
|
44
|
+
}
|
|
40
45
|
const tokens = await requestAccessToken(
|
|
41
46
|
config.tokenURL,
|
|
42
47
|
{
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { eventHandler, getQuery, sendRedirect } from "h3";
|
|
2
2
|
import { withQuery } from "ufo";
|
|
3
3
|
import { defu } from "defu";
|
|
4
|
-
import { handleMissingConfiguration, handleAccessTokenErrorResponse, getOAuthRedirectURL, requestAccessToken } from "../utils.js";
|
|
4
|
+
import { handleMissingConfiguration, handleAccessTokenErrorResponse, getOAuthRedirectURL, handleInvalidState, handleState, requestAccessToken } from "../utils.js";
|
|
5
5
|
import { useRuntimeConfig, createError } from "#imports";
|
|
6
6
|
export function defineOAuthTwitchEventHandler({ config, onSuccess, onError }) {
|
|
7
7
|
return eventHandler(async (event) => {
|
|
@@ -15,6 +15,7 @@ export function defineOAuthTwitchEventHandler({ config, onSuccess, onError }) {
|
|
|
15
15
|
return handleMissingConfiguration(event, "twitch", ["clientId", "clientSecret"], onError);
|
|
16
16
|
}
|
|
17
17
|
const redirectURL = config.redirectURL || getOAuthRedirectURL(event);
|
|
18
|
+
const state = await handleState(event);
|
|
18
19
|
if (!query.code) {
|
|
19
20
|
config.scope = config.scope || [];
|
|
20
21
|
if (config.emailRequired && !config.scope.includes("user:read:email")) {
|
|
@@ -27,10 +28,14 @@ export function defineOAuthTwitchEventHandler({ config, onSuccess, onError }) {
|
|
|
27
28
|
client_id: config.clientId,
|
|
28
29
|
redirect_uri: redirectURL,
|
|
29
30
|
scope: config.scope.join(" "),
|
|
30
|
-
...config.authorizationParams
|
|
31
|
+
...config.authorizationParams,
|
|
32
|
+
state
|
|
31
33
|
})
|
|
32
34
|
);
|
|
33
35
|
}
|
|
36
|
+
if (query.state !== state) {
|
|
37
|
+
return handleInvalidState(event, "twitch", onError);
|
|
38
|
+
}
|
|
34
39
|
const tokens = await requestAccessToken(config.tokenURL, {
|
|
35
40
|
body: {
|
|
36
41
|
grant_type: "authorization_code",
|
|
@@ -6,6 +6,8 @@ import {
|
|
|
6
6
|
handleMissingConfiguration,
|
|
7
7
|
handleAccessTokenErrorResponse,
|
|
8
8
|
getOAuthRedirectURL,
|
|
9
|
+
handleInvalidState,
|
|
10
|
+
handleState,
|
|
9
11
|
requestAccessToken
|
|
10
12
|
} from "../utils.js";
|
|
11
13
|
import { useRuntimeConfig, createError } from "#imports";
|
|
@@ -31,6 +33,7 @@ export function defineOAuthVKEventHandler({
|
|
|
31
33
|
}
|
|
32
34
|
const codeVerifier = "verify";
|
|
33
35
|
const redirectURL = config.redirectURL || getOAuthRedirectURL(event);
|
|
36
|
+
const state = await handleState(event);
|
|
34
37
|
if (!query.code) {
|
|
35
38
|
config.scope = config.scope || [];
|
|
36
39
|
if (config.emailRequired && !config.scope.includes("email")) {
|
|
@@ -43,12 +46,15 @@ export function defineOAuthVKEventHandler({
|
|
|
43
46
|
client_id: config.clientId,
|
|
44
47
|
code_challenge: crypto.createHash("sha256").update(codeVerifier).digest("base64url"),
|
|
45
48
|
code_challenge_method: "s256",
|
|
46
|
-
state
|
|
49
|
+
state,
|
|
47
50
|
redirect_uri: redirectURL,
|
|
48
51
|
scope: config.scope.join(" ")
|
|
49
52
|
})
|
|
50
53
|
);
|
|
51
54
|
}
|
|
55
|
+
if (query.state !== state) {
|
|
56
|
+
return handleInvalidState(event, "vk", onError);
|
|
57
|
+
}
|
|
52
58
|
const tokens = await requestAccessToken(config.tokenURL, {
|
|
53
59
|
body: {
|
|
54
60
|
grant_type: "authorization_code",
|