nuxt-auth-utils 0.5.28 → 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 +4 -2
- package/dist/module.json +1 -1
- package/dist/module.mjs +12 -0
- 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.d.ts +95 -0
- package/dist/runtime/server/lib/oauth/box.js +69 -0
- 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 +9 -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.d.ts +74 -0
- package/dist/runtime/server/lib/oauth/riotgames.js +83 -0
- 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/dist/runtime/types/oauth-config.d.ts +1 -1
- package/dist/runtime/types/webauthn.d.ts +1 -1
- package/package.json +14 -14
|
@@ -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 defineOAuthGoogleEventHandler({
|
|
7
7
|
config,
|
|
@@ -20,6 +20,7 @@ export function defineOAuthGoogleEventHandler({
|
|
|
20
20
|
return handleMissingConfiguration(event, "google", ["clientId", "clientSecret"], onError);
|
|
21
21
|
}
|
|
22
22
|
const redirectURL = config.redirectURL || getOAuthRedirectURL(event);
|
|
23
|
+
const state = await handleState(event);
|
|
23
24
|
if (!query.code) {
|
|
24
25
|
config.scope = config.scope || ["email", "profile"];
|
|
25
26
|
return sendRedirect(
|
|
@@ -29,11 +30,14 @@ export function defineOAuthGoogleEventHandler({
|
|
|
29
30
|
client_id: config.clientId,
|
|
30
31
|
redirect_uri: redirectURL,
|
|
31
32
|
scope: config.scope.join(" "),
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
...config.authorizationParams,
|
|
34
|
+
state
|
|
34
35
|
})
|
|
35
36
|
);
|
|
36
37
|
}
|
|
38
|
+
if (query.state !== state) {
|
|
39
|
+
return handleInvalidState(event, "google", onError);
|
|
40
|
+
}
|
|
37
41
|
const tokens = await requestAccessToken(config.tokenURL, {
|
|
38
42
|
body: {
|
|
39
43
|
grant_type: "authorization_code",
|
|
@@ -5,6 +5,8 @@ import {
|
|
|
5
5
|
getOAuthRedirectURL,
|
|
6
6
|
handleAccessTokenErrorResponse,
|
|
7
7
|
handleMissingConfiguration,
|
|
8
|
+
handleInvalidState,
|
|
9
|
+
handleState,
|
|
8
10
|
requestAccessToken
|
|
9
11
|
} from "../utils.js";
|
|
10
12
|
import { useRuntimeConfig } from "#imports";
|
|
@@ -19,16 +21,21 @@ export function defineOAuthHubspotEventHandler({ config, onSuccess, onError }) {
|
|
|
19
21
|
if (query.error) {
|
|
20
22
|
return handleAccessTokenErrorResponse(event, "hubspot", query, onError);
|
|
21
23
|
}
|
|
24
|
+
const state = await handleState(event);
|
|
22
25
|
if (!query.code) {
|
|
23
26
|
return sendRedirect(
|
|
24
27
|
event,
|
|
25
28
|
withQuery("https://app.hubspot.com/oauth/authorize", {
|
|
26
29
|
client_id: config.clientId,
|
|
27
30
|
redirect_uri: redirectURL,
|
|
28
|
-
scope: config.scope?.join(" ") || "oauth"
|
|
31
|
+
scope: config.scope?.join(" ") || "oauth",
|
|
32
|
+
state
|
|
29
33
|
})
|
|
30
34
|
);
|
|
31
35
|
}
|
|
36
|
+
if (query.state !== state) {
|
|
37
|
+
return handleInvalidState(event, "hubspot", onError);
|
|
38
|
+
}
|
|
32
39
|
const tokens = await requestAccessToken(
|
|
33
40
|
"https://api.hubapi.com/oauth/v1/token",
|
|
34
41
|
{
|
|
@@ -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 defineOAuthInstagramEventHandler({
|
|
7
7
|
config,
|
|
@@ -33,6 +33,7 @@ export function defineOAuthInstagramEventHandler({
|
|
|
33
33
|
return handleMissingConfiguration(event, "instagram", ["clientId", "clientSecret"], onError);
|
|
34
34
|
}
|
|
35
35
|
const redirectURL = config.redirectURL || getOAuthRedirectURL(event);
|
|
36
|
+
const state = await handleState(event);
|
|
36
37
|
if (!query.code) {
|
|
37
38
|
config.scope = config.scope || [];
|
|
38
39
|
return sendRedirect(
|
|
@@ -41,10 +42,14 @@ export function defineOAuthInstagramEventHandler({
|
|
|
41
42
|
client_id: config.clientId,
|
|
42
43
|
redirect_uri: redirectURL,
|
|
43
44
|
scope: config.scope.join(),
|
|
44
|
-
response_type: "code"
|
|
45
|
+
response_type: "code",
|
|
46
|
+
state
|
|
45
47
|
})
|
|
46
48
|
);
|
|
47
49
|
}
|
|
50
|
+
if (query.state !== state) {
|
|
51
|
+
return handleInvalidState(event, "instagram", onError);
|
|
52
|
+
}
|
|
48
53
|
const tokens = await requestAccessToken(config.tokenURL, {
|
|
49
54
|
body: {
|
|
50
55
|
client_id: config.clientId,
|
|
@@ -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 defineOAuthKeycloakEventHandler({
|
|
7
7
|
config,
|
|
@@ -30,6 +30,7 @@ export function defineOAuthKeycloakEventHandler({
|
|
|
30
30
|
const authorizationURL = `${realmURL}/protocol/openid-connect/auth`;
|
|
31
31
|
const tokenURL = `${realmURLInternal}/protocol/openid-connect/token`;
|
|
32
32
|
const redirectURL = config.redirectURL || getOAuthRedirectURL(event);
|
|
33
|
+
const state = await handleState(event);
|
|
33
34
|
if (!query.code) {
|
|
34
35
|
config.scope = config.scope || ["openid"];
|
|
35
36
|
return sendRedirect(
|
|
@@ -40,10 +41,14 @@ export function defineOAuthKeycloakEventHandler({
|
|
|
40
41
|
redirect_uri: redirectURL,
|
|
41
42
|
scope: config.scope.join(" "),
|
|
42
43
|
response_type: "code",
|
|
43
|
-
...config.authorizationParams
|
|
44
|
+
...config.authorizationParams,
|
|
45
|
+
state
|
|
44
46
|
})
|
|
45
47
|
);
|
|
46
48
|
}
|
|
49
|
+
if (query.state !== state) {
|
|
50
|
+
return handleInvalidState(event, "keycloak", onError);
|
|
51
|
+
}
|
|
47
52
|
config.scope = config.scope || [];
|
|
48
53
|
if (!config.scope.includes("openid")) {
|
|
49
54
|
config.scope.push("openid");
|
|
@@ -56,6 +61,8 @@ export function defineOAuthKeycloakEventHandler({
|
|
|
56
61
|
redirect_uri: redirectURL,
|
|
57
62
|
code: query.code
|
|
58
63
|
}
|
|
64
|
+
}).catch((error) => {
|
|
65
|
+
return handleAccessTokenErrorResponse(event, "keycloak", error?.data || error, onError);
|
|
59
66
|
});
|
|
60
67
|
if (tokens.error) {
|
|
61
68
|
return handleAccessTokenErrorResponse(event, "keycloak", tokens, onError);
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { eventHandler, getQuery, sendRedirect } from "h3";
|
|
2
2
|
import { withQuery } from "ufo";
|
|
3
3
|
import { defu } from "defu";
|
|
4
|
-
import {
|
|
5
|
-
import { handleAccessTokenErrorResponse, handleMissingConfiguration, getOAuthRedirectURL, requestAccessToken, handlePkceVerifier } from "../utils.js";
|
|
4
|
+
import { handleAccessTokenErrorResponse, handleInvalidState, handleMissingConfiguration, getOAuthRedirectURL, requestAccessToken, handlePkceVerifier, handleState } from "../utils.js";
|
|
6
5
|
import { useRuntimeConfig, createError } from "#imports";
|
|
7
6
|
export function defineOAuthKickEventHandler({ config, onSuccess, onError }) {
|
|
8
7
|
return eventHandler(async (event) => {
|
|
@@ -15,6 +14,7 @@ export function defineOAuthKickEventHandler({ config, onSuccess, onError }) {
|
|
|
15
14
|
return handleMissingConfiguration(event, "kick", ["clientId", "clientSecret"], onError);
|
|
16
15
|
}
|
|
17
16
|
const verifier = await handlePkceVerifier(event);
|
|
17
|
+
const state = await handleState(event);
|
|
18
18
|
const redirectURL = config.redirectURL || getOAuthRedirectURL(event);
|
|
19
19
|
if (!query.code) {
|
|
20
20
|
config.scope = config.scope || [];
|
|
@@ -27,12 +27,15 @@ export function defineOAuthKickEventHandler({ config, onSuccess, onError }) {
|
|
|
27
27
|
client_id: config.clientId,
|
|
28
28
|
redirect_uri: redirectURL,
|
|
29
29
|
scope: config.scope.join(" "),
|
|
30
|
-
state
|
|
30
|
+
state,
|
|
31
31
|
code_challenge: verifier.code_challenge,
|
|
32
32
|
code_challenge_method: verifier.code_challenge_method
|
|
33
33
|
})
|
|
34
34
|
);
|
|
35
35
|
}
|
|
36
|
+
if (query.state !== state) {
|
|
37
|
+
return handleInvalidState(event, "kick", onError);
|
|
38
|
+
}
|
|
36
39
|
const tokens = await requestAccessToken(config.tokenURL, {
|
|
37
40
|
body: {
|
|
38
41
|
grant_type: "authorization_code",
|
|
@@ -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",
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { OAuthConfig } from '#auth-utils';
|
|
2
|
+
export interface OAuthRiotGamesConfig {
|
|
3
|
+
/**
|
|
4
|
+
* RiotGames OAuth Client ID
|
|
5
|
+
* @default process.env.NUXT_OAUTH_RIOTGAMES_CLIENT_ID
|
|
6
|
+
*/
|
|
7
|
+
clientId?: string;
|
|
8
|
+
/**
|
|
9
|
+
* RiotGames OAuth Client Secret
|
|
10
|
+
* @default process.env.NUXT_OAUTH_RIOTGAMES_CLIENT_SECRET
|
|
11
|
+
*/
|
|
12
|
+
clientSecret?: string;
|
|
13
|
+
/**
|
|
14
|
+
* RiotGames OAuth Scope
|
|
15
|
+
* @default []
|
|
16
|
+
* @see https://beta.developer.riotgames.com/sign-on
|
|
17
|
+
* @example ['cpid', 'offline_access']
|
|
18
|
+
*/
|
|
19
|
+
scope?: string[];
|
|
20
|
+
/**
|
|
21
|
+
* RiotGames OAuth Authorization URL
|
|
22
|
+
* @default 'https://auth.riotgames.com/authorize'
|
|
23
|
+
*/
|
|
24
|
+
authorizationURL?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Riot OAuth Token URL
|
|
27
|
+
* @default 'https://auth.riotgames.com/token'
|
|
28
|
+
*/
|
|
29
|
+
tokenURL?: string;
|
|
30
|
+
/**
|
|
31
|
+
* RiotGames API URL
|
|
32
|
+
* @default 'https://auth.riotgames.com'
|
|
33
|
+
*/
|
|
34
|
+
apiURL?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Extra authorization parameters to provide to the authorization URL
|
|
37
|
+
*/
|
|
38
|
+
authorizationParams?: Record<string, string>;
|
|
39
|
+
/**
|
|
40
|
+
* Redirect URL to to allow overriding for situations like prod failing to determine public hostname
|
|
41
|
+
* @default process.env.NUXT_OAUTH_RIOTGAMES_REDIRECT_URL
|
|
42
|
+
*/
|
|
43
|
+
redirectURL?: string;
|
|
44
|
+
/**
|
|
45
|
+
* API routing values for Accounts Endpoint. You can query for any account in any region.
|
|
46
|
+
* @default 'europe'
|
|
47
|
+
*/
|
|
48
|
+
region?: 'americas' | 'europe' | 'asia';
|
|
49
|
+
}
|
|
50
|
+
interface RiotGamesUser extends RiotGamesAccount, RiotGamesUserInfo {
|
|
51
|
+
}
|
|
52
|
+
interface RiotGamesAccount {
|
|
53
|
+
puuid: string;
|
|
54
|
+
gameName: string;
|
|
55
|
+
tagLine: string;
|
|
56
|
+
}
|
|
57
|
+
interface RiotGamesUserInfo {
|
|
58
|
+
sub: string;
|
|
59
|
+
cpid?: string;
|
|
60
|
+
jti: string;
|
|
61
|
+
}
|
|
62
|
+
interface RiotGamesTokens {
|
|
63
|
+
access_token: string;
|
|
64
|
+
refresh_token: string;
|
|
65
|
+
id_token: string;
|
|
66
|
+
expires_in: number;
|
|
67
|
+
scope: string;
|
|
68
|
+
token_type: string;
|
|
69
|
+
}
|
|
70
|
+
export declare function defineOAuthRiotGamesEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthRiotGamesConfig, {
|
|
71
|
+
user: RiotGamesUser;
|
|
72
|
+
tokens: RiotGamesTokens;
|
|
73
|
+
}>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
|
|
74
|
+
export {};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { createError, eventHandler, getQuery, sendRedirect } from "h3";
|
|
2
|
+
import { withQuery } from "ufo";
|
|
3
|
+
import { defu } from "defu";
|
|
4
|
+
import { getOAuthRedirectURL, handleAccessTokenErrorResponse, handleInvalidState, handleMissingConfiguration, handleState, requestAccessToken } from "../utils.js";
|
|
5
|
+
import { useRuntimeConfig } from "#imports";
|
|
6
|
+
export function defineOAuthRiotGamesEventHandler({ config, onSuccess, onError }) {
|
|
7
|
+
return eventHandler(async (event) => {
|
|
8
|
+
config = defu(config, useRuntimeConfig(event).oauth?.riotgames, {
|
|
9
|
+
authorizationURL: "https://auth.riotgames.com/authorize",
|
|
10
|
+
tokenURL: "https://auth.riotgames.com/token",
|
|
11
|
+
apiURL: "https://auth.riotgames.com",
|
|
12
|
+
region: "europe"
|
|
13
|
+
});
|
|
14
|
+
const query = getQuery(event);
|
|
15
|
+
if (query.error) {
|
|
16
|
+
const error = createError({
|
|
17
|
+
statusCode: 401,
|
|
18
|
+
message: `RiotGames login failed: ${query.error || "Unknown error"}`,
|
|
19
|
+
data: query
|
|
20
|
+
});
|
|
21
|
+
if (!onError) throw error;
|
|
22
|
+
return onError(event, error);
|
|
23
|
+
}
|
|
24
|
+
if (!config.clientId || !config.clientSecret) {
|
|
25
|
+
return handleMissingConfiguration(event, "riotgames", ["clientId", "clientSecret"], onError);
|
|
26
|
+
}
|
|
27
|
+
const redirectURL = config.redirectURL || getOAuthRedirectURL(event);
|
|
28
|
+
const state = await handleState(event);
|
|
29
|
+
if (!query.code) {
|
|
30
|
+
config.scope = config.scope || [];
|
|
31
|
+
if (!config.scope.includes("openid")) {
|
|
32
|
+
config.scope.push("openid");
|
|
33
|
+
}
|
|
34
|
+
return sendRedirect(
|
|
35
|
+
event,
|
|
36
|
+
withQuery(config.authorizationURL, {
|
|
37
|
+
client_id: config.clientId,
|
|
38
|
+
redirect_uri: redirectURL,
|
|
39
|
+
response_type: "code",
|
|
40
|
+
scope: config.scope.join(" "),
|
|
41
|
+
...config.authorizationParams,
|
|
42
|
+
state
|
|
43
|
+
})
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
if (query.state !== state) {
|
|
47
|
+
return handleInvalidState(event, "riotgames", onError);
|
|
48
|
+
}
|
|
49
|
+
const tokens = await requestAccessToken(config.tokenURL, {
|
|
50
|
+
body: {
|
|
51
|
+
grant_type: "authorization_code",
|
|
52
|
+
client_id: config.clientId,
|
|
53
|
+
client_secret: config.clientSecret,
|
|
54
|
+
redirect_uri: redirectURL,
|
|
55
|
+
code: query.code
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
if (tokens.error) {
|
|
59
|
+
return handleAccessTokenErrorResponse(event, "riotgames", tokens, onError);
|
|
60
|
+
}
|
|
61
|
+
const accessToken = tokens.access_token;
|
|
62
|
+
const [account, userInfo] = await Promise.all([
|
|
63
|
+
$fetch(`https://${config.region}.api.riotgames.com/riot/account/v1/accounts/me`, {
|
|
64
|
+
headers: {
|
|
65
|
+
Authorization: `Bearer ${accessToken}`
|
|
66
|
+
}
|
|
67
|
+
}),
|
|
68
|
+
$fetch(`${config.apiURL}/userinfo`, {
|
|
69
|
+
headers: {
|
|
70
|
+
Authorization: `Bearer ${accessToken}`
|
|
71
|
+
}
|
|
72
|
+
})
|
|
73
|
+
]);
|
|
74
|
+
const user = {
|
|
75
|
+
...account,
|
|
76
|
+
...userInfo
|
|
77
|
+
};
|
|
78
|
+
return onSuccess(event, {
|
|
79
|
+
user,
|
|
80
|
+
tokens
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
}
|