@absolutejs/auth 0.22.4 → 0.22.5
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/dist/index.js +11078 -233
- package/dist/index.js.map +106 -17
- package/dist/src/authSessionStores.d.ts +7 -0
- package/dist/src/authorize.d.ts +12 -6
- package/dist/src/callback.d.ts +8 -2
- package/dist/src/errors.d.ts +12 -0
- package/dist/src/index.d.ts +25 -11
- package/dist/src/linkedProviderResolver.d.ts +22 -0
- package/dist/src/linkedProviderStores.d.ts +9 -0
- package/dist/src/neonLinkedProviders.d.ts +1722 -0
- package/dist/src/oauthLinkedProviderResolver.d.ts +9 -0
- package/dist/src/profile.d.ts +1 -1
- package/dist/src/protectRoute.d.ts +8 -3
- package/dist/src/providerClients.d.ts +41 -0
- package/dist/src/refresh.d.ts +5 -3
- package/dist/src/revoke.d.ts +5 -3
- package/dist/src/sessionAccess.d.ts +31 -0
- package/dist/src/sessionCleanup.d.ts +4 -2
- package/dist/src/sessionTypes.d.ts +11 -0
- package/dist/src/signout.d.ts +3 -1
- package/dist/src/typeGuards.d.ts +2 -1
- package/dist/src/typebox.d.ts +2 -0
- package/dist/src/types.d.ts +65 -12
- package/dist/src/userStatus.d.ts +3 -1
- package/dist/src/utils.d.ts +10 -2
- package/package.json +12 -5
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { LinkedProviderBindingStore, LinkedProviderGrantStore } from '@absolutejs/linked-providers';
|
|
2
|
+
import type { OAuth2ConfigurationOptions } from './types';
|
|
3
|
+
export type CreateOAuthLinkedProviderCredentialResolverOptions = {
|
|
4
|
+
grantStore: LinkedProviderGrantStore;
|
|
5
|
+
bindingStore: LinkedProviderBindingStore;
|
|
6
|
+
providersConfiguration: OAuth2ConfigurationOptions;
|
|
7
|
+
now?: () => number;
|
|
8
|
+
};
|
|
9
|
+
export declare const createOAuthLinkedProviderCredentialResolver: ({ bindingStore, grantStore, now, providersConfiguration }: CreateOAuthLinkedProviderCredentialResolverOptions) => Promise<import("@absolutejs/linked-providers").LinkedProviderCredentialResolver>;
|
package/dist/src/profile.d.ts
CHANGED
|
@@ -34,7 +34,7 @@ export declare const profile: <UserType>({ clientProviders, profileRoute, onProf
|
|
|
34
34
|
response: {
|
|
35
35
|
200: Response;
|
|
36
36
|
400: "Cookies are missing";
|
|
37
|
-
401: "Client provider not found" | "No auth provider found" | "Invalid provider" | "No user session found";
|
|
37
|
+
401: "Client provider not found" | "Client variant is required" | "Client variant not found" | "Provider is required" | "No auth provider found" | "Invalid provider" | "No user session found";
|
|
38
38
|
422: {
|
|
39
39
|
type: "validation";
|
|
40
40
|
on: string;
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { Elysia } from 'elysia';
|
|
2
|
-
import {
|
|
3
|
-
type AuthFailError =
|
|
2
|
+
import type { AbsoluteAuthSessionStore } from './sessionTypes';
|
|
3
|
+
type AuthFailError = {
|
|
4
|
+
readonly code: 'Bad Request';
|
|
5
|
+
readonly message: 'Cookies are missing';
|
|
6
|
+
} | {
|
|
4
7
|
readonly code: 'Unauthorized';
|
|
5
8
|
readonly message: 'User is not authenticated';
|
|
6
9
|
};
|
|
7
|
-
export declare const protectRoutePlugin: <UserType>(
|
|
10
|
+
export declare const protectRoutePlugin: <UserType>({ authSessionStore }?: {
|
|
11
|
+
authSessionStore?: AbsoluteAuthSessionStore<UserType>;
|
|
12
|
+
}) => Elysia<"", {
|
|
8
13
|
decorator: {};
|
|
9
14
|
store: {
|
|
10
15
|
session: import("./types").SessionRecord<UserType>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { CredentialsFor, OAuth2Client, ProviderOption } from 'citra';
|
|
2
|
+
import { OAuth2ConfigurationOptions, OAuth2ProviderClientConfiguration, ClientProviderEntry, ClientProviderGroup } from './types';
|
|
3
|
+
export declare const normalizeProvidersConfiguration: (providersConfiguration: OAuth2ConfigurationOptions) => Record<ProviderOption, Record<string, OAuth2ProviderClientConfiguration<ProviderOption>>>;
|
|
4
|
+
export declare const resolveProviderClientConfiguration: ({ clientName, providerName, providersConfiguration }: {
|
|
5
|
+
providerName: ProviderOption;
|
|
6
|
+
clientName?: string;
|
|
7
|
+
providersConfiguration: OAuth2ConfigurationOptions;
|
|
8
|
+
}) => {
|
|
9
|
+
error: "Client provider not found";
|
|
10
|
+
config?: undefined;
|
|
11
|
+
} | {
|
|
12
|
+
config: OAuth2ProviderClientConfiguration<"42" | "amazoncognito" | "anilist" | "apple" | "atlassian" | "auth0" | "authentik" | "autodesk" | "battlenet" | "bitbucket" | "box" | "bungie" | "coinbase" | "discord" | "donationalerts" | "dribbble" | "dropbox" | "epicgames" | "etsy" | "facebook" | "figma" | "gitea" | "github" | "gitlab" | "google" | "intuit" | "kakao" | "keycloak" | "kick" | "lichess" | "line" | "linear" | "linkedin" | "mastodon" | "mercadolibre" | "mercadopago" | "microsoftentraid" | "myanimelist" | "naver" | "notion" | "okta" | "osu" | "patreon" | "polar" | "polaraccesslink" | "polarteampro" | "reddit" | "roblox" | "salesforce" | "shikimori" | "slack" | "spotify" | "startgg" | "strava" | "synology" | "tiktok" | "tiltify" | "tumblr" | "twitch" | "twitter" | "vk" | "withings" | "workos" | "yahoo" | "yandex" | "zoom"> | undefined;
|
|
13
|
+
error?: undefined;
|
|
14
|
+
} | {
|
|
15
|
+
error: "Client variant is required";
|
|
16
|
+
config?: undefined;
|
|
17
|
+
} | {
|
|
18
|
+
error: "Client variant not found";
|
|
19
|
+
config?: undefined;
|
|
20
|
+
};
|
|
21
|
+
export declare const buildClientProviders: (providersConfiguration: OAuth2ConfigurationOptions, createOAuth2ClientFn: <P extends ProviderOption>(providerName: P, config: CredentialsFor<P>) => Promise<OAuth2Client<P>>) => Promise<Record<string, ClientProviderGroup>>;
|
|
22
|
+
export declare const resolveClientProviderEntry: ({ clientName, clientProviders, providerName }: {
|
|
23
|
+
providerName: string | undefined;
|
|
24
|
+
clientName?: string;
|
|
25
|
+
clientProviders: Record<string, ClientProviderGroup>;
|
|
26
|
+
}) => {
|
|
27
|
+
error: "Provider is required";
|
|
28
|
+
entry?: undefined;
|
|
29
|
+
} | {
|
|
30
|
+
error: "Client provider not found";
|
|
31
|
+
entry?: undefined;
|
|
32
|
+
} | {
|
|
33
|
+
entry: ClientProviderEntry;
|
|
34
|
+
error?: undefined;
|
|
35
|
+
} | {
|
|
36
|
+
error: "Client variant is required";
|
|
37
|
+
entry?: undefined;
|
|
38
|
+
} | {
|
|
39
|
+
error: "Client variant not found";
|
|
40
|
+
entry?: undefined;
|
|
41
|
+
};
|
package/dist/src/refresh.d.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { Elysia } from 'elysia';
|
|
2
|
+
import type { AbsoluteAuthSessionStore } from './sessionTypes';
|
|
2
3
|
import { ClientProviders, OnRefreshError, OnRefreshSuccess, RouteString } from './types';
|
|
3
|
-
type RefreshProps = {
|
|
4
|
+
type RefreshProps<UserType> = {
|
|
5
|
+
authSessionStore?: AbsoluteAuthSessionStore<UserType>;
|
|
4
6
|
clientProviders: ClientProviders;
|
|
5
7
|
refreshRoute?: RouteString;
|
|
6
8
|
onRefreshSuccess: OnRefreshSuccess;
|
|
7
9
|
onRefreshError: OnRefreshError;
|
|
8
10
|
sessionDurationMs?: number;
|
|
9
11
|
};
|
|
10
|
-
export declare const refresh: <UserType>({ clientProviders, refreshRoute, onRefreshSuccess, onRefreshError, sessionDurationMs }: RefreshProps) => Elysia<"", {
|
|
12
|
+
export declare const refresh: <UserType>({ authSessionStore, clientProviders, refreshRoute, onRefreshSuccess, onRefreshError, sessionDurationMs }: RefreshProps<UserType>) => Elysia<"", {
|
|
11
13
|
decorator: {};
|
|
12
14
|
store: {
|
|
13
15
|
session: import("./types").SessionRecord<UserType>;
|
|
@@ -35,7 +37,7 @@ export declare const refresh: <UserType>({ clientProviders, refreshRoute, onRefr
|
|
|
35
37
|
response: {
|
|
36
38
|
200: Response;
|
|
37
39
|
400: "Cookies are missing" | "Invalid provider" | "No refresh token found";
|
|
38
|
-
401: "Client provider not found" | "No auth provider found" | "No user session found";
|
|
40
|
+
401: "Client provider not found" | "Client variant is required" | "Client variant not found" | "Provider is required" | "No auth provider found" | "No user session found";
|
|
39
41
|
422: {
|
|
40
42
|
type: "validation";
|
|
41
43
|
on: string;
|
package/dist/src/revoke.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { Elysia } from 'elysia';
|
|
2
|
+
import type { AbsoluteAuthSessionStore } from './sessionTypes';
|
|
2
3
|
import { ClientProviders, OnRevocationError, OnRevocationSuccess, RouteString } from './types';
|
|
3
|
-
type RevokeProps = {
|
|
4
|
+
type RevokeProps<UserType> = {
|
|
5
|
+
authSessionStore?: AbsoluteAuthSessionStore<UserType>;
|
|
4
6
|
clientProviders: ClientProviders;
|
|
5
7
|
revokeRoute?: RouteString;
|
|
6
8
|
onRevocationSuccess: OnRevocationSuccess;
|
|
7
9
|
onRevocationError: OnRevocationError;
|
|
8
10
|
};
|
|
9
|
-
export declare const revoke: <UserType>({ clientProviders, revokeRoute, onRevocationSuccess, onRevocationError }: RevokeProps) => Elysia<"", {
|
|
11
|
+
export declare const revoke: <UserType>({ authSessionStore, clientProviders, revokeRoute, onRevocationSuccess, onRevocationError }: RevokeProps<UserType>) => Elysia<"", {
|
|
10
12
|
decorator: {};
|
|
11
13
|
store: {
|
|
12
14
|
session: import("./types").SessionRecord<UserType>;
|
|
@@ -34,7 +36,7 @@ export declare const revoke: <UserType>({ clientProviders, revokeRoute, onRevoca
|
|
|
34
36
|
response: {
|
|
35
37
|
200: Response;
|
|
36
38
|
400: "Cookies are missing" | "Invalid provider";
|
|
37
|
-
401: "Client provider not found" | "No auth provider found" | "No user session found";
|
|
39
|
+
401: "Client provider not found" | "Client variant is required" | "Client variant not found" | "Provider is required" | "No auth provider found" | "No user session found";
|
|
38
40
|
422: {
|
|
39
41
|
type: "validation";
|
|
40
42
|
on: string;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Cookie } from 'elysia';
|
|
2
|
+
import type { AbsoluteAuthSessionStore } from './sessionTypes';
|
|
3
|
+
import type { SessionData, SessionRecord, UnregisteredSessionRecord, UserSessionId } from './types';
|
|
4
|
+
export declare const loadSessionFromSource: <UserType>({ authSessionStore, session, userSessionId, removeExpired }: {
|
|
5
|
+
authSessionStore?: AbsoluteAuthSessionStore<UserType>;
|
|
6
|
+
session?: SessionRecord<UserType>;
|
|
7
|
+
userSessionId?: UserSessionId;
|
|
8
|
+
removeExpired?: boolean;
|
|
9
|
+
}) => Promise<SessionData<UserType> | undefined>;
|
|
10
|
+
export declare const getStatusFromSource: <UserType>({ authSessionStore, session, user_session_id }: {
|
|
11
|
+
authSessionStore?: AbsoluteAuthSessionStore<UserType>;
|
|
12
|
+
session?: SessionRecord<UserType>;
|
|
13
|
+
user_session_id: Cookie<UserSessionId | undefined>;
|
|
14
|
+
}) => Promise<{
|
|
15
|
+
error: {
|
|
16
|
+
readonly code: "Bad Request";
|
|
17
|
+
readonly message: "Cookies are missing";
|
|
18
|
+
};
|
|
19
|
+
user: null;
|
|
20
|
+
} | {
|
|
21
|
+
error: null;
|
|
22
|
+
user: NonNullable<UserType> | null;
|
|
23
|
+
}>;
|
|
24
|
+
export declare const createSessionCompatibilityLayer: <UserType>({ authSessionStore, userSessionId }: {
|
|
25
|
+
authSessionStore?: AbsoluteAuthSessionStore<UserType>;
|
|
26
|
+
userSessionId?: UserSessionId;
|
|
27
|
+
}) => Promise<{
|
|
28
|
+
session: SessionRecord<UserType>;
|
|
29
|
+
unregisteredSession: UnregisteredSessionRecord;
|
|
30
|
+
persist: () => Promise<void>;
|
|
31
|
+
}>;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { Elysia } from 'elysia';
|
|
2
|
-
import {
|
|
2
|
+
import type { AbsoluteAuthSessionStore } from './sessionTypes';
|
|
3
|
+
import type { OnSessionCleanup, SessionRecord, UnregisteredSessionRecord } from './types';
|
|
3
4
|
type SessionCleanupProps<UserType> = {
|
|
5
|
+
authSessionStore?: AbsoluteAuthSessionStore<UserType>;
|
|
4
6
|
cleanupIntervalMs?: number;
|
|
5
7
|
maxSessions?: number;
|
|
6
8
|
onSessionCleanup?: OnSessionCleanup<UserType>;
|
|
7
9
|
};
|
|
8
|
-
export declare const sessionCleanup: <UserType>({ cleanupIntervalMs, maxSessions, onSessionCleanup }: SessionCleanupProps<UserType>) => Elysia<"", {
|
|
10
|
+
export declare const sessionCleanup: <UserType>({ authSessionStore, cleanupIntervalMs, maxSessions, onSessionCleanup }: SessionCleanupProps<UserType>) => Elysia<"", {
|
|
9
11
|
decorator: {};
|
|
10
12
|
store: {
|
|
11
13
|
session: SessionRecord<UserType>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { SessionData, UnregisteredSessionData, UserSessionId } from './types';
|
|
2
|
+
export type AbsoluteAuthSessionStore<UserType> = {
|
|
3
|
+
getSession: (id: UserSessionId) => Promise<SessionData<UserType> | undefined>;
|
|
4
|
+
setSession: (id: UserSessionId, value: SessionData<UserType>) => Promise<void>;
|
|
5
|
+
removeSession: (id: UserSessionId) => Promise<void>;
|
|
6
|
+
getUnregisteredSession: (id: UserSessionId) => Promise<UnregisteredSessionData | undefined>;
|
|
7
|
+
setUnregisteredSession: (id: UserSessionId, value: UnregisteredSessionData) => Promise<void>;
|
|
8
|
+
removeUnregisteredSession: (id: UserSessionId) => Promise<void>;
|
|
9
|
+
listSessionIds?: () => Promise<UserSessionId[]>;
|
|
10
|
+
listUnregisteredSessionIds?: () => Promise<UserSessionId[]>;
|
|
11
|
+
};
|
package/dist/src/signout.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { Elysia } from 'elysia';
|
|
2
|
+
import type { AbsoluteAuthSessionStore } from './sessionTypes';
|
|
2
3
|
import { OnSignOut, RouteString } from './types';
|
|
3
4
|
type SignOutProps<UserType> = {
|
|
5
|
+
authSessionStore?: AbsoluteAuthSessionStore<UserType>;
|
|
4
6
|
signoutRoute?: RouteString;
|
|
5
7
|
onSignOut: OnSignOut<UserType>;
|
|
6
8
|
};
|
|
7
|
-
export declare const signout: <UserType>({ signoutRoute, onSignOut }: SignOutProps<UserType>) => Elysia<"", {
|
|
9
|
+
export declare const signout: <UserType>({ authSessionStore, signoutRoute, onSignOut }: SignOutProps<UserType>) => Elysia<"", {
|
|
8
10
|
decorator: {};
|
|
9
11
|
store: {
|
|
10
12
|
session: import("./types").SessionRecord<UserType>;
|
package/dist/src/typeGuards.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { StatusReturn, UserSessionId } from './types';
|
|
1
|
+
import { AuthIntent, StatusReturn, UserSessionId } from './types';
|
|
2
2
|
export declare const isValidUser: <UserType>(user: unknown) => user is UserType;
|
|
3
3
|
export declare const isUserSessionId: (key: string) => key is UserSessionId;
|
|
4
4
|
export declare const isNonEmptyString: (str: string | null | undefined) => str is string;
|
|
5
5
|
export declare const isStatusResponse: (value: unknown) => value is StatusReturn;
|
|
6
|
+
export declare const isAuthIntent: (value: unknown) => value is AuthIntent;
|
package/dist/src/typebox.d.ts
CHANGED
|
@@ -2,3 +2,5 @@ export declare const userSessionIdTypebox: import("@sinclair/typebox").TOptional
|
|
|
2
2
|
export declare const authProviderOption: import("@sinclair/typebox").TEnum<{
|
|
3
3
|
[k: string]: "42" | "amazoncognito" | "anilist" | "apple" | "atlassian" | "auth0" | "authentik" | "autodesk" | "battlenet" | "bitbucket" | "box" | "bungie" | "coinbase" | "discord" | "donationalerts" | "dribbble" | "dropbox" | "epicgames" | "etsy" | "facebook" | "figma" | "gitea" | "github" | "gitlab" | "google" | "intuit" | "kakao" | "keycloak" | "kick" | "lichess" | "line" | "linear" | "linkedin" | "mastodon" | "mercadolibre" | "mercadopago" | "microsoftentraid" | "myanimelist" | "naver" | "notion" | "okta" | "osu" | "patreon" | "polar" | "polaraccesslink" | "polarteampro" | "reddit" | "roblox" | "salesforce" | "shikimori" | "slack" | "spotify" | "startgg" | "strava" | "synology" | "tiktok" | "tiltify" | "tumblr" | "twitch" | "twitter" | "vk" | "withings" | "workos" | "yahoo" | "yandex" | "zoom";
|
|
4
4
|
}>;
|
|
5
|
+
export declare const authClientOption: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
6
|
+
export declare const authIntentOption: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"login">, import("@sinclair/typebox").TLiteral<"link_identity">, import("@sinclair/typebox").TLiteral<"link_connector">]>>;
|
package/dist/src/types.d.ts
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import { CredentialsFor, NonEmptyArray, OAuth2Client, OAuth2TokenResponse, ProviderOption, ProvidersMap } from 'citra';
|
|
2
2
|
import { Cookie, status as statusType, redirect as redirectType } from 'elysia';
|
|
3
3
|
import { ElysiaCustomStatusResponse } from 'elysia/error';
|
|
4
|
+
import type { AuthIdentityConflict } from './errors';
|
|
5
|
+
import type { AbsoluteAuthSessionStore } from './sessionTypes';
|
|
6
|
+
export type AuthIntent = 'login' | 'link_identity' | 'link_connector';
|
|
7
|
+
export type OAuth2ProviderClientConfiguration<Provider extends ProviderOption> = {
|
|
8
|
+
credentials: CredentialsFor<Provider>;
|
|
9
|
+
searchParams?: [string, string][];
|
|
10
|
+
} & (ProvidersMap[Provider]['scopeRequired'] extends true ? {
|
|
11
|
+
scope: NonEmptyArray<string>;
|
|
12
|
+
} : {
|
|
13
|
+
scope?: string[];
|
|
14
|
+
});
|
|
15
|
+
export type OAuth2ProviderConfiguration<Provider extends ProviderOption> = OAuth2ProviderClientConfiguration<Provider> | Record<string, OAuth2ProviderClientConfiguration<Provider>>;
|
|
4
16
|
export type OAuth2ConfigurationOptions = {
|
|
5
|
-
[Provider in ProviderOption]?:
|
|
6
|
-
credentials: CredentialsFor<Provider>;
|
|
7
|
-
searchParams?: [string, string][];
|
|
8
|
-
} & (ProvidersMap[Provider]['scopeRequired'] extends true ? {
|
|
9
|
-
scope: NonEmptyArray<string>;
|
|
10
|
-
} : {
|
|
11
|
-
scope?: string[];
|
|
12
|
-
});
|
|
17
|
+
[Provider in ProviderOption]?: OAuth2ProviderConfiguration<Provider>;
|
|
13
18
|
};
|
|
14
19
|
export type UserSessionId = `${string}-${string}-${string}-${string}-${string}`;
|
|
15
20
|
export type SessionData<UserType> = {
|
|
@@ -27,59 +32,95 @@ export type UnregisteredSessionData = {
|
|
|
27
32
|
refreshToken?: string;
|
|
28
33
|
};
|
|
29
34
|
export type UnregisteredSessionRecord = Record<UserSessionId, UnregisteredSessionData>;
|
|
35
|
+
export type ResolvedOAuthAuthorization = {
|
|
36
|
+
userIdentity: Record<string, unknown>;
|
|
37
|
+
accessToken: string;
|
|
38
|
+
refreshToken?: string;
|
|
39
|
+
expiresAt?: number;
|
|
40
|
+
tokenType?: string;
|
|
41
|
+
};
|
|
30
42
|
export type StatusReturn = ElysiaCustomStatusResponse<any, any, any>;
|
|
31
43
|
export type OnNewUser<UserType> = (userIdentity: Record<string, unknown>) => UserType | StatusReturn | Response | Promise<UserType | StatusReturn | Response>;
|
|
32
44
|
export type GetUser<UserType> = (userIdentity: Record<string, unknown>) => UserType | null | undefined | Promise<UserType | null | undefined>;
|
|
33
45
|
export type CallbackCookie = Record<string, Cookie<unknown>> & {
|
|
46
|
+
auth_client: Cookie<string | undefined>;
|
|
47
|
+
auth_intent: Cookie<AuthIntent | undefined>;
|
|
34
48
|
user_session_id: Cookie<UserSessionId | undefined>;
|
|
35
49
|
};
|
|
36
|
-
export type
|
|
50
|
+
export type CallbackContext<UserType> = {
|
|
37
51
|
providerInstance: OAuth2Client<ProviderOption>;
|
|
38
52
|
authProvider: ProviderOption;
|
|
53
|
+
authClient?: string;
|
|
54
|
+
authIntent: AuthIntent;
|
|
39
55
|
tokenResponse: OAuth2TokenResponse;
|
|
40
56
|
session: SessionRecord<UserType>;
|
|
41
57
|
unregisteredSession: UnregisteredSessionRecord;
|
|
42
58
|
userSessionId: UserSessionId;
|
|
43
59
|
originUrl: string;
|
|
44
60
|
cookie: CallbackCookie;
|
|
61
|
+
currentUser?: UserType;
|
|
45
62
|
status: typeof statusType;
|
|
46
63
|
redirect: typeof redirectType;
|
|
64
|
+
};
|
|
65
|
+
export type ResolveAuthIntent<UserType> = (({ authProvider, authClient, originUrl, session, userSessionId, currentUser }: {
|
|
66
|
+
authProvider: ProviderOption;
|
|
67
|
+
authClient?: string;
|
|
68
|
+
originUrl: string;
|
|
69
|
+
session: SessionRecord<UserType>;
|
|
70
|
+
userSessionId?: UserSessionId;
|
|
71
|
+
currentUser?: UserType;
|
|
72
|
+
}) => AuthIntent | Promise<AuthIntent>) | undefined;
|
|
73
|
+
export type OnCallbackSuccess<UserType> = ((context: CallbackContext<UserType>) => void | Response | StatusReturn | Promise<void | Response | StatusReturn>) | undefined;
|
|
74
|
+
export type OnLinkIdentity<UserType> = ((context: CallbackContext<UserType>) => void | Response | StatusReturn | Promise<void | Response | StatusReturn>) | undefined;
|
|
75
|
+
export type OnLinkIdentityConflict<UserType> = ((context: CallbackContext<UserType> & {
|
|
76
|
+
conflict: AuthIdentityConflict;
|
|
47
77
|
}) => void | Response | StatusReturn | Promise<void | Response | StatusReturn>) | undefined;
|
|
78
|
+
export type OnLinkConnector<UserType> = ((context: CallbackContext<UserType>) => void | Response | StatusReturn | Promise<void | Response | StatusReturn>) | undefined;
|
|
48
79
|
export type OnCallbackError = (({ error, authProvider, originUrl }: {
|
|
49
80
|
authProvider: string;
|
|
81
|
+
authClient?: string;
|
|
50
82
|
error: unknown;
|
|
51
83
|
originUrl: string;
|
|
52
84
|
}) => void | Promise<void>) | undefined;
|
|
53
|
-
export type OnAuthorizeSuccess = (({ authProvider, authorizationUrl }: {
|
|
85
|
+
export type OnAuthorizeSuccess = (({ authProvider, authClient, authIntent, authorizationUrl }: {
|
|
54
86
|
authProvider: string;
|
|
87
|
+
authClient?: string;
|
|
88
|
+
authIntent?: AuthIntent;
|
|
55
89
|
authorizationUrl: URL;
|
|
56
90
|
}) => void | Promise<void>) | undefined;
|
|
57
91
|
export type OnAuthorizeError = (({ error, authProvider }: {
|
|
58
92
|
authProvider: string;
|
|
93
|
+
authClient?: string;
|
|
59
94
|
error: unknown;
|
|
60
95
|
}) => void | Promise<void>) | undefined;
|
|
61
96
|
export type OnRefreshSuccess = (({ tokenResponse, authProvider }: {
|
|
62
97
|
tokenResponse: OAuth2TokenResponse;
|
|
63
98
|
authProvider: string;
|
|
99
|
+
authClient?: string;
|
|
64
100
|
}) => void | Promise<void>) | undefined;
|
|
65
101
|
export type OnRefreshError = (({ error, authProvider }: {
|
|
66
102
|
authProvider: string;
|
|
103
|
+
authClient?: string;
|
|
67
104
|
error: unknown;
|
|
68
105
|
}) => void | Promise<void>) | undefined;
|
|
69
106
|
export type OnProfileSuccess = (({ userProfile, authProvider }: {
|
|
70
107
|
userProfile: Record<string, unknown>;
|
|
71
108
|
authProvider: string;
|
|
109
|
+
authClient?: string;
|
|
72
110
|
}) => void | Promise<void>) | undefined;
|
|
73
111
|
export type OnProfileError = (({ error, authProvider }: {
|
|
74
112
|
authProvider: string;
|
|
113
|
+
authClient?: string;
|
|
75
114
|
error: unknown;
|
|
76
115
|
}) => void | Promise<void>) | undefined;
|
|
77
116
|
export type OnRevocationSuccess = (({ tokenToRevoke, authProvider }: {
|
|
78
117
|
tokenToRevoke: string;
|
|
79
118
|
authProvider: string;
|
|
119
|
+
authClient?: string;
|
|
80
120
|
}) => void | Promise<void>) | undefined;
|
|
81
121
|
export type OnRevocationError = (({ error, authProvider }: {
|
|
82
122
|
authProvider: string;
|
|
123
|
+
authClient?: string;
|
|
83
124
|
error: unknown;
|
|
84
125
|
}) => void | Promise<void>) | undefined;
|
|
85
126
|
export type OnStatus<UserType> = (({ user }: {
|
|
@@ -108,10 +149,15 @@ export type AbsoluteAuthProps<UserType> = {
|
|
|
108
149
|
cleanupIntervalMs?: number;
|
|
109
150
|
maxSessions?: number;
|
|
110
151
|
sessionDurationMs?: number;
|
|
152
|
+
authSessionStore?: AbsoluteAuthSessionStore<UserType>;
|
|
111
153
|
unregisteredSessionDurationMs?: number;
|
|
154
|
+
resolveAuthIntent?: ResolveAuthIntent<UserType>;
|
|
112
155
|
onAuthorizeSuccess?: OnAuthorizeSuccess;
|
|
113
156
|
onAuthorizeError?: OnAuthorizeError;
|
|
114
157
|
onCallbackSuccess?: OnCallbackSuccess<UserType>;
|
|
158
|
+
onLinkIdentity?: OnLinkIdentity<UserType>;
|
|
159
|
+
onLinkIdentityConflict?: OnLinkIdentityConflict<UserType>;
|
|
160
|
+
onLinkConnector?: OnLinkConnector<UserType>;
|
|
115
161
|
onCallbackError?: OnCallbackError;
|
|
116
162
|
onStatus?: OnStatus<UserType>;
|
|
117
163
|
onRefreshSuccess?: OnRefreshSuccess;
|
|
@@ -123,11 +169,17 @@ export type AbsoluteAuthProps<UserType> = {
|
|
|
123
169
|
onProfileError?: OnProfileError;
|
|
124
170
|
onSessionCleanup?: OnSessionCleanup<UserType>;
|
|
125
171
|
};
|
|
126
|
-
export type
|
|
172
|
+
export type ClientProviderEntry = {
|
|
173
|
+
clientName?: string;
|
|
127
174
|
providerInstance: OAuth2Client<ProviderOption>;
|
|
128
175
|
scope?: string[];
|
|
129
176
|
searchParams?: [string, string][];
|
|
130
|
-
}
|
|
177
|
+
};
|
|
178
|
+
export type ClientProviderGroup = {
|
|
179
|
+
entries: Record<string, ClientProviderEntry>;
|
|
180
|
+
isSingleClient: boolean;
|
|
181
|
+
};
|
|
182
|
+
export type ClientProviders = Record<string, ClientProviderGroup>;
|
|
131
183
|
export type InsantiateUserSessionProps<UserType> = {
|
|
132
184
|
authProvider: ProviderOption;
|
|
133
185
|
tokenResponse: OAuth2TokenResponse;
|
|
@@ -137,6 +189,7 @@ export type InsantiateUserSessionProps<UserType> = {
|
|
|
137
189
|
user_session_id: Cookie<UserSessionId | undefined>;
|
|
138
190
|
onNewUser: OnNewUser<UserType>;
|
|
139
191
|
getUser: GetUser<UserType>;
|
|
192
|
+
resolvedAuthorization?: ResolvedOAuthAuthorization;
|
|
140
193
|
sessionDurationMs?: number;
|
|
141
194
|
unregisteredSessionDurationMs?: number;
|
|
142
195
|
};
|
package/dist/src/userStatus.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { Elysia } from 'elysia';
|
|
2
|
+
import type { AbsoluteAuthSessionStore } from './sessionTypes';
|
|
2
3
|
import { OnStatus, RouteString } from './types';
|
|
3
4
|
type StatusProps<UserType> = {
|
|
5
|
+
authSessionStore?: AbsoluteAuthSessionStore<UserType>;
|
|
4
6
|
statusRoute?: RouteString;
|
|
5
7
|
onStatus: OnStatus<UserType>;
|
|
6
8
|
};
|
|
7
|
-
export declare const userStatus: <UserType>({ statusRoute, onStatus }: StatusProps<UserType>) => Elysia<"", {
|
|
9
|
+
export declare const userStatus: <UserType>({ authSessionStore, statusRoute, onStatus }: StatusProps<UserType>) => Elysia<"", {
|
|
8
10
|
decorator: {};
|
|
9
11
|
store: {
|
|
10
12
|
session: import("./types").SessionRecord<UserType>;
|
package/dist/src/utils.d.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
|
+
import { OAuth2Client, OAuth2TokenResponse, ProviderOption } from 'citra';
|
|
1
2
|
import { Cookie } from 'elysia';
|
|
2
|
-
import { AbsoluteAuthProps, InsantiateUserSessionProps, OAuth2ConfigurationOptions, SessionRecord, UnregisteredSessionRecord, UserSessionId } from './types';
|
|
3
|
-
export declare const
|
|
3
|
+
import { AbsoluteAuthProps, InsantiateUserSessionProps, OAuth2ConfigurationOptions, ResolvedOAuthAuthorization, SessionRecord, UnregisteredSessionRecord, UserSessionId } from './types';
|
|
4
|
+
export declare const resolveOAuthTokenExpiresAt: (tokenResponse: OAuth2TokenResponse, now?: number) => number | undefined;
|
|
5
|
+
export declare const resolveOAuthAuthorization: ({ authProvider, providerInstance, tokenResponse, now }: {
|
|
6
|
+
authProvider: ProviderOption;
|
|
7
|
+
providerInstance: OAuth2Client<ProviderOption>;
|
|
8
|
+
tokenResponse: OAuth2TokenResponse;
|
|
9
|
+
now?: number;
|
|
10
|
+
}) => Promise<ResolvedOAuthAuthorization>;
|
|
11
|
+
export declare const instantiateUserSession: <UserType>({ authProvider, session, user_session_id, unregisteredSession, tokenResponse, providerInstance, getUser, onNewUser, resolvedAuthorization, sessionDurationMs, unregisteredSessionDurationMs }: InsantiateUserSessionProps<UserType>) => Promise<import("./types").StatusReturn | Response | undefined>;
|
|
4
12
|
export declare const createAuthConfiguration: <UserType>(configuration: AbsoluteAuthProps<UserType>) => AbsoluteAuthProps<UserType>;
|
|
5
13
|
export declare const createProvidersConfiguration: (providersConfiguration: OAuth2ConfigurationOptions) => OAuth2ConfigurationOptions;
|
|
6
14
|
export declare const getStatus: <UserType>(session: SessionRecord<UserType>, user_session_id: Cookie<UserSessionId | undefined>) => Promise<{
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.22.
|
|
2
|
+
"version": "0.22.5",
|
|
3
3
|
"name": "@absolutejs/auth",
|
|
4
4
|
"description": "An authorization library for absolutejs",
|
|
5
5
|
"repository": {
|
|
@@ -33,21 +33,22 @@
|
|
|
33
33
|
"elysia": ">= 1.4.26"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"
|
|
36
|
+
"@absolutejs/linked-providers": "0.0.2",
|
|
37
|
+
"citra": "0.25.11",
|
|
38
|
+
"@neondatabase/serverless": "1.0.0",
|
|
39
|
+
"drizzle-orm": "0.41.0"
|
|
37
40
|
},
|
|
38
41
|
"devDependencies": {
|
|
39
42
|
"@absolutejs/absolute": "0.12.3",
|
|
40
43
|
"@tanstack/react-query": "5.79.0",
|
|
41
44
|
"@elysiajs/eden": "1.2.0",
|
|
42
45
|
"@elysiajs/static": "1.2.0",
|
|
43
|
-
"@neondatabase/serverless": "1.0.0",
|
|
44
46
|
"@react-spring/web": "10.0.0-beta.0",
|
|
45
47
|
"@stylistic/eslint-plugin-ts": "4.2.0",
|
|
46
48
|
"@types/bun": "1.2.9",
|
|
47
49
|
"@types/react": "19.1.1",
|
|
48
50
|
"@types/react-dom": "19.1.2",
|
|
49
51
|
"drizzle-kit": "0.30.6",
|
|
50
|
-
"drizzle-orm": "0.41.0",
|
|
51
52
|
"elysia": "1.4.26",
|
|
52
53
|
"eslint": "9.26.0",
|
|
53
54
|
"eslint-plugin-absolute": "0.0.3",
|
|
@@ -65,5 +66,11 @@
|
|
|
65
66
|
"typescript": "5.8.3",
|
|
66
67
|
"typescript-eslint": "8.32.0"
|
|
67
68
|
},
|
|
68
|
-
"module": "dist/index.js"
|
|
69
|
+
"module": "dist/index.js",
|
|
70
|
+
"exports": {
|
|
71
|
+
".": {
|
|
72
|
+
"types": "./dist/src/index.d.ts",
|
|
73
|
+
"default": "./dist/index.js"
|
|
74
|
+
}
|
|
75
|
+
}
|
|
69
76
|
}
|