@absolutejs/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/LICENSE +24 -0
- package/README.md +62 -0
- package/dist/authorize.d.ts +57 -0
- package/dist/callback.d.ts +49 -0
- package/dist/index.d.ts +138 -0
- package/dist/index.js +322 -0
- package/dist/logout.d.ts +43 -0
- package/dist/protectRoute.d.ts +27 -0
- package/dist/providers.d.ts +56 -0
- package/dist/refresh.d.ts +44 -0
- package/dist/revoke.d.ts +46 -0
- package/dist/sessionStore.d.ts +26 -0
- package/dist/status.d.ts +44 -0
- package/dist/typeGuards.d.ts +13 -0
- package/dist/types.d.ts +50 -0
- package/package.json +53 -0
package/dist/logout.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import Elysia from 'elysia';
|
|
2
|
+
import type { OAuthEventHandler } from './types';
|
|
3
|
+
type LogoutProps = {
|
|
4
|
+
logoutRoute?: string;
|
|
5
|
+
onLogout?: OAuthEventHandler;
|
|
6
|
+
};
|
|
7
|
+
export declare const logout: ({ logoutRoute, onLogout }: LogoutProps) => Elysia<"", {
|
|
8
|
+
decorator: {};
|
|
9
|
+
store: {};
|
|
10
|
+
derive: {};
|
|
11
|
+
resolve: {};
|
|
12
|
+
}, {
|
|
13
|
+
typebox: import("@sinclair/typebox").TModule<{}>;
|
|
14
|
+
error: {};
|
|
15
|
+
}, {
|
|
16
|
+
schema: {};
|
|
17
|
+
macro: {};
|
|
18
|
+
macroFn: {};
|
|
19
|
+
parser: {};
|
|
20
|
+
}, {
|
|
21
|
+
[x: string]: {
|
|
22
|
+
post: {
|
|
23
|
+
body: unknown;
|
|
24
|
+
params: {};
|
|
25
|
+
query: unknown;
|
|
26
|
+
headers: unknown;
|
|
27
|
+
response: {
|
|
28
|
+
200: import("undici-types").Response;
|
|
29
|
+
500: "Internal Server Error";
|
|
30
|
+
401: "No auth provider found";
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
}, {
|
|
35
|
+
derive: {};
|
|
36
|
+
resolve: {};
|
|
37
|
+
schema: {};
|
|
38
|
+
}, {
|
|
39
|
+
derive: {};
|
|
40
|
+
resolve: {};
|
|
41
|
+
schema: {};
|
|
42
|
+
}>;
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import Elysia from 'elysia';
|
|
2
|
+
export declare const protectRoute: <UserType>() => Elysia<"", {
|
|
3
|
+
decorator: {};
|
|
4
|
+
store: {
|
|
5
|
+
session: import("./types").SessionRecord<UserType_1>;
|
|
6
|
+
};
|
|
7
|
+
derive: {};
|
|
8
|
+
resolve: {};
|
|
9
|
+
}, {
|
|
10
|
+
error: {};
|
|
11
|
+
typebox: import("elysia/dist/types").MergeTypeModule<import("@sinclair/typebox").TModule<{}, {}>, import("@sinclair/typebox").TModule<{}, {}>>;
|
|
12
|
+
}, {
|
|
13
|
+
schema: {};
|
|
14
|
+
macro: {};
|
|
15
|
+
macroFn: {};
|
|
16
|
+
parser: {};
|
|
17
|
+
}, {}, {
|
|
18
|
+
derive: {
|
|
19
|
+
readonly protectRoute: (onAuth: () => Promise<Response>, onAuthFail?: () => Promise<Response>) => Promise<Response | import("elysia/dist/error").ElysiaCustomStatusResponse<401, "No session ID found", 401> | import("elysia/dist/error").ElysiaCustomStatusResponse<401, "No session found", 401>>;
|
|
20
|
+
};
|
|
21
|
+
resolve: {};
|
|
22
|
+
schema: import("elysia").MergeSchema<{}, {}, "">;
|
|
23
|
+
}, {
|
|
24
|
+
derive: {};
|
|
25
|
+
resolve: {};
|
|
26
|
+
schema: {};
|
|
27
|
+
}>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { AmazonCognito, AniList, Apple, Atlassian, Auth0, Authentik, Bitbucket, Box, Coinbase, Discord, Dribbble, Dropbox, Facebook, Figma, Intuit, GitHub, GitLab, Google, Kakao, KeyCloak, Lichess, Line, Linear, LinkedIn, MicrosoftEntraId, MyAnimeList, Notion, Okta, Osu, Patreon, Reddit, Roblox, Salesforce, Shikimori, Slack, Spotify, Strava, Tiltify, Tumblr, Twitch, Twitter, VK, WorkOS, Yahoo, Yandex, Zoom, FortyTwo } from 'arctic';
|
|
2
|
+
export type ProvidersMap = {
|
|
3
|
+
AmazonCognito: typeof AmazonCognito;
|
|
4
|
+
AniList: typeof AniList;
|
|
5
|
+
Apple: typeof Apple;
|
|
6
|
+
Atlassian: typeof Atlassian;
|
|
7
|
+
Auth0: typeof Auth0;
|
|
8
|
+
Authentik: typeof Authentik;
|
|
9
|
+
Bitbucket: typeof Bitbucket;
|
|
10
|
+
Box: typeof Box;
|
|
11
|
+
Coinbase: typeof Coinbase;
|
|
12
|
+
Discord: typeof Discord;
|
|
13
|
+
Dribbble: typeof Dribbble;
|
|
14
|
+
Dropbox: typeof Dropbox;
|
|
15
|
+
Facebook: typeof Facebook;
|
|
16
|
+
Figma: typeof Figma;
|
|
17
|
+
FortyTwo: typeof FortyTwo;
|
|
18
|
+
GitHub: typeof GitHub;
|
|
19
|
+
GitLab: typeof GitLab;
|
|
20
|
+
Google: typeof Google;
|
|
21
|
+
Intuit: typeof Intuit;
|
|
22
|
+
Kakao: typeof Kakao;
|
|
23
|
+
KeyCloak: typeof KeyCloak;
|
|
24
|
+
Lichess: typeof Lichess;
|
|
25
|
+
Line: typeof Line;
|
|
26
|
+
Linear: typeof Linear;
|
|
27
|
+
LinkedIn: typeof LinkedIn;
|
|
28
|
+
MicrosoftEntraId: typeof MicrosoftEntraId;
|
|
29
|
+
MyAnimeList: typeof MyAnimeList;
|
|
30
|
+
Notion: typeof Notion;
|
|
31
|
+
Okta: typeof Okta;
|
|
32
|
+
Osu: typeof Osu;
|
|
33
|
+
Patreon: typeof Patreon;
|
|
34
|
+
Reddit: typeof Reddit;
|
|
35
|
+
Roblox: typeof Roblox;
|
|
36
|
+
Salesforce: typeof Salesforce;
|
|
37
|
+
Shikimori: typeof Shikimori;
|
|
38
|
+
Slack: typeof Slack;
|
|
39
|
+
Spotify: typeof Spotify;
|
|
40
|
+
Strava: typeof Strava;
|
|
41
|
+
Tiltify: typeof Tiltify;
|
|
42
|
+
Tumblr: typeof Tumblr;
|
|
43
|
+
Twitch: typeof Twitch;
|
|
44
|
+
Twitter: typeof Twitter;
|
|
45
|
+
VK: typeof VK;
|
|
46
|
+
WorkOS: typeof WorkOS;
|
|
47
|
+
Yahoo: typeof Yahoo;
|
|
48
|
+
Yandex: typeof Yandex;
|
|
49
|
+
Zoom: typeof Zoom;
|
|
50
|
+
};
|
|
51
|
+
export declare const providers: ProvidersMap;
|
|
52
|
+
export declare const normalizedProviderKeys: Record<string, string>;
|
|
53
|
+
export declare const userInfoURLs: Record<string, string>;
|
|
54
|
+
export declare const issuerURLs: Record<string, string>;
|
|
55
|
+
export declare const normalizedUserInfoURLKeys: Record<string, string>;
|
|
56
|
+
export declare const normalizedIssuerURLKeys: Record<string, string>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import Elysia from 'elysia';
|
|
2
|
+
import type { ClientProviders, OAuthEventHandler } from './types';
|
|
3
|
+
type RefreshProps = {
|
|
4
|
+
clientProviders: ClientProviders;
|
|
5
|
+
refreshRoute?: string;
|
|
6
|
+
onRefresh?: OAuthEventHandler;
|
|
7
|
+
};
|
|
8
|
+
export declare const refresh: ({ clientProviders, refreshRoute, onRefresh }: RefreshProps) => Elysia<"", {
|
|
9
|
+
decorator: {};
|
|
10
|
+
store: {};
|
|
11
|
+
derive: {};
|
|
12
|
+
resolve: {};
|
|
13
|
+
}, {
|
|
14
|
+
typebox: import("@sinclair/typebox").TModule<{}>;
|
|
15
|
+
error: {};
|
|
16
|
+
}, {
|
|
17
|
+
schema: {};
|
|
18
|
+
macro: {};
|
|
19
|
+
macroFn: {};
|
|
20
|
+
parser: {};
|
|
21
|
+
}, {
|
|
22
|
+
[x: string]: {
|
|
23
|
+
post: {
|
|
24
|
+
body: unknown;
|
|
25
|
+
params: {};
|
|
26
|
+
query: unknown;
|
|
27
|
+
headers: unknown;
|
|
28
|
+
response: {
|
|
29
|
+
200: import("undici-types").Response;
|
|
30
|
+
500: "Internal Server Error";
|
|
31
|
+
401: "No auth provider found" | "No refresh token found" | "Provider is not refreshable";
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
}, {
|
|
36
|
+
derive: {};
|
|
37
|
+
resolve: {};
|
|
38
|
+
schema: {};
|
|
39
|
+
}, {
|
|
40
|
+
derive: {};
|
|
41
|
+
resolve: {};
|
|
42
|
+
schema: {};
|
|
43
|
+
}>;
|
|
44
|
+
export {};
|
package/dist/revoke.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import Elysia from 'elysia';
|
|
2
|
+
import type { ClientProviders, OAuthEventHandler } from './types';
|
|
3
|
+
type RevokeProps = {
|
|
4
|
+
clientProviders: ClientProviders;
|
|
5
|
+
revokeRoute?: string;
|
|
6
|
+
onRevoke?: OAuthEventHandler;
|
|
7
|
+
};
|
|
8
|
+
export declare const revoke: ({ clientProviders, revokeRoute, onRevoke }: RevokeProps) => Elysia<"", {
|
|
9
|
+
decorator: {};
|
|
10
|
+
store: {};
|
|
11
|
+
derive: {};
|
|
12
|
+
resolve: {};
|
|
13
|
+
}, {
|
|
14
|
+
typebox: import("@sinclair/typebox").TModule<{}>;
|
|
15
|
+
error: {};
|
|
16
|
+
}, {
|
|
17
|
+
schema: {};
|
|
18
|
+
macro: {};
|
|
19
|
+
macroFn: {};
|
|
20
|
+
parser: {};
|
|
21
|
+
}, {
|
|
22
|
+
[x: string]: {
|
|
23
|
+
"access-token": {
|
|
24
|
+
post: {
|
|
25
|
+
body: unknown;
|
|
26
|
+
params: {};
|
|
27
|
+
query: unknown;
|
|
28
|
+
headers: unknown;
|
|
29
|
+
response: {
|
|
30
|
+
200: undefined;
|
|
31
|
+
400: "Invalid provider";
|
|
32
|
+
401: "No auth provider found" | "No refresh token found";
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
}, {
|
|
38
|
+
derive: {};
|
|
39
|
+
resolve: {};
|
|
40
|
+
schema: {};
|
|
41
|
+
}, {
|
|
42
|
+
derive: {};
|
|
43
|
+
resolve: {};
|
|
44
|
+
schema: {};
|
|
45
|
+
}>;
|
|
46
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import Elysia from 'elysia';
|
|
2
|
+
import type { SessionRecord } from './types';
|
|
3
|
+
export declare const sessionStore: <UserType>() => Elysia<"", {
|
|
4
|
+
decorator: {};
|
|
5
|
+
store: {
|
|
6
|
+
session: SessionRecord<UserType>;
|
|
7
|
+
};
|
|
8
|
+
derive: {};
|
|
9
|
+
resolve: {};
|
|
10
|
+
}, {
|
|
11
|
+
typebox: import("@sinclair/typebox").TModule<{}>;
|
|
12
|
+
error: {};
|
|
13
|
+
}, {
|
|
14
|
+
schema: {};
|
|
15
|
+
macro: {};
|
|
16
|
+
macroFn: {};
|
|
17
|
+
parser: {};
|
|
18
|
+
}, {}, {
|
|
19
|
+
derive: {};
|
|
20
|
+
resolve: {};
|
|
21
|
+
schema: {};
|
|
22
|
+
}, {
|
|
23
|
+
derive: {};
|
|
24
|
+
resolve: {};
|
|
25
|
+
schema: {};
|
|
26
|
+
}>;
|
package/dist/status.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import Elysia from 'elysia';
|
|
2
|
+
import type { OAuthEventHandler } from './types';
|
|
3
|
+
type StatusProps = {
|
|
4
|
+
statusRoute?: string;
|
|
5
|
+
onStatus?: OAuthEventHandler;
|
|
6
|
+
};
|
|
7
|
+
export declare const status: <UserType>({ statusRoute, onStatus }: StatusProps) => Elysia<"", {
|
|
8
|
+
decorator: {};
|
|
9
|
+
store: {
|
|
10
|
+
session: import("./types").SessionRecord<UserType_1>;
|
|
11
|
+
};
|
|
12
|
+
derive: {};
|
|
13
|
+
resolve: {};
|
|
14
|
+
}, {
|
|
15
|
+
error: {};
|
|
16
|
+
typebox: import("elysia/dist/types").MergeTypeModule<import("@sinclair/typebox").TModule<{}, {}>, import("@sinclair/typebox").TModule<{}, {}>>;
|
|
17
|
+
}, {
|
|
18
|
+
schema: {};
|
|
19
|
+
macro: {};
|
|
20
|
+
macroFn: {};
|
|
21
|
+
parser: {};
|
|
22
|
+
}, {
|
|
23
|
+
[x: string]: {
|
|
24
|
+
get: {
|
|
25
|
+
body: unknown;
|
|
26
|
+
params: {};
|
|
27
|
+
query: unknown;
|
|
28
|
+
headers: unknown;
|
|
29
|
+
response: {
|
|
30
|
+
200: import("undici-types").Response;
|
|
31
|
+
500: "Internal Server Error";
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
}, {
|
|
36
|
+
derive: {};
|
|
37
|
+
resolve: {};
|
|
38
|
+
schema: {};
|
|
39
|
+
}, {
|
|
40
|
+
derive: {};
|
|
41
|
+
resolve: {};
|
|
42
|
+
schema: {};
|
|
43
|
+
}>;
|
|
44
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { OAuth2Tokens } from 'arctic';
|
|
2
|
+
import { providers, userInfoURLs, issuerURLs } from './providers';
|
|
3
|
+
import type { Providers } from './types';
|
|
4
|
+
export declare const isRefreshableProvider: (provider: InstanceType<(typeof providers)[Providers]>) => provider is InstanceType<(typeof providers)[Providers]> & {
|
|
5
|
+
refreshAccessToken: () => Promise<OAuth2Tokens>;
|
|
6
|
+
};
|
|
7
|
+
export declare const isRevocableProvider: (provider: InstanceType<(typeof providers)[Providers]>) => provider is InstanceType<(typeof providers)[Providers]> & {
|
|
8
|
+
revokeAccessToken: (token: string) => Promise<void>;
|
|
9
|
+
};
|
|
10
|
+
export declare const isValidProviderKey: (provider: string) => provider is keyof typeof providers;
|
|
11
|
+
export declare const isValidUserInfoURLKey: (userInfoURLKey: string) => userInfoURLKey is keyof typeof userInfoURLs;
|
|
12
|
+
export declare const isValidIssuerURLKey: (issuerURLKey: string) => issuerURLKey is keyof typeof issuerURLs;
|
|
13
|
+
export declare const isValidUser: <UserType>(user: any) => user is UserType;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { providers } from './providers';
|
|
2
|
+
export type Providers = keyof typeof providers;
|
|
3
|
+
export type SessionData<UserType> = {
|
|
4
|
+
user: UserType;
|
|
5
|
+
expiresAt: number;
|
|
6
|
+
};
|
|
7
|
+
export type SessionRecord<UserType> = Record<string, SessionData<UserType> | undefined>;
|
|
8
|
+
export type Oauth2ConfigOptions = {
|
|
9
|
+
[K in Providers]?: {
|
|
10
|
+
credentials: ConstructorParameters<(typeof providers)[K]>;
|
|
11
|
+
scopes?: string[];
|
|
12
|
+
searchParams?: [string, string][];
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
export type OAuthEventHandler = () => void;
|
|
16
|
+
export type CreateUser<UserType> = ({ decodedIdToken, authProvider }: {
|
|
17
|
+
decodedIdToken: {
|
|
18
|
+
[key: string]: string | undefined;
|
|
19
|
+
};
|
|
20
|
+
authProvider: string;
|
|
21
|
+
}) => Promise<UserType>;
|
|
22
|
+
export type GetUser<UserType> = ({ decodedIdToken, authProvider }: {
|
|
23
|
+
decodedIdToken: {
|
|
24
|
+
[key: string]: string | undefined;
|
|
25
|
+
};
|
|
26
|
+
authProvider: string;
|
|
27
|
+
}) => Promise<UserType | null>;
|
|
28
|
+
export type AbsoluteAuthProps = {
|
|
29
|
+
config: Oauth2ConfigOptions;
|
|
30
|
+
authorizeRoute?: string;
|
|
31
|
+
callbackRoute?: string;
|
|
32
|
+
refreshRoute?: string;
|
|
33
|
+
revokeRoute?: string;
|
|
34
|
+
logoutRoute?: string;
|
|
35
|
+
statusRoute?: string;
|
|
36
|
+
onAuthorize?: OAuthEventHandler;
|
|
37
|
+
onCallback?: OAuthEventHandler;
|
|
38
|
+
onStatus?: OAuthEventHandler;
|
|
39
|
+
onRefresh?: OAuthEventHandler;
|
|
40
|
+
onLogout?: OAuthEventHandler;
|
|
41
|
+
onRevoke?: OAuthEventHandler;
|
|
42
|
+
createUser?: CreateUser<any>;
|
|
43
|
+
getUser?: GetUser<any>;
|
|
44
|
+
};
|
|
45
|
+
export type ClientProviders = Record<string, {
|
|
46
|
+
providerInstance: InstanceType<(typeof providers)[Providers]>;
|
|
47
|
+
scopes: string[];
|
|
48
|
+
searchParams: [string, string][];
|
|
49
|
+
userInfoURL?: string;
|
|
50
|
+
}>;
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "0.0.1",
|
|
3
|
+
"name": "@absolutejs/auth",
|
|
4
|
+
"description": "An authorization library for absolutejs",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/alexkahndev/absolute-auth.git"
|
|
8
|
+
},
|
|
9
|
+
"main": "dist/index.js",
|
|
10
|
+
"license": "CC BY-NC 4.0",
|
|
11
|
+
"author": "Alex Kahn",
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "bun build src/index.ts --outdir dist --minify --splitting && tsc --emitDeclarationOnly --project tsconfig.dts.json",
|
|
14
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
15
|
+
"format": "prettier --write \"./**/*.{js,jsx,ts,tsx,css,json}\"",
|
|
16
|
+
"dev": "bun run --watch example/server.ts",
|
|
17
|
+
"db:generate": "drizzle-kit generate --schema ./example/db/schema.ts --dialect postgresql",
|
|
18
|
+
"db:migrate": "bun run ./example/db/migrate.ts",
|
|
19
|
+
"db:studio": "drizzle-kit studio"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"authorization",
|
|
23
|
+
"authentication",
|
|
24
|
+
"absolutejs",
|
|
25
|
+
"elysia",
|
|
26
|
+
"oauth"
|
|
27
|
+
],
|
|
28
|
+
"types": "dist/index.d.ts",
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"arctic": "3.0.0",
|
|
31
|
+
"elysia": "1.2.9"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@elysiajs/static": "1.2.0",
|
|
35
|
+
"@neondatabase/serverless": "0.10.4",
|
|
36
|
+
"@types/bun": "1.1.14",
|
|
37
|
+
"@types/react": "19.0.2",
|
|
38
|
+
"@types/react-dom": "19.0.2",
|
|
39
|
+
"drizzle-kit": "0.28.0",
|
|
40
|
+
"drizzle-orm": "0.36.1",
|
|
41
|
+
"prettier": "3.4.2",
|
|
42
|
+
"react": "19.0.0",
|
|
43
|
+
"react-dom": "19.0.0",
|
|
44
|
+
"tsup": "8.3.5",
|
|
45
|
+
"typescript": "^5.7.2"
|
|
46
|
+
},
|
|
47
|
+
"module": "dist/index.js",
|
|
48
|
+
"files": [
|
|
49
|
+
"dist/",
|
|
50
|
+
"README.md",
|
|
51
|
+
"LICENSE"
|
|
52
|
+
]
|
|
53
|
+
}
|