@witchcraft/nuxt-auth 0.0.1
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 +693 -0
- package/dist/module.d.mts +170 -0
- package/dist/module.json +9 -0
- package/dist/module.mjs +146 -0
- package/dist/runtime/build/genAuthSecretKeys.d.ts +6 -0
- package/dist/runtime/build/genAuthSecretKeys.js +10 -0
- package/dist/runtime/components/ExternalCallback.d.vue.ts +7 -0
- package/dist/runtime/components/ExternalCallback.vue +96 -0
- package/dist/runtime/components/ExternalCallback.vue.d.ts +7 -0
- package/dist/runtime/components/ExternalCode.d.vue.ts +11 -0
- package/dist/runtime/components/ExternalCode.vue +77 -0
- package/dist/runtime/components/ExternalCode.vue.d.ts +11 -0
- package/dist/runtime/components/LoginProviderButtons.client.d.vue.ts +15 -0
- package/dist/runtime/components/LoginProviderButtons.client.vue +66 -0
- package/dist/runtime/components/LoginProviderButtons.client.vue.d.ts +15 -0
- package/dist/runtime/components/Mocker.d.vue.ts +2 -0
- package/dist/runtime/components/Mocker.vue +39 -0
- package/dist/runtime/components/Mocker.vue.d.ts +2 -0
- package/dist/runtime/components/SessionStatus.d.vue.ts +35 -0
- package/dist/runtime/components/SessionStatus.vue +85 -0
- package/dist/runtime/components/SessionStatus.vue.d.ts +35 -0
- package/dist/runtime/components/UserRegistration.d.vue.ts +35 -0
- package/dist/runtime/components/UserRegistration.vue +158 -0
- package/dist/runtime/components/UserRegistration.vue.d.ts +35 -0
- package/dist/runtime/composables/useAuth.d.ts +27 -0
- package/dist/runtime/composables/useAuth.js +73 -0
- package/dist/runtime/core/providerStyles.d.ts +2 -0
- package/dist/runtime/core/providerStyles.js +6 -0
- package/dist/runtime/core/providers/github.d.ts +89 -0
- package/dist/runtime/core/providers/github.js +60 -0
- package/dist/runtime/core/providers/google.d.ts +70 -0
- package/dist/runtime/core/providers/google.js +54 -0
- package/dist/runtime/middleware/authGlobal.d.ts +2 -0
- package/dist/runtime/middleware/authGlobal.js +34 -0
- package/dist/runtime/middleware/authProtected.d.ts +2 -0
- package/dist/runtime/middleware/authProtected.js +38 -0
- package/dist/runtime/server/helpers/getSafeSecretsInfo.d.ts +4 -0
- package/dist/runtime/server/helpers/getSafeSecretsInfo.js +10 -0
- package/dist/runtime/server/helpers/logSafeRoute.d.ts +1 -0
- package/dist/runtime/server/helpers/logSafeRoute.js +3 -0
- package/dist/runtime/server/helpers/signJwt.d.ts +5 -0
- package/dist/runtime/server/helpers/signJwt.js +16 -0
- package/dist/runtime/server/helpers/verifyJwt.d.ts +5 -0
- package/dist/runtime/server/helpers/verifyJwt.js +19 -0
- package/dist/runtime/server/tsconfig.json +3 -0
- package/dist/runtime/server/utils/Auth.d.ts +83 -0
- package/dist/runtime/server/utils/Auth.js +653 -0
- package/dist/runtime/server/utils/SessionManager.d.ts +25 -0
- package/dist/runtime/server/utils/SessionManager.js +93 -0
- package/dist/runtime/server/utils/createAuthHandler.d.ts +8 -0
- package/dist/runtime/server/utils/createAuthHandler.js +29 -0
- package/dist/runtime/server/utils/createAuthMiddleware.d.ts +10 -0
- package/dist/runtime/server/utils/createAuthMiddleware.js +28 -0
- package/dist/runtime/server/utils/createAuthSchema.d.ts +244 -0
- package/dist/runtime/server/utils/createAuthSchema.js +43 -0
- package/dist/runtime/types.d.ts +239 -0
- package/dist/runtime/types.js +15 -0
- package/dist/runtime/utils/createExternalAuthHandler.d.ts +36 -0
- package/dist/runtime/utils/createExternalAuthHandler.js +25 -0
- package/dist/runtime/utils/decodeQueryUri.d.ts +2 -0
- package/dist/runtime/utils/decodeQueryUri.js +4 -0
- package/dist/runtime/utils/getAuthApiRoute.d.ts +3 -0
- package/dist/runtime/utils/getAuthApiRoute.js +14 -0
- package/dist/types.d.mts +13 -0
- package/package.json +101 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import GithubLogo from "~icons/logos/github-icon";
|
|
2
|
+
import { unreachable } from "@alanscodelog/utils/unreachable";
|
|
3
|
+
import {
|
|
4
|
+
GitHub
|
|
5
|
+
} from "arctic";
|
|
6
|
+
export default class GithubProvider {
|
|
7
|
+
name = "github";
|
|
8
|
+
type = "oauth2";
|
|
9
|
+
provider;
|
|
10
|
+
providerOptions;
|
|
11
|
+
options;
|
|
12
|
+
constructor(providerOptions, options = {}) {
|
|
13
|
+
this.providerOptions = providerOptions;
|
|
14
|
+
this.options = options;
|
|
15
|
+
this.provider = new GitHub(
|
|
16
|
+
providerOptions.clientId,
|
|
17
|
+
providerOptions.clientSecret,
|
|
18
|
+
providerOptions.redirectUri
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
getLoginInfo(state) {
|
|
22
|
+
const url = this.provider.createAuthorizationURL(state, ["user:email"]);
|
|
23
|
+
return { type: "oauth2", url };
|
|
24
|
+
}
|
|
25
|
+
async getAccountInfo(tokens) {
|
|
26
|
+
const user = await $fetch("https://api.github.com/user", {
|
|
27
|
+
headers: {
|
|
28
|
+
Authorization: `Bearer ${tokens.accessToken()}`
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
const emails = await $fetch("https://api.github.com/user/emails", {
|
|
32
|
+
headers: {
|
|
33
|
+
Authorization: `Bearer ${tokens.accessToken()}`
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
const email = emails.find((m) => m.primary);
|
|
37
|
+
if (!email) unreachable();
|
|
38
|
+
const baseInfo = {
|
|
39
|
+
providerId: user.id.toString(),
|
|
40
|
+
provider: "github",
|
|
41
|
+
name: user.login,
|
|
42
|
+
email: email.email,
|
|
43
|
+
isVerified: email.verified
|
|
44
|
+
};
|
|
45
|
+
return {
|
|
46
|
+
...baseInfo,
|
|
47
|
+
info: await this.options.getAdditionalAccountInfo?.(user) ?? null
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
export const githubProviderStyle = {
|
|
52
|
+
name: "Github",
|
|
53
|
+
logo: GithubLogo,
|
|
54
|
+
style: {
|
|
55
|
+
bg: "#fff",
|
|
56
|
+
bgDark: "#000",
|
|
57
|
+
text: "#000",
|
|
58
|
+
textDark: "#fff"
|
|
59
|
+
}
|
|
60
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Google, type OAuth2Tokens } from "arctic";
|
|
2
|
+
import type { ProviderHandler, ProviderHandlerOptions, ProviderOptions } from "../../types.js";
|
|
3
|
+
declare module "../../types.js" {
|
|
4
|
+
interface InternalProviders {
|
|
5
|
+
google: GoogleUser;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export interface GoogleUser {
|
|
9
|
+
/** The audience (your app's client ID). */
|
|
10
|
+
aud: string;
|
|
11
|
+
/** Expiration time in Unix time (seconds). */
|
|
12
|
+
exp: number;
|
|
13
|
+
/** Issued at time in Unix time (seconds). */
|
|
14
|
+
iat: number;
|
|
15
|
+
/** Issuer Identifier (always "https://accounts.google.com"). */
|
|
16
|
+
iss: string;
|
|
17
|
+
/** User identifier, unique across Google accounts. */
|
|
18
|
+
sub: string;
|
|
19
|
+
/** Optional: Access token hash for validation. */
|
|
20
|
+
at_hash?: string;
|
|
21
|
+
/** Optional: Authorized presenter client ID (hybrid apps). */
|
|
22
|
+
azp?: string;
|
|
23
|
+
email: string;
|
|
24
|
+
email_verified: boolean;
|
|
25
|
+
family_name?: string;
|
|
26
|
+
given_name?: string;
|
|
27
|
+
/** User's Google Workspace/Cloud domain. */
|
|
28
|
+
hd?: string;
|
|
29
|
+
/** User's locale. */
|
|
30
|
+
locale?: string;
|
|
31
|
+
/** User's full name. */
|
|
32
|
+
name?: string;
|
|
33
|
+
/** Nonce value for replay attack protection. */
|
|
34
|
+
nonce?: string;
|
|
35
|
+
/** URL of user's profile picture. */
|
|
36
|
+
picture?: string;
|
|
37
|
+
/** URL of user's profile page. */
|
|
38
|
+
profile?: string;
|
|
39
|
+
}
|
|
40
|
+
export default class GoogleProvider implements ProviderHandler<"oauth2_pcke", "google", Google> {
|
|
41
|
+
name: "google";
|
|
42
|
+
type: "oauth2_pcke";
|
|
43
|
+
provider: Google;
|
|
44
|
+
providerOptions: ProviderHandlerOptions;
|
|
45
|
+
options: Partial<ProviderOptions<"google">>;
|
|
46
|
+
constructor(providerOptions: GoogleProvider["providerOptions"], options?: GoogleProvider["options"]);
|
|
47
|
+
getLoginInfo(state: string): {
|
|
48
|
+
type: "oauth2_pcke";
|
|
49
|
+
url: URL;
|
|
50
|
+
codeVerifier: string;
|
|
51
|
+
};
|
|
52
|
+
getAccountInfo(tokens: OAuth2Tokens): Promise<{
|
|
53
|
+
info: null;
|
|
54
|
+
name: string;
|
|
55
|
+
email: string;
|
|
56
|
+
providerId: string;
|
|
57
|
+
provider: string;
|
|
58
|
+
isVerified: boolean;
|
|
59
|
+
}>;
|
|
60
|
+
}
|
|
61
|
+
export declare const googleProviderStyle: {
|
|
62
|
+
name: string;
|
|
63
|
+
logo: import("vue").FunctionalComponent<import("vue").SVGAttributes, {}, any, {}>;
|
|
64
|
+
style: {
|
|
65
|
+
bg: string;
|
|
66
|
+
bgDark: string;
|
|
67
|
+
text: string;
|
|
68
|
+
textDark: string;
|
|
69
|
+
};
|
|
70
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {
|
|
2
|
+
generateCodeVerifier,
|
|
3
|
+
Google
|
|
4
|
+
} from "arctic";
|
|
5
|
+
import GoogleLogo from "~icons/logos/google-icon";
|
|
6
|
+
export default class GoogleProvider {
|
|
7
|
+
name = "google";
|
|
8
|
+
type = "oauth2_pcke";
|
|
9
|
+
provider;
|
|
10
|
+
providerOptions;
|
|
11
|
+
options;
|
|
12
|
+
constructor(providerOptions, options = {}) {
|
|
13
|
+
this.providerOptions = providerOptions;
|
|
14
|
+
this.options = options;
|
|
15
|
+
this.provider = new Google(
|
|
16
|
+
providerOptions.clientId,
|
|
17
|
+
providerOptions.clientSecret,
|
|
18
|
+
providerOptions.redirectUri
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
getLoginInfo(state) {
|
|
22
|
+
const codeVerifier = generateCodeVerifier();
|
|
23
|
+
const url = this.provider.createAuthorizationURL(state, codeVerifier, ["profile", "email"]);
|
|
24
|
+
return { type: "oauth2_pcke", url, codeVerifier };
|
|
25
|
+
}
|
|
26
|
+
async getAccountInfo(tokens) {
|
|
27
|
+
const user = await $fetch("https://openidconnect.googleapis.com/v1/userinfo", {
|
|
28
|
+
headers: {
|
|
29
|
+
Authorization: `Bearer ${tokens.accessToken()}`
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
const baseInfo = {
|
|
33
|
+
providerId: user.sub.toString(),
|
|
34
|
+
provider: "google",
|
|
35
|
+
name: user.name ?? "",
|
|
36
|
+
email: user.email,
|
|
37
|
+
isVerified: user.email_verified
|
|
38
|
+
};
|
|
39
|
+
return {
|
|
40
|
+
...baseInfo,
|
|
41
|
+
info: await this.options.getAdditionalAccountInfo?.(user) ?? null
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export const googleProviderStyle = {
|
|
46
|
+
name: "Google",
|
|
47
|
+
logo: GoogleLogo,
|
|
48
|
+
style: {
|
|
49
|
+
bg: "#fff",
|
|
50
|
+
bgDark: "#000",
|
|
51
|
+
text: "#000",
|
|
52
|
+
textDark: "#fff"
|
|
53
|
+
}
|
|
54
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { jsonSafeParse } from "@alanscodelog/utils/jsonSafeParse";
|
|
2
|
+
import {
|
|
3
|
+
defineNuxtRouteMiddleware,
|
|
4
|
+
useFetch,
|
|
5
|
+
useRuntimeConfig,
|
|
6
|
+
useState
|
|
7
|
+
} from "#imports";
|
|
8
|
+
import { getAuthApiRoute } from "../utils/getAuthApiRoute.js";
|
|
9
|
+
export default defineNuxtRouteMiddleware(async (_to, _from) => {
|
|
10
|
+
const doFetch = useState("auth:_fetch", () => true);
|
|
11
|
+
const userData = useState("auth:user", () => null);
|
|
12
|
+
const semiAuthed = useState("auth:semiAuthed", () => false);
|
|
13
|
+
if (import.meta.client && import.meta.dev) {
|
|
14
|
+
console.log({ ns: "auth:middleware:authGlobal", doFetch: doFetch.value, userData: userData.value });
|
|
15
|
+
}
|
|
16
|
+
if (!doFetch.value) return;
|
|
17
|
+
const res = await useFetch(getAuthApiRoute(useRuntimeConfig().public, "usersInfo"));
|
|
18
|
+
doFetch.value = false;
|
|
19
|
+
userData.value = res.data.value;
|
|
20
|
+
if (import.meta.client && !userData.value) {
|
|
21
|
+
const user = jsonSafeParse(localStorage.getItem("auth:user") ?? "null");
|
|
22
|
+
if (user.isOk && user.value) {
|
|
23
|
+
semiAuthed.value = true;
|
|
24
|
+
userData.value = user.value;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (import.meta.client && import.meta.dev) {
|
|
28
|
+
console.log({
|
|
29
|
+
ns: "auth:middleware:authGlobal:fetched",
|
|
30
|
+
userData: userData.value,
|
|
31
|
+
semiAuthed: semiAuthed.value
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { isArray } from "@alanscodelog/utils/isArray";
|
|
2
|
+
import { keys } from "@alanscodelog/utils/keys";
|
|
3
|
+
import { pick } from "@alanscodelog/utils/pick";
|
|
4
|
+
import { defineNuxtRouteMiddleware, navigateTo, useAuth, useRuntimeConfig } from "#imports";
|
|
5
|
+
export default defineNuxtRouteMiddleware(async (to, from) => {
|
|
6
|
+
const rc = useRuntimeConfig();
|
|
7
|
+
const config = rc.public.auth;
|
|
8
|
+
const auth = useAuth();
|
|
9
|
+
const meta = to.meta.auth ?? {};
|
|
10
|
+
const isRegistered = auth.user.value?.isRegistered ?? false;
|
|
11
|
+
const isAuthenticated = !!auth.user.value;
|
|
12
|
+
const fallbackRedirectPath = isAuthenticated && isRegistered ? auth.authRoutes.postRegisteredLogin : isAuthenticated && !isRegistered ? auth.authRoutes.register : auth.authRoutes.login;
|
|
13
|
+
const query = typeof from.query === "object" && meta.keepQuery ? isArray(meta.keepQuery) ? pick(from.query, meta.keepQuery) : from.query : {};
|
|
14
|
+
if (typeof meta.redirectTo === "function") {
|
|
15
|
+
meta.redirectTo = meta.redirectTo();
|
|
16
|
+
}
|
|
17
|
+
const redirectTo = (!meta.redirectTo ? fallbackRedirectPath : meta.redirectTo === "$login" ? auth.authRoutes.login : meta.redirectTo === "$register" ? auth.authRoutes.register : meta.redirectTo === "$postRegisteredLogin" ? auth.authRoutes.postRegisteredLogin : meta.redirectTo === "$externalCode" ? auth.authRoutes.externalCode : meta.redirectTo && keys(config.additionalMiddlewarePaths ?? []).includes(meta.redirectTo) ? config.additionalMiddlewarePaths[meta.redirectTo] : meta.redirectTo) + (keys(query).length > 0 ? `?${new URLSearchParams(query).toString()}` : "");
|
|
18
|
+
const matchesCondition = typeof meta.only === "function" ? meta.only(auth) : !meta.only && !isAuthenticated && isRegistered ? true : meta.only === "authenticated" && isAuthenticated || meta.only === "authenticated-registered" && isAuthenticated && isRegistered || meta.only === "registered" && isRegistered || meta.only === "authenticated-unregistered" && isAuthenticated && !isRegistered || meta.only === "unauthenticated" && !isAuthenticated;
|
|
19
|
+
const doRedirect = !matchesCondition && to.path !== redirectTo;
|
|
20
|
+
if (import.meta.client && import.meta.dev) {
|
|
21
|
+
console.log({
|
|
22
|
+
ns: "auth:middleware:authProtected",
|
|
23
|
+
willRedirect: doRedirect,
|
|
24
|
+
isRegistered,
|
|
25
|
+
isAuthenticated,
|
|
26
|
+
meta,
|
|
27
|
+
matchesCondition,
|
|
28
|
+
redirectTo
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
if (doRedirect) {
|
|
32
|
+
if (meta.handleRedirect) {
|
|
33
|
+
return meta.handleRedirect(redirectTo);
|
|
34
|
+
} else {
|
|
35
|
+
return navigateTo(redirectTo);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { capitalize } from "@alanscodelog/utils/capitalize";
|
|
2
|
+
import { isBlank } from "@alanscodelog/utils/isBlank";
|
|
3
|
+
import { useRuntimeConfig } from "#imports";
|
|
4
|
+
export function getSafeSecretsInfo() {
|
|
5
|
+
const rc = useRuntimeConfig();
|
|
6
|
+
const auth = rc.public.auth;
|
|
7
|
+
const allowedSecrets = auth.enabledProviders.flatMap((provider) => [`auth${capitalize(provider)}ClientId`, `auth${capitalize(provider)}ClientSecret`]);
|
|
8
|
+
const secretsKeysPassed = Object.keys(rc).filter((key) => allowedSecrets.includes(key) && rc[key] !== void 0 && !isBlank(rc[key]));
|
|
9
|
+
return { allowedSecrets, secretsKeysPassed };
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function logSafeRoute(route: string): string;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import jwt from "jsonwebtoken";
|
|
2
|
+
export async function signJwt(payload, secret, opts = {}) {
|
|
3
|
+
return new Promise((resolve, reject) => {
|
|
4
|
+
jwt.sign(payload, secret, opts, (err, token) => {
|
|
5
|
+
if (err) {
|
|
6
|
+
reject(err);
|
|
7
|
+
} else {
|
|
8
|
+
if (typeof token !== "string") {
|
|
9
|
+
reject(new Error(`Token was of wrong type. Expected string, got ${typeof token}.`));
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
resolve(token);
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { JwtPayload, VerifyOptions } from "jsonwebtoken";
|
|
2
|
+
/** Promisified version of jsonwebtoken.verify. */
|
|
3
|
+
export declare function verifyJwt<T extends Record<string, any>>(token: string | undefined, secret: string, opts?: Partial<VerifyOptions & {
|
|
4
|
+
complete: true;
|
|
5
|
+
}>): Promise<T & JwtPayload>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import jwt from "jsonwebtoken";
|
|
2
|
+
export async function verifyJwt(token, secret, opts = {}) {
|
|
3
|
+
if (!token) {
|
|
4
|
+
throw new Error("Missing token.");
|
|
5
|
+
}
|
|
6
|
+
return new Promise((resolve, reject) => {
|
|
7
|
+
jwt.verify(token, secret, opts, (err, decoded) => {
|
|
8
|
+
if (err) {
|
|
9
|
+
reject(err);
|
|
10
|
+
} else {
|
|
11
|
+
if (typeof decoded !== "object") {
|
|
12
|
+
reject(new Error(`Decoded was of wrong type. Expected object, got ${typeof decoded}.`));
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
resolve(decoded);
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { BaseLogger } from "@witchcraft/nuxt-logger/createUseLogger";
|
|
2
|
+
import { type OAuth2RequestError, type OAuth2Tokens } from "arctic";
|
|
3
|
+
import type { CookieSerializeOptions } from "cookie-es";
|
|
4
|
+
import type { PgDatabase } from "drizzle-orm/pg-core";
|
|
5
|
+
import type { EventHandler, H3Event, Router } from "h3";
|
|
6
|
+
import type { JwtPayload } from "jsonwebtoken";
|
|
7
|
+
import type { RuntimeConfig } from "nuxt/schema";
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
import type { AuthAccountsTable, UserTable } from "./createAuthSchema.js.js";
|
|
10
|
+
import type { SessionManager } from "./SessionManager.js.js";
|
|
11
|
+
import type { AuthOptions, AuthSession, AuthUser, BaseProviderAccountInfo, ProviderHandler, ProviderNames } from "../../types.js";
|
|
12
|
+
export declare const zState: z.ZodObject<{
|
|
13
|
+
oauthState: z.ZodString;
|
|
14
|
+
additionalState: z.ZodAny;
|
|
15
|
+
deeplink: z.ZodOptional<z.ZodString>;
|
|
16
|
+
}, z.core.$strip>;
|
|
17
|
+
type State = z.infer<typeof zState>;
|
|
18
|
+
export declare const oauth2CallbackQuery: z.ZodObject<{
|
|
19
|
+
code: z.ZodString;
|
|
20
|
+
state: z.ZodString;
|
|
21
|
+
}, z.core.$strip>;
|
|
22
|
+
export declare class Auth {
|
|
23
|
+
validRoutes: string[];
|
|
24
|
+
providers: Record<string, ProviderHandler<"oauth2"> | ProviderHandler<"oauth2_pcke">>;
|
|
25
|
+
handlers: AuthOptions["handlers"];
|
|
26
|
+
externalAccessTokenExpiresIn: AuthOptions["externalAccessTokenExpiresIn"];
|
|
27
|
+
deeplinkSchemes: Record<string, string>;
|
|
28
|
+
onRegister?: (event: H3Event,
|
|
29
|
+
/** Route the handler will redirect to (without the deeplink query param). */
|
|
30
|
+
route: string,
|
|
31
|
+
/** The deeplink query param, if any. */
|
|
32
|
+
deeplink?: string) => Promise<boolean>;
|
|
33
|
+
eventHandler: EventHandler;
|
|
34
|
+
getAdditionalState?: AuthOptions["additionalState"];
|
|
35
|
+
modifyCallbackRedirect?: AuthOptions["modifyCallbackRedirect"];
|
|
36
|
+
devBypassAuth?: AuthOptions["devBypassAuth"];
|
|
37
|
+
createMockUser: AuthOptions["createMockUser"];
|
|
38
|
+
generateUser: AuthOptions["generateUser"];
|
|
39
|
+
static defaultCreateMockUser(_username: string | undefined, id: string | undefined, provider: string): Omit<BaseProviderAccountInfo, "userId">;
|
|
40
|
+
db: PgDatabase<any, any, any>;
|
|
41
|
+
usersTable: UserTable;
|
|
42
|
+
authAccountsTable: AuthAccountsTable;
|
|
43
|
+
sessionManager: SessionManager;
|
|
44
|
+
router: Router;
|
|
45
|
+
logger: BaseLogger;
|
|
46
|
+
rc: RuntimeConfig;
|
|
47
|
+
providerCookieOpts: CookieSerializeOptions;
|
|
48
|
+
constructor(runtimeConfig: RuntimeConfig, db: Auth["db"], usersTable: Auth["usersTable"], authAccountsTable: Auth["authAccountsTable"], sessionManager: Auth["sessionManager"], router: Auth["router"], opts: AuthOptions, env: Record<`auth${string}${"ClientId" | "ClientSecret"}` | string, string>, logger: BaseLogger);
|
|
49
|
+
assertValidProvider(provider?: string): asserts provider is ProviderNames;
|
|
50
|
+
getProvider(provider: ProviderNames): ProviderHandler<"oauth2"> | ProviderHandler<"oauth2_pcke">;
|
|
51
|
+
static assertAuthorizedUser(user: AuthUser | undefined | null): asserts user is AuthUser;
|
|
52
|
+
static assertEventWithAuthorizedUser(event: H3Event): asserts event is H3Event & {
|
|
53
|
+
context: {
|
|
54
|
+
user: AuthUser;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
static assertAuthorizedUserAndId(user: AuthUser | undefined | null, id: string | undefined): asserts id is string;
|
|
58
|
+
encodeState(state: State): string;
|
|
59
|
+
decodeState(state: string): State;
|
|
60
|
+
handleOAuth2(event: H3Event, provider: ProviderHandler<"oauth2">, redirectToLogin: Record<string, string>): Promise<{
|
|
61
|
+
tokens: OAuth2Tokens;
|
|
62
|
+
additionalState: any;
|
|
63
|
+
deeplink: string | undefined;
|
|
64
|
+
}>;
|
|
65
|
+
handleOAuth2Pcke(event: H3Event, provider: ProviderHandler<"oauth2_pcke">, redirectToLogin: Record<string, string>): Promise<{
|
|
66
|
+
tokens: any;
|
|
67
|
+
additionalState: any;
|
|
68
|
+
deeplink: string | undefined;
|
|
69
|
+
}>;
|
|
70
|
+
handleMaybeTokenError(valid: boolean, tokens: OAuth2Tokens | OAuth2RequestError, redirectToLogin?: Record<string, string>): Promise<void>;
|
|
71
|
+
createSession(event: H3Event, sessionUserId: string): Promise<{
|
|
72
|
+
session: AuthSession;
|
|
73
|
+
token: string;
|
|
74
|
+
}>;
|
|
75
|
+
createRedirect(event: H3Event, userId: string, isRegistered: boolean, additionalState?: any, deeplink?: string): Promise<void>;
|
|
76
|
+
getRedirect(route: string, isRegistered: boolean, deeplink: string | undefined, accessToken: string): string;
|
|
77
|
+
getDeeplinkScheme(deeplink: string): string;
|
|
78
|
+
verifyAccessToken(accessToken?: string): Promise<JwtPayload & {
|
|
79
|
+
userId: string;
|
|
80
|
+
}>;
|
|
81
|
+
createAccessToken(userId: string, payload?: Record<string, any>): Promise<string>;
|
|
82
|
+
}
|
|
83
|
+
export {};
|