nuxt-auth-utils 0.5.25 → 0.5.27
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 +30 -6
- package/dist/module.d.mts +3 -4
- package/dist/module.json +1 -1
- package/dist/module.mjs +21 -6
- package/dist/runtime/app/components/AuthState.vue.d.ts +7 -6
- package/dist/runtime/server/api/session.get.d.ts +1 -5
- package/dist/runtime/server/lib/atproto/bluesky.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/apple.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/atlassian.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/auth0.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/authentik.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/azureb2c.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/azureb2c.js +0 -1
- package/dist/runtime/server/lib/oauth/battledotnet.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/cognito.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/discord.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/dropbox.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/facebook.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/gitea.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/github.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/gitlab.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/google.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/heroku.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/hubspot.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/instagram.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/keycloak.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/kick.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/line.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/linear.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/linkedin.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/livechat.d.ts +2 -3
- package/dist/runtime/server/lib/oauth/livechat.js +1 -3
- package/dist/runtime/server/lib/oauth/microsoft.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/oidc.d.ts +216 -0
- package/dist/runtime/server/lib/oauth/oidc.js +83 -0
- package/dist/runtime/server/lib/oauth/okta.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/ory.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/ory.js +1 -1
- package/dist/runtime/server/lib/oauth/paypal.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/polar.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/roblox.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/salesforce.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/seznam.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/shopifyCustomer.d.ts +26 -0
- package/dist/runtime/server/lib/oauth/shopifyCustomer.js +90 -0
- package/dist/runtime/server/lib/oauth/slack.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/spotify.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/steam.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/steam.js +2 -1
- package/dist/runtime/server/lib/oauth/strava.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/tiktok.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/twitch.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/vk.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/workos.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/x.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/x.js +18 -12
- package/dist/runtime/server/lib/oauth/xsuaa.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/yandex.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/zitadel.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/zitadel.js +5 -4
- package/dist/runtime/server/lib/utils.d.ts +9 -9
- package/dist/runtime/server/lib/utils.js +36 -20
- package/dist/runtime/server/lib/webauthn/register.js +2 -1
- package/dist/runtime/server/plugins/oauth.d.ts +1 -1
- package/dist/runtime/server/utils/password.d.ts +17 -0
- package/dist/runtime/server/utils/password.js +3 -0
- package/dist/runtime/server/utils/session.d.ts +3 -2
- package/dist/runtime/types/oauth-config.d.ts +1 -1
- package/dist/runtime/types/utils.d.ts +14 -0
- package/dist/runtime/types/webauthn.d.ts +1 -0
- package/package.json +18 -18
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import type { OAuthConfig } from '#auth-utils';
|
|
2
|
+
export interface OAuthOidcConfig {
|
|
3
|
+
/**
|
|
4
|
+
* OAuth Client ID
|
|
5
|
+
*
|
|
6
|
+
* @default process.env.NUXT_OAUTH_OIDC_CLIENT_ID
|
|
7
|
+
*/
|
|
8
|
+
clientId?: string;
|
|
9
|
+
/**
|
|
10
|
+
* OAuth Client secret.
|
|
11
|
+
* If unset, PKCE will be used where no client secret is needed.
|
|
12
|
+
*
|
|
13
|
+
* @default process.env.NUXT_OAUTH_OIDC_CLIENT_SECRET
|
|
14
|
+
*/
|
|
15
|
+
clientSecret?: string;
|
|
16
|
+
/**
|
|
17
|
+
* OpenID configuration. If a string is passed, it is considered to be the full URL to the OpenID configuration endpoint
|
|
18
|
+
* where all required endpoints are listed and fetched from automatically.
|
|
19
|
+
*
|
|
20
|
+
* Alternatively, an object can be set with the required endpoint URLs.
|
|
21
|
+
*
|
|
22
|
+
* @default process.env.NUXT_OAUTH_OIDC_OPENID_CONFIG
|
|
23
|
+
* @example "https://my-provider.com/.well-known/openid-configuration"
|
|
24
|
+
*/
|
|
25
|
+
openidConfig?: string | OIDCConfiguration;
|
|
26
|
+
/**
|
|
27
|
+
* OAuth Scope
|
|
28
|
+
*
|
|
29
|
+
* @default ['openid']
|
|
30
|
+
* @example ['openid', 'profile', 'email']
|
|
31
|
+
*/
|
|
32
|
+
scope?: string[];
|
|
33
|
+
/**
|
|
34
|
+
* Redirect URL to to allow overriding for situations like prod failing to determine public hostname
|
|
35
|
+
*
|
|
36
|
+
* @default process.env.NUXT_OAUTH_OIDC_REDIRECT_URL
|
|
37
|
+
*/
|
|
38
|
+
redirectURL?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Additional custom params that are passed to the specific endpoint requests.
|
|
41
|
+
* Can be used to provide custom (query) params.
|
|
42
|
+
*/
|
|
43
|
+
params?: Partial<Record<'authorization_endpoint' | 'token_endpoint' | 'userinfo_endpoint', object>>;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Standard OIDC claims.
|
|
47
|
+
*
|
|
48
|
+
* @see: https://openid.net/specs/openid-connect-core-1_0.html#StandardClaims
|
|
49
|
+
*/
|
|
50
|
+
interface OidcUser {
|
|
51
|
+
/**
|
|
52
|
+
* Subject - Identifier for the End-User at the Issuer.
|
|
53
|
+
*/
|
|
54
|
+
sub: string;
|
|
55
|
+
/**
|
|
56
|
+
* End-User's full name in displayable form including all name parts,
|
|
57
|
+
* possibly including titles and suffixes, ordered according to the
|
|
58
|
+
* End-User's locale and preferences.
|
|
59
|
+
*/
|
|
60
|
+
name?: string;
|
|
61
|
+
/**
|
|
62
|
+
* Given name(s) or first name(s) of the End-User. Note that in some cultures,
|
|
63
|
+
* people can have multiple given names; all can be present, with the names
|
|
64
|
+
* being separated by space characters.
|
|
65
|
+
*/
|
|
66
|
+
given_name?: string;
|
|
67
|
+
/**
|
|
68
|
+
* Surname(s) or last name(s) of the End-User. Note that in some cultures,
|
|
69
|
+
* people can have multiple family names or no family name; all can be present,
|
|
70
|
+
* with the names being separated by space characters.
|
|
71
|
+
*/
|
|
72
|
+
family_name?: string;
|
|
73
|
+
/**
|
|
74
|
+
* Middle name(s) of the End-User. Note that in some cultures, people can have
|
|
75
|
+
* multiple middle names; all can be present, with the names being separated by
|
|
76
|
+
* space characters. Also note that in some cultures, middle names are not used.
|
|
77
|
+
*/
|
|
78
|
+
middle_name?: string;
|
|
79
|
+
/**
|
|
80
|
+
* Casual name of the End-User that may or may not be the same as the given_name.
|
|
81
|
+
* For instance, a nickname value of Mike might be returned alongside a given_name
|
|
82
|
+
* value of Michael.
|
|
83
|
+
*/
|
|
84
|
+
nickname?: string;
|
|
85
|
+
/**
|
|
86
|
+
* Shorthand name by which the End-User wishes to be referred to at the RP, such as
|
|
87
|
+
* janedoe or j.doe. This value MAY be any valid JSON string including special
|
|
88
|
+
* characters such as @, /, or whitespace. The RP MUST NOT rely upon this value
|
|
89
|
+
* being unique.
|
|
90
|
+
*/
|
|
91
|
+
preferred_username?: string;
|
|
92
|
+
/**
|
|
93
|
+
* URL of the End-User's profile page. The contents of this Web page SHOULD be
|
|
94
|
+
* about the End-User.
|
|
95
|
+
*/
|
|
96
|
+
profile?: string;
|
|
97
|
+
/**
|
|
98
|
+
* URL of the End-User's profile picture. This URL MUST refer to an image file
|
|
99
|
+
* (for example, a PNG, JPEG, or GIF image file), rather than to a Web page
|
|
100
|
+
* containing an image. Note that this URL SHOULD specifically reference a profile
|
|
101
|
+
* photo of the End-User suitable for displaying when describing the End-User,
|
|
102
|
+
* rather than an arbitrary photo taken by the End-User.
|
|
103
|
+
*/
|
|
104
|
+
picture?: string;
|
|
105
|
+
/**
|
|
106
|
+
* URL of the End-User's Web page or blog. This Web page SHOULD contain information
|
|
107
|
+
* published by the End-User or an organization that the End-User is affiliated with.
|
|
108
|
+
*/
|
|
109
|
+
website?: string;
|
|
110
|
+
/**
|
|
111
|
+
* End-User's preferred e-mail address. Its value MUST conform to the RFC 5322
|
|
112
|
+
* addr-spec syntax. The RP MUST NOT rely upon this value being unique.
|
|
113
|
+
*/
|
|
114
|
+
email?: string;
|
|
115
|
+
/**
|
|
116
|
+
* True if the End-User's e-mail address has been verified; otherwise false.
|
|
117
|
+
* When this Claim Value is true, this means that the OP took affirmative steps
|
|
118
|
+
* to ensure that this e-mail address was controlled by the End-User at the time
|
|
119
|
+
* the verification was performed. The means by which an e-mail address is verified
|
|
120
|
+
* is context specific, and dependent upon the trust framework or contractual
|
|
121
|
+
* agreements within which the parties are operating.
|
|
122
|
+
*/
|
|
123
|
+
email_verified?: boolean;
|
|
124
|
+
/**
|
|
125
|
+
* End-User's gender. Values defined by this specification are female and male.
|
|
126
|
+
* Other values MAY be used when neither of the defined values are applicable.
|
|
127
|
+
*/
|
|
128
|
+
gender?: string;
|
|
129
|
+
/**
|
|
130
|
+
* End-User's birthday, represented as an ISO 8601-1 YYYY-MM-DD format. The year
|
|
131
|
+
* MAY be 0000, indicating that it is omitted. To represent only the year, YYYY
|
|
132
|
+
* format is allowed. Note that depending on the underlying platform's date related
|
|
133
|
+
* function, providing just year can result in varying month and day, so the
|
|
134
|
+
* implementers need to take this factor into account to correctly process the dates.
|
|
135
|
+
*/
|
|
136
|
+
birthdate?: string;
|
|
137
|
+
/**
|
|
138
|
+
* String from IANA Time Zone Database representing the End-User's time zone.
|
|
139
|
+
* For example, Europe/Paris or America/Los_Angeles.
|
|
140
|
+
*/
|
|
141
|
+
zoneinfo?: string;
|
|
142
|
+
/**
|
|
143
|
+
* End-User's locale, represented as a BCP47 language tag. This is typically an
|
|
144
|
+
* ISO 639 Alpha-2 language code in lowercase and an ISO 3166-1 Alpha-2 country
|
|
145
|
+
* code in uppercase, separated by a dash. For example, en-US or fr-CA. As a
|
|
146
|
+
* compatibility note, some implementations have used an underscore as the separator
|
|
147
|
+
* rather than a dash, for example, en_US; Relying Parties MAY choose to accept
|
|
148
|
+
* this locale syntax as well.
|
|
149
|
+
*/
|
|
150
|
+
locale?: string;
|
|
151
|
+
/**
|
|
152
|
+
* End-User's preferred telephone number. E.164 is RECOMMENDED as the format of
|
|
153
|
+
* this Claim, for example, +1 (555) 555-5555 or +56 (2) 687 2400. If the phone
|
|
154
|
+
* number contains an extension, it is RECOMMENDED that the extension be represented
|
|
155
|
+
* using the RFC 3966 extension syntax, for example, +1 (555) 555-5555;ext=5678.
|
|
156
|
+
*/
|
|
157
|
+
phone_number?: string;
|
|
158
|
+
/**
|
|
159
|
+
* True if the End-User's phone number has been verified; otherwise false. When
|
|
160
|
+
* this Claim Value is true, this means that the OP took affirmative steps to
|
|
161
|
+
* ensure that this phone number was controlled by the End-User at the time the
|
|
162
|
+
* verification was performed. The means by which a phone number is verified is
|
|
163
|
+
* context specific, and dependent upon the trust framework or contractual
|
|
164
|
+
* agreements within which the parties are operating. When true, the phone_number
|
|
165
|
+
* Claim MUST be in E.164 format and any extensions MUST be represented in RFC 3966 format.
|
|
166
|
+
*/
|
|
167
|
+
phone_number_verified?: boolean;
|
|
168
|
+
/**
|
|
169
|
+
* End-User's preferred postal address.
|
|
170
|
+
*/
|
|
171
|
+
address?: AddressClaim;
|
|
172
|
+
/**
|
|
173
|
+
* Time the End-User's information was last updated. Its value is a JSON number
|
|
174
|
+
* representing the number of seconds from 1970-01-01T00:00:00Z as measured in
|
|
175
|
+
* UTC until the date/time.
|
|
176
|
+
*/
|
|
177
|
+
updated_at?: number;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Address claim structure as defined in OpenID Connect specification
|
|
181
|
+
*/
|
|
182
|
+
interface AddressClaim {
|
|
183
|
+
/** Full mailing address, formatted for display or use on a mailing label */
|
|
184
|
+
formatted?: string;
|
|
185
|
+
/** Full street address component, which may include house number, street name, post office box, and multi-line extended street address information */
|
|
186
|
+
street_address?: string;
|
|
187
|
+
/** City or locality component */
|
|
188
|
+
locality?: string;
|
|
189
|
+
/** State, province, prefecture, or region component */
|
|
190
|
+
region?: string;
|
|
191
|
+
/** Zip code or postal code component */
|
|
192
|
+
postal_code?: string;
|
|
193
|
+
/** Country name component */
|
|
194
|
+
country?: string;
|
|
195
|
+
}
|
|
196
|
+
interface OidcTokens {
|
|
197
|
+
access_token: string;
|
|
198
|
+
token_type: string;
|
|
199
|
+
scope?: string;
|
|
200
|
+
id_token?: string;
|
|
201
|
+
refresh_token?: string;
|
|
202
|
+
expires_in?: number;
|
|
203
|
+
}
|
|
204
|
+
interface OIDCConfiguration {
|
|
205
|
+
authorization_endpoint: string;
|
|
206
|
+
token_endpoint: string;
|
|
207
|
+
userinfo_endpoint?: string;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Event handler for generic OAuth using OIDC and PKCE.
|
|
211
|
+
*/
|
|
212
|
+
export declare function defineOAuthOidcEventHandler<TUser = OidcUser>({ config, onSuccess, onError }: OAuthConfig<OAuthOidcConfig, {
|
|
213
|
+
user: TUser;
|
|
214
|
+
tokens: OidcTokens;
|
|
215
|
+
}>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
|
|
216
|
+
export {};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { useRuntimeConfig } from "#imports";
|
|
2
|
+
import { defu } from "defu";
|
|
3
|
+
import { createError, eventHandler, getQuery, sendRedirect } from "h3";
|
|
4
|
+
import { withQuery } from "ufo";
|
|
5
|
+
import { getOAuthRedirectURL, handleAccessTokenErrorResponse, handleInvalidState, handleMissingConfiguration, handlePkceVerifier, handleState, requestAccessToken } from "../utils.js";
|
|
6
|
+
export function defineOAuthOidcEventHandler({ config, onSuccess, onError }) {
|
|
7
|
+
return eventHandler(async (event) => {
|
|
8
|
+
config = defu(config, useRuntimeConfig(event).oauth.oidc, {
|
|
9
|
+
scope: ["openid"]
|
|
10
|
+
});
|
|
11
|
+
const query = getQuery(event);
|
|
12
|
+
if (query.error) {
|
|
13
|
+
const error = createError({
|
|
14
|
+
statusCode: 401,
|
|
15
|
+
message: `OIDC login failed: ${query.error || "Unknown error"}`,
|
|
16
|
+
data: query
|
|
17
|
+
});
|
|
18
|
+
if (!onError) throw error;
|
|
19
|
+
return onError(event, error);
|
|
20
|
+
}
|
|
21
|
+
if (!config.clientId || !config.openidConfig) {
|
|
22
|
+
return handleMissingConfiguration(event, "oidc", ["clientId", "openidConfig"], onError);
|
|
23
|
+
}
|
|
24
|
+
const oidcConfig = typeof config.openidConfig === "string" ? await $fetch(config.openidConfig) : config.openidConfig;
|
|
25
|
+
const redirectURL = config.redirectURL || getOAuthRedirectURL(event);
|
|
26
|
+
const state = await handleState(event);
|
|
27
|
+
const verifier = !config.clientSecret ? await handlePkceVerifier(event) : void 0;
|
|
28
|
+
if (!query.code) {
|
|
29
|
+
config.scope = config.scope || [];
|
|
30
|
+
const authQuery = {
|
|
31
|
+
client_id: config.clientId,
|
|
32
|
+
redirect_uri: redirectURL,
|
|
33
|
+
scope: config.scope.join(" "),
|
|
34
|
+
state,
|
|
35
|
+
response_type: "code",
|
|
36
|
+
...config.params?.authorization_endpoint
|
|
37
|
+
};
|
|
38
|
+
if (verifier) {
|
|
39
|
+
authQuery.code_challenge = verifier.code_challenge;
|
|
40
|
+
authQuery.code_challenge_method = verifier.code_challenge_method;
|
|
41
|
+
}
|
|
42
|
+
return sendRedirect(
|
|
43
|
+
event,
|
|
44
|
+
withQuery(oidcConfig.authorization_endpoint, authQuery)
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
if (query.state !== state) {
|
|
48
|
+
return handleInvalidState(event, "oidc", onError);
|
|
49
|
+
}
|
|
50
|
+
const tokenQuery = {
|
|
51
|
+
grant_type: "authorization_code",
|
|
52
|
+
client_id: config.clientId,
|
|
53
|
+
client_secret: config.clientSecret,
|
|
54
|
+
redirect_uri: redirectURL,
|
|
55
|
+
code: query.code,
|
|
56
|
+
...config.params?.token_endpoint
|
|
57
|
+
};
|
|
58
|
+
if (verifier) {
|
|
59
|
+
tokenQuery.code_verifier = verifier.code_verifier;
|
|
60
|
+
}
|
|
61
|
+
const tokens = await requestAccessToken(oidcConfig.token_endpoint, {
|
|
62
|
+
body: tokenQuery
|
|
63
|
+
});
|
|
64
|
+
if (tokens.error) {
|
|
65
|
+
return handleAccessTokenErrorResponse(event, "oidc", tokens, onError);
|
|
66
|
+
}
|
|
67
|
+
let user = {};
|
|
68
|
+
if (oidcConfig.userinfo_endpoint) {
|
|
69
|
+
user = await $fetch(oidcConfig.userinfo_endpoint, {
|
|
70
|
+
headers: {
|
|
71
|
+
Authorization: `${tokens.token_type} ${tokens.access_token}`
|
|
72
|
+
},
|
|
73
|
+
params: {
|
|
74
|
+
...config.params?.userinfo_endpoint
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
return onSuccess(event, {
|
|
79
|
+
user,
|
|
80
|
+
tokens
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
}
|
|
@@ -85,4 +85,4 @@ export interface OAuthOktaConfig {
|
|
|
85
85
|
*/
|
|
86
86
|
openIdConfigCacheTTL?: number;
|
|
87
87
|
}
|
|
88
|
-
export declare function defineOAuthOktaEventHandler({ config, onSuccess, onError }: OAuthConfigExt<OAuthOktaConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<
|
|
88
|
+
export declare function defineOAuthOktaEventHandler({ config, onSuccess, onError }: OAuthConfigExt<OAuthOktaConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
|
|
@@ -48,4 +48,4 @@ export interface OAuthOryConfig {
|
|
|
48
48
|
*/
|
|
49
49
|
userURL?: string;
|
|
50
50
|
}
|
|
51
|
-
export declare function defineOAuthOryEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthOryConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<
|
|
51
|
+
export declare function defineOAuthOryEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthOryConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
|
|
@@ -57,7 +57,7 @@ export function defineOAuthOryEventHandler({ config, onSuccess, onError }) {
|
|
|
57
57
|
);
|
|
58
58
|
}
|
|
59
59
|
if (query.state !== state) {
|
|
60
|
-
handleInvalidState(event, "ory", onError);
|
|
60
|
+
return handleInvalidState(event, "ory", onError);
|
|
61
61
|
}
|
|
62
62
|
const tokenURL = `${config.sdkURL}${config.tokenURL}`;
|
|
63
63
|
const tokens = await requestAccessToken(tokenURL, {
|
|
@@ -49,4 +49,4 @@ export interface OAuthPaypalConfig {
|
|
|
49
49
|
*/
|
|
50
50
|
redirectURL?: string;
|
|
51
51
|
}
|
|
52
|
-
export declare function defineOAuthPaypalEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthPaypalConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<
|
|
52
|
+
export declare function defineOAuthPaypalEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthPaypalConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
|
|
@@ -46,4 +46,4 @@ export interface OAuthPolarConfig {
|
|
|
46
46
|
*/
|
|
47
47
|
redirectURL?: string;
|
|
48
48
|
}
|
|
49
|
-
export declare function defineOAuthPolarEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthPolarConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<
|
|
49
|
+
export declare function defineOAuthPolarEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthPolarConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
|
|
@@ -123,4 +123,4 @@ export interface OAuthRobloxUser {
|
|
|
123
123
|
visibility: 'SOCIAL_NETWORK_VISIBILITY_UNSPECIFIED' | 'NO_ONE' | 'FRIENDS' | 'FRIENDS_AND_FOLLOWING' | 'FRIENDS_FOLLOWING_AND_FOLLOWERS' | 'EVERYONE';
|
|
124
124
|
};
|
|
125
125
|
}
|
|
126
|
-
export declare function defineOAuthRobloxEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthRobloxConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<
|
|
126
|
+
export declare function defineOAuthRobloxEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthRobloxConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
|
|
@@ -43,4 +43,4 @@ export interface OAuthSalesforceConfig {
|
|
|
43
43
|
*/
|
|
44
44
|
redirectURL?: string;
|
|
45
45
|
}
|
|
46
|
-
export declare function defineOAuthSalesforceEventHandler({ config, onSuccess, onError, }: OAuthConfig<OAuthSalesforceConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<
|
|
46
|
+
export declare function defineOAuthSalesforceEventHandler({ config, onSuccess, onError, }: OAuthConfig<OAuthSalesforceConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
|
|
@@ -95,4 +95,4 @@ export interface OAuthSeznamUser {
|
|
|
95
95
|
export declare function defineOAuthSeznamEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthSeznamConfig, {
|
|
96
96
|
user: OAuthSeznamUser;
|
|
97
97
|
tokens: unknown;
|
|
98
|
-
}>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<
|
|
98
|
+
}>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { OAuthConfig } from '#auth-utils';
|
|
2
|
+
export interface OAuthShopifyCustomerConfig {
|
|
3
|
+
/**
|
|
4
|
+
* Shopify shop domain ID
|
|
5
|
+
* @default process.env.NUXT_OAUTH_SHOPIFY_CUSTOMER_SHOP_DOMAIN
|
|
6
|
+
* @example 123.myshopify.com
|
|
7
|
+
*/
|
|
8
|
+
shopDomain?: string;
|
|
9
|
+
/**
|
|
10
|
+
* Shopify Customer Client ID
|
|
11
|
+
* @default process.env.NUXT_OAUTH_SHOPIFY_CUSTOMER_CLIENT_ID
|
|
12
|
+
*/
|
|
13
|
+
clientId?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Shopify Customer OAuth Scope
|
|
16
|
+
* @default ['openid', 'email', 'customer-account-api:full']
|
|
17
|
+
* @example ['openid', 'email', 'customer-account-api:full']
|
|
18
|
+
*/
|
|
19
|
+
scope?: string[];
|
|
20
|
+
/**
|
|
21
|
+
* Redirect URL to to allow overriding for situations like prod failing to determine public hostname
|
|
22
|
+
* @default process.env.NUXT_OAUTH_SHOPIFY_CUSTOMER_REDIRECT_URL or current URL
|
|
23
|
+
*/
|
|
24
|
+
redirectURL?: string;
|
|
25
|
+
}
|
|
26
|
+
export declare function defineOAuthShopifyCustomerEventHandler({ config, onSuccess, onError, }: OAuthConfig<OAuthShopifyCustomerConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { createError, eventHandler, getQuery, sendRedirect } from "h3";
|
|
2
|
+
import { withQuery } from "ufo";
|
|
3
|
+
import { defu } from "defu";
|
|
4
|
+
import { getOAuthRedirectURL, handleAccessTokenErrorResponse, handleMissingConfiguration, handlePkceVerifier, handleState, requestAccessToken } from "../utils.js";
|
|
5
|
+
import { useRuntimeConfig } from "#imports";
|
|
6
|
+
export function defineOAuthShopifyCustomerEventHandler({
|
|
7
|
+
config,
|
|
8
|
+
onSuccess,
|
|
9
|
+
onError
|
|
10
|
+
}) {
|
|
11
|
+
return eventHandler(async (event) => {
|
|
12
|
+
config = defu(config, useRuntimeConfig(event).oauth?.shopifyCustomer, {});
|
|
13
|
+
const query = getQuery(event);
|
|
14
|
+
if (!config.clientId || !config.shopDomain) {
|
|
15
|
+
return handleMissingConfiguration(event, "spotify", ["clientId", "shopDomain"], onError);
|
|
16
|
+
}
|
|
17
|
+
const verifier = await handlePkceVerifier(event);
|
|
18
|
+
const redirectURL = config.redirectURL || getOAuthRedirectURL(event);
|
|
19
|
+
const discoveryResponse = await $fetch(`https://${config.shopDomain}/.well-known/openid-configuration`).then((d) => d).catch(() => null);
|
|
20
|
+
if (!discoveryResponse?.issuer) {
|
|
21
|
+
const error = createError({
|
|
22
|
+
statusCode: 400,
|
|
23
|
+
message: "Getting Shopify discovery endpoint failed."
|
|
24
|
+
});
|
|
25
|
+
if (!onError) throw error;
|
|
26
|
+
return onError(event, error);
|
|
27
|
+
}
|
|
28
|
+
const state = await handleState(event);
|
|
29
|
+
if (!query.code) {
|
|
30
|
+
config.scope = config.scope && config.scope.length > 0 ? config.scope : ["openid", "email", "customer-account-api:full"];
|
|
31
|
+
config.scope = [...new Set(config.scope)];
|
|
32
|
+
return sendRedirect(
|
|
33
|
+
event,
|
|
34
|
+
withQuery(discoveryResponse.authorization_endpoint, {
|
|
35
|
+
response_type: "code",
|
|
36
|
+
client_id: config.clientId,
|
|
37
|
+
redirect_uri: redirectURL,
|
|
38
|
+
scope: config.scope.join(" "),
|
|
39
|
+
state,
|
|
40
|
+
code_challenge: verifier.code_challenge,
|
|
41
|
+
code_challenge_method: verifier.code_challenge_method
|
|
42
|
+
})
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
const tokens = await requestAccessToken(discoveryResponse.token_endpoint, {
|
|
46
|
+
body: {
|
|
47
|
+
grant_type: "authorization_code",
|
|
48
|
+
client_id: config.clientId,
|
|
49
|
+
redirect_uri: redirectURL,
|
|
50
|
+
code: query.code,
|
|
51
|
+
code_verifier: verifier.code_verifier
|
|
52
|
+
}
|
|
53
|
+
}).catch(() => ({ error: "failed" }));
|
|
54
|
+
if (tokens.error) {
|
|
55
|
+
return handleAccessTokenErrorResponse(event, "shopifyCustomer", tokens, onError);
|
|
56
|
+
}
|
|
57
|
+
const apiDiscoveryUrl = await $fetch(`https://${config.shopDomain}/.well-known/customer-account-api`).then((d) => d).catch(() => null);
|
|
58
|
+
if (!apiDiscoveryUrl?.graphql_api) {
|
|
59
|
+
const error = createError({
|
|
60
|
+
statusCode: 400,
|
|
61
|
+
message: "Getting Shopify api endpoints failed."
|
|
62
|
+
});
|
|
63
|
+
if (!onError) throw error;
|
|
64
|
+
return onError(event, error);
|
|
65
|
+
}
|
|
66
|
+
const user = await $fetch(apiDiscoveryUrl.graphql_api, {
|
|
67
|
+
method: "POST",
|
|
68
|
+
headers: {
|
|
69
|
+
"Content-Type": "application/json",
|
|
70
|
+
"Authorization": tokens.access_token
|
|
71
|
+
},
|
|
72
|
+
body: JSON.stringify({
|
|
73
|
+
operationName: "getCustomer",
|
|
74
|
+
query: "query { customer { firstName lastName emailAddress { emailAddress }}}"
|
|
75
|
+
})
|
|
76
|
+
}).then((d) => d.data).catch(() => null);
|
|
77
|
+
if (!user || !user.customer) {
|
|
78
|
+
const error = createError({
|
|
79
|
+
statusCode: 400,
|
|
80
|
+
message: "Getting Shopify Customer failed."
|
|
81
|
+
});
|
|
82
|
+
if (!onError) throw error;
|
|
83
|
+
return onError(event, error);
|
|
84
|
+
}
|
|
85
|
+
return onSuccess(event, {
|
|
86
|
+
tokens,
|
|
87
|
+
user: user.customer
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
}
|
|
@@ -38,4 +38,4 @@ export interface OAuthSlackConfig {
|
|
|
38
38
|
*/
|
|
39
39
|
redirectURL?: string;
|
|
40
40
|
}
|
|
41
|
-
export declare function defineOAuthSlackEventHandler({ config, onSuccess, onError, }: OAuthConfig<OAuthSlackConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<
|
|
41
|
+
export declare function defineOAuthSlackEventHandler({ config, onSuccess, onError, }: OAuthConfig<OAuthSlackConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
|
|
@@ -44,4 +44,4 @@ export interface OAuthSpotifyConfig {
|
|
|
44
44
|
*/
|
|
45
45
|
redirectURL?: string;
|
|
46
46
|
}
|
|
47
|
-
export declare function defineOAuthSpotifyEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthSpotifyConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<
|
|
47
|
+
export declare function defineOAuthSpotifyEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthSpotifyConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
|
|
@@ -17,4 +17,4 @@ export interface OAuthSteamConfig {
|
|
|
17
17
|
*/
|
|
18
18
|
redirectURL?: string;
|
|
19
19
|
}
|
|
20
|
-
export declare function defineOAuthSteamEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthSteamConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<
|
|
20
|
+
export declare function defineOAuthSteamEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthSteamConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
|
|
@@ -15,11 +15,12 @@ export function defineOAuthSteamEventHandler({ config, onSuccess, onError }) {
|
|
|
15
15
|
const url = getRequestURL(event);
|
|
16
16
|
if (!query["openid.claimed_id"]) {
|
|
17
17
|
const redirectURL = config.redirectURL || getRequestURL(event).href;
|
|
18
|
+
const realm = url.port ? `${url.protocol}//${url.hostname}:${url.port}` : `${url.protocol}//${url.hostname}`;
|
|
18
19
|
const steamOpenIdParams = {
|
|
19
20
|
"openid.ns": "http://specs.openid.net/auth/2.0",
|
|
20
21
|
"openid.mode": "checkid_setup",
|
|
21
22
|
"openid.return_to": redirectURL,
|
|
22
|
-
"openid.realm":
|
|
23
|
+
"openid.realm": realm,
|
|
23
24
|
"openid.identity": "http://specs.openid.net/auth/2.0/identifier_select",
|
|
24
25
|
"openid.claimed_id": "http://specs.openid.net/auth/2.0/identifier_select"
|
|
25
26
|
};
|
|
@@ -116,4 +116,4 @@ export interface OAuthStravaTokens {
|
|
|
116
116
|
export declare function defineOAuthStravaEventHandler({ config, onSuccess, onError, }: OAuthConfig<OAuthStravaConfig, {
|
|
117
117
|
user: OAuthStravaUser;
|
|
118
118
|
tokens: OAuthStravaTokens;
|
|
119
|
-
}>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<
|
|
119
|
+
}>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
|
|
@@ -42,4 +42,4 @@ export interface OAuthTikTokConfig {
|
|
|
42
42
|
*/
|
|
43
43
|
redirectURL?: string;
|
|
44
44
|
}
|
|
45
|
-
export declare function defineOAuthTikTokEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthTikTokConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<
|
|
45
|
+
export declare function defineOAuthTikTokEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthTikTokConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
|
|
@@ -44,4 +44,4 @@ export interface OAuthTwitchConfig {
|
|
|
44
44
|
*/
|
|
45
45
|
redirectURL?: string;
|
|
46
46
|
}
|
|
47
|
-
export declare function defineOAuthTwitchEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthTwitchConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<
|
|
47
|
+
export declare function defineOAuthTwitchEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthTwitchConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
|
|
@@ -43,4 +43,4 @@ export interface OAuthVKConfig {
|
|
|
43
43
|
*/
|
|
44
44
|
redirectURL?: string;
|
|
45
45
|
}
|
|
46
|
-
export declare function defineOAuthVKEventHandler({ config, onSuccess, onError, }: OAuthConfig<OAuthVKConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<
|
|
46
|
+
export declare function defineOAuthVKEventHandler({ config, onSuccess, onError, }: OAuthConfig<OAuthVKConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
|
|
@@ -63,4 +63,4 @@ export interface OAuthWorkOSTokens {
|
|
|
63
63
|
export declare function defineOAuthWorkOSEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthWorkOSConfig, {
|
|
64
64
|
user: OAuthWorkOSUser;
|
|
65
65
|
tokens: OAuthWorkOSTokens;
|
|
66
|
-
}>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<
|
|
66
|
+
}>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
|
|
@@ -43,4 +43,4 @@ export interface OAuthXConfig {
|
|
|
43
43
|
*/
|
|
44
44
|
redirectURL?: string;
|
|
45
45
|
}
|
|
46
|
-
export declare function defineOAuthXEventHandler({ config, onSuccess, onError, }: OAuthConfig<OAuthXConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<
|
|
46
|
+
export declare function defineOAuthXEventHandler({ config, onSuccess, onError, }: OAuthConfig<OAuthXConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
+
import { useRuntimeConfig } from "#imports";
|
|
2
|
+
import { defu } from "defu";
|
|
1
3
|
import { eventHandler, getQuery, sendRedirect } from "h3";
|
|
2
4
|
import { withQuery } from "ufo";
|
|
3
|
-
import { defu } from "defu";
|
|
4
|
-
import { randomUUID } from "uncrypto";
|
|
5
5
|
import {
|
|
6
|
-
handleMissingConfiguration,
|
|
7
|
-
handleAccessTokenErrorResponse,
|
|
8
6
|
getOAuthRedirectURL,
|
|
7
|
+
handleAccessTokenErrorResponse,
|
|
8
|
+
handleInvalidState,
|
|
9
|
+
handleMissingConfiguration,
|
|
10
|
+
handlePkceVerifier,
|
|
11
|
+
handleState,
|
|
9
12
|
requestAccessToken
|
|
10
13
|
} from "../utils.js";
|
|
11
|
-
import { useRuntimeConfig } from "#imports";
|
|
12
14
|
export function defineOAuthXEventHandler({
|
|
13
15
|
config,
|
|
14
16
|
onSuccess,
|
|
@@ -19,16 +21,15 @@ export function defineOAuthXEventHandler({
|
|
|
19
21
|
authorizationURL: "https://x.com/i/oauth2/authorize",
|
|
20
22
|
tokenURL: "https://api.x.com/2/oauth2/token",
|
|
21
23
|
userURL: "https://api.x.com/2/users/me",
|
|
22
|
-
authorizationParams: {
|
|
23
|
-
state: randomUUID(),
|
|
24
|
-
code_challenge: randomUUID()
|
|
25
|
-
}
|
|
24
|
+
authorizationParams: {}
|
|
26
25
|
});
|
|
27
26
|
const query = getQuery(event);
|
|
28
27
|
if (!config.clientId || !config.clientSecret) {
|
|
29
28
|
return handleMissingConfiguration(event, "x", ["clientId", "clientSecret"], onError);
|
|
30
29
|
}
|
|
31
30
|
const redirectURL = config.redirectURL || getOAuthRedirectURL(event);
|
|
31
|
+
const pkce = await handlePkceVerifier(event);
|
|
32
|
+
const state = await handleState(event);
|
|
32
33
|
if (!query.code) {
|
|
33
34
|
config.scope = config.scope || [
|
|
34
35
|
"tweet.read",
|
|
@@ -40,13 +41,18 @@ export function defineOAuthXEventHandler({
|
|
|
40
41
|
withQuery(config.authorizationURL, {
|
|
41
42
|
response_type: "code",
|
|
42
43
|
client_id: config.clientId,
|
|
43
|
-
code_challenge_method: "plain",
|
|
44
44
|
redirect_uri: redirectURL,
|
|
45
45
|
scope: config.scope.join(" "),
|
|
46
|
-
...config.authorizationParams
|
|
46
|
+
...config.authorizationParams,
|
|
47
|
+
code_challenge: pkce.code_challenge,
|
|
48
|
+
code_challenge_method: pkce.code_challenge_method,
|
|
49
|
+
state
|
|
47
50
|
})
|
|
48
51
|
);
|
|
49
52
|
}
|
|
53
|
+
if (query.state !== state) {
|
|
54
|
+
return handleInvalidState(event, "x", onError);
|
|
55
|
+
}
|
|
50
56
|
const tokens = await requestAccessToken(config.tokenURL, {
|
|
51
57
|
headers: {
|
|
52
58
|
Authorization: `Basic ${Buffer.from(
|
|
@@ -55,7 +61,7 @@ export function defineOAuthXEventHandler({
|
|
|
55
61
|
},
|
|
56
62
|
params: {
|
|
57
63
|
grant_type: "authorization_code",
|
|
58
|
-
code_verifier:
|
|
64
|
+
code_verifier: pkce.code_verifier,
|
|
59
65
|
redirect_uri: redirectURL,
|
|
60
66
|
code: query.code
|
|
61
67
|
}
|
|
@@ -28,4 +28,4 @@ export interface OAuthXSUAAConfig {
|
|
|
28
28
|
*/
|
|
29
29
|
redirectURL?: string;
|
|
30
30
|
}
|
|
31
|
-
export declare function defineOAuthXSUAAEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthXSUAAConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<
|
|
31
|
+
export declare function defineOAuthXSUAAEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthXSUAAConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
|
|
@@ -43,4 +43,4 @@ export interface OAuthYandexConfig {
|
|
|
43
43
|
*/
|
|
44
44
|
redirectURL?: string;
|
|
45
45
|
}
|
|
46
|
-
export declare function defineOAuthYandexEventHandler({ config, onSuccess, onError, }: OAuthConfig<OAuthYandexConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<
|
|
46
|
+
export declare function defineOAuthYandexEventHandler({ config, onSuccess, onError, }: OAuthConfig<OAuthYandexConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
|
|
@@ -34,4 +34,4 @@ export interface OAuthZitadelConfig {
|
|
|
34
34
|
*/
|
|
35
35
|
redirectURL?: string;
|
|
36
36
|
}
|
|
37
|
-
export declare function defineOAuthZitadelEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthZitadelConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<
|
|
37
|
+
export declare function defineOAuthZitadelEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthZitadelConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
|