@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/LICENSE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
```
|
|
2
|
+
# Creative Commons Attribution-NonCommercial 4.0 International License (CC BY-NC 4.0)
|
|
3
|
+
|
|
4
|
+
By using this project, you agree to the following terms under the Creative Commons Attribution-NonCommercial 4.0 International License.
|
|
5
|
+
|
|
6
|
+
## License Summary
|
|
7
|
+
This license allows you to:
|
|
8
|
+
- **Share**: Copy and redistribute the material in any medium or format.
|
|
9
|
+
- **Adapt**: Remix, transform, and build upon the material.
|
|
10
|
+
|
|
11
|
+
**Under the following conditions**:
|
|
12
|
+
- **Attribution**: You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
|
|
13
|
+
- **Non-Commercial**: You may not use the material for commercial purposes.
|
|
14
|
+
|
|
15
|
+
## Full License Text
|
|
16
|
+
The full license text can be found at: https://creativecommons.org/licenses/by-nc/4.0/legalcode
|
|
17
|
+
|
|
18
|
+
## Contact Information for Commercial Use
|
|
19
|
+
For commercial use, licensing inquiries, or additional permissions, please contact:
|
|
20
|
+
Alex Kahn
|
|
21
|
+
alexkahndev@gmail.com
|
|
22
|
+
alexkahndev.github.io
|
|
23
|
+
```
|
|
24
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Absolute Auth
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
Absolute Auth is a TypeScript-based authentication system that provides a comprehensive solution for handling user authentication in web applications. It supports multiple authentication providers and offers features such as authorization, callback handling, token refresh, token revocation, and session management.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
### Prerequisites
|
|
10
|
+
|
|
11
|
+
- [Elysia](https://elysiajs.com/)
|
|
12
|
+
|
|
13
|
+
### Steps to Install Dependencies
|
|
14
|
+
|
|
15
|
+
1. Clone the repository:
|
|
16
|
+
```bash
|
|
17
|
+
git clone https://github.com/alexkahndev/absolute-auth.git
|
|
18
|
+
cd absolute-auth
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
2. Install the dependencies:
|
|
22
|
+
```bash
|
|
23
|
+
bun install
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
### Running the Example Server
|
|
29
|
+
|
|
30
|
+
Start the example server:
|
|
31
|
+
```bash
|
|
32
|
+
bun dev
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
3. Open your browser and navigate to `http://localhost:3000` to test the authentication flow.
|
|
36
|
+
|
|
37
|
+
## Authentication System
|
|
38
|
+
|
|
39
|
+
### Features
|
|
40
|
+
|
|
41
|
+
- **Authorization**: Handles the authorization process by generating the authorization URL and redirecting the user to the authentication provider.
|
|
42
|
+
- **Callback Handling**: Handles the callback process by validating the authorization code, decoding the ID token, and creating or retrieving the user.
|
|
43
|
+
- **Token Refresh**: Handles the token refresh process by refreshing the access token using the refresh token.
|
|
44
|
+
- **Token Revocation**: Handles the token revocation process by revoking the access token.
|
|
45
|
+
- **Session Management**: Manages user sessions, including creating, retrieving, and removing sessions.
|
|
46
|
+
|
|
47
|
+
### Configuration Options
|
|
48
|
+
|
|
49
|
+
- **Providers**: Configure multiple authentication providers such as Google, GitHub, and more.
|
|
50
|
+
- **Routes**: Customize the routes for authorization, callback, logout, status, refresh, and revoke.
|
|
51
|
+
- **Event Handlers**: Define custom event handlers for authorization, callback, status, refresh, logout, and revoke events.
|
|
52
|
+
- **User Management**: Implement custom functions for creating and retrieving users.
|
|
53
|
+
|
|
54
|
+
### Example Components and Utilities in the `example` Directory
|
|
55
|
+
|
|
56
|
+
- `components/Example.tsx`: A React component that demonstrates the usage of the authentication system, including login, logout, and protected routes.
|
|
57
|
+
- `components/Navbar.tsx`: A React component that provides a navigation bar with authentication-related links and actions.
|
|
58
|
+
- `server.ts`: The main server file that sets up the example server, handles routes, and integrates the authentication system.
|
|
59
|
+
|
|
60
|
+
## Note
|
|
61
|
+
|
|
62
|
+
This project uses Bun and is built for Elysia.
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import Elysia from 'elysia';
|
|
2
|
+
import type { ClientProviders, OAuthEventHandler } from './types';
|
|
3
|
+
type AuthorizeProps = {
|
|
4
|
+
clientProviders: ClientProviders;
|
|
5
|
+
authorizeRoute?: string;
|
|
6
|
+
onAuthorize?: OAuthEventHandler;
|
|
7
|
+
};
|
|
8
|
+
export declare const authorize: ({ clientProviders, authorizeRoute, onAuthorize }: AuthorizeProps) => 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
|
+
":provider": {
|
|
24
|
+
get: {
|
|
25
|
+
body: unknown;
|
|
26
|
+
params: {
|
|
27
|
+
provider: string;
|
|
28
|
+
};
|
|
29
|
+
query: unknown;
|
|
30
|
+
headers: unknown;
|
|
31
|
+
response: {
|
|
32
|
+
200: import("undici-types").Response;
|
|
33
|
+
400: "Provider is required" | "Invalid provider";
|
|
34
|
+
500: "Internal Server Error";
|
|
35
|
+
422: {
|
|
36
|
+
type: "validation";
|
|
37
|
+
on: string;
|
|
38
|
+
summary?: string;
|
|
39
|
+
message?: string;
|
|
40
|
+
found?: unknown;
|
|
41
|
+
property?: string;
|
|
42
|
+
expected?: string;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
}, {
|
|
49
|
+
derive: {};
|
|
50
|
+
resolve: {};
|
|
51
|
+
schema: {};
|
|
52
|
+
}, {
|
|
53
|
+
derive: {};
|
|
54
|
+
resolve: {};
|
|
55
|
+
schema: {};
|
|
56
|
+
}>;
|
|
57
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import Elysia from 'elysia';
|
|
2
|
+
import type { ClientProviders, CreateUser, GetUser, OAuthEventHandler } from './types';
|
|
3
|
+
type CallbackProps<UserType> = {
|
|
4
|
+
clientProviders: ClientProviders;
|
|
5
|
+
callbackRoute?: string;
|
|
6
|
+
onCallback?: OAuthEventHandler;
|
|
7
|
+
getUser?: GetUser<UserType>;
|
|
8
|
+
createUser?: CreateUser<UserType>;
|
|
9
|
+
};
|
|
10
|
+
export declare const callback: <UserType>({ clientProviders, callbackRoute, onCallback, getUser, createUser }: CallbackProps<UserType>) => Elysia<"", {
|
|
11
|
+
decorator: {};
|
|
12
|
+
store: {
|
|
13
|
+
session: import("./types").SessionRecord<UserType_1>;
|
|
14
|
+
};
|
|
15
|
+
derive: {};
|
|
16
|
+
resolve: {};
|
|
17
|
+
}, {
|
|
18
|
+
error: {};
|
|
19
|
+
typebox: import("elysia/dist/types").MergeTypeModule<import("@sinclair/typebox").TModule<{}, {}>, import("@sinclair/typebox").TModule<{}, {}>>;
|
|
20
|
+
}, {
|
|
21
|
+
schema: {};
|
|
22
|
+
macro: {};
|
|
23
|
+
macroFn: {};
|
|
24
|
+
parser: {};
|
|
25
|
+
}, {
|
|
26
|
+
[x: string]: {
|
|
27
|
+
get: {
|
|
28
|
+
body: unknown;
|
|
29
|
+
params: {};
|
|
30
|
+
query: unknown;
|
|
31
|
+
headers: unknown;
|
|
32
|
+
response: {
|
|
33
|
+
200: import("undici-types").Response;
|
|
34
|
+
400: "Invalid provider" | "Invalid callback request" | "Invalid state mismatch" | "Code verifier not found and is required";
|
|
35
|
+
500: "Internal Server Error" | "Invalid user schema";
|
|
36
|
+
401: "No auth provider found";
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
}, {
|
|
41
|
+
derive: {};
|
|
42
|
+
resolve: {};
|
|
43
|
+
schema: {};
|
|
44
|
+
}, {
|
|
45
|
+
derive: {};
|
|
46
|
+
resolve: {};
|
|
47
|
+
schema: {};
|
|
48
|
+
}>;
|
|
49
|
+
export {};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import Elysia from 'elysia';
|
|
2
|
+
import { OAuth2RequestError, ArcticFetchError } from 'arctic';
|
|
3
|
+
import type { AbsoluteAuthProps } from './types';
|
|
4
|
+
export declare const absoluteAuth: <UserType>({ config, authorizeRoute, callbackRoute, logoutRoute, statusRoute, refreshRoute, revokeRoute, onAuthorize, onCallback, onStatus, onRefresh, onLogout, onRevoke, createUser, getUser }: AbsoluteAuthProps) => Elysia<"", {
|
|
5
|
+
decorator: {};
|
|
6
|
+
store: {
|
|
7
|
+
session: import("./types").SessionRecord<UserType_1>;
|
|
8
|
+
};
|
|
9
|
+
derive: {};
|
|
10
|
+
resolve: {};
|
|
11
|
+
}, {
|
|
12
|
+
error: {
|
|
13
|
+
OAUTH2_REQUEST_ERROR: OAuth2RequestError;
|
|
14
|
+
ARCTIC_FETCH_ERROR: ArcticFetchError;
|
|
15
|
+
};
|
|
16
|
+
typebox: import("elysia/dist/types").MergeTypeModule<import("elysia/dist/types").MergeTypeModule<import("elysia/dist/types").MergeTypeModule<import("elysia/dist/types").MergeTypeModule<import("elysia/dist/types").MergeTypeModule<import("elysia/dist/types").MergeTypeModule<import("elysia/dist/types").MergeTypeModule<import("@sinclair/typebox").TModule<{}, {}>, import("@sinclair/typebox").TModule<{}, {}>>, import("@sinclair/typebox").TModule<{}, {}>>, import("elysia/dist/types").MergeTypeModule<import("@sinclair/typebox").TModule<{}, {}>, import("@sinclair/typebox").TModule<{}, {}>>>, import("@sinclair/typebox").TModule<{}, {}>>, import("@sinclair/typebox").TModule<{}, {}>>, import("elysia/dist/types").MergeTypeModule<import("@sinclair/typebox").TModule<{}, {}>, import("@sinclair/typebox").TModule<{}, {}>>>, 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
|
+
post: {
|
|
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
|
+
401: "No auth provider found";
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
} & {
|
|
37
|
+
[x: string]: {
|
|
38
|
+
"access-token": {
|
|
39
|
+
post: {
|
|
40
|
+
body: unknown;
|
|
41
|
+
params: {};
|
|
42
|
+
query: unknown;
|
|
43
|
+
headers: unknown;
|
|
44
|
+
response: {
|
|
45
|
+
200: undefined;
|
|
46
|
+
400: "Invalid provider";
|
|
47
|
+
401: "No auth provider found" | "No refresh token found";
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
} & {
|
|
53
|
+
[x: string]: {
|
|
54
|
+
get: {
|
|
55
|
+
body: unknown;
|
|
56
|
+
params: {};
|
|
57
|
+
query: unknown;
|
|
58
|
+
headers: unknown;
|
|
59
|
+
response: {
|
|
60
|
+
200: import("undici-types").Response;
|
|
61
|
+
500: "Internal Server Error";
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
} & {
|
|
66
|
+
[x: string]: {
|
|
67
|
+
post: {
|
|
68
|
+
body: unknown;
|
|
69
|
+
params: {};
|
|
70
|
+
query: unknown;
|
|
71
|
+
headers: unknown;
|
|
72
|
+
response: {
|
|
73
|
+
200: import("undici-types").Response;
|
|
74
|
+
500: "Internal Server Error";
|
|
75
|
+
401: "No auth provider found" | "No refresh token found" | "Provider is not refreshable";
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
} & {
|
|
80
|
+
[x: string]: {
|
|
81
|
+
":provider": {
|
|
82
|
+
get: {
|
|
83
|
+
body: unknown;
|
|
84
|
+
params: {
|
|
85
|
+
provider: string;
|
|
86
|
+
};
|
|
87
|
+
query: unknown;
|
|
88
|
+
headers: unknown;
|
|
89
|
+
response: {
|
|
90
|
+
200: import("undici-types").Response;
|
|
91
|
+
400: "Provider is required" | "Invalid provider";
|
|
92
|
+
500: "Internal Server Error";
|
|
93
|
+
422: {
|
|
94
|
+
type: "validation";
|
|
95
|
+
on: string;
|
|
96
|
+
summary?: string;
|
|
97
|
+
message?: string;
|
|
98
|
+
found?: unknown;
|
|
99
|
+
property?: string;
|
|
100
|
+
expected?: string;
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
} & {
|
|
107
|
+
[x: string]: {
|
|
108
|
+
get: {
|
|
109
|
+
body: unknown;
|
|
110
|
+
params: {};
|
|
111
|
+
query: unknown;
|
|
112
|
+
headers: unknown;
|
|
113
|
+
response: {
|
|
114
|
+
200: import("undici-types").Response;
|
|
115
|
+
400: "Invalid provider" | "Invalid callback request" | "Invalid state mismatch" | "Code verifier not found and is required";
|
|
116
|
+
500: "Internal Server Error" | "Invalid user schema";
|
|
117
|
+
401: "No auth provider found";
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
}, {
|
|
122
|
+
derive: {
|
|
123
|
+
readonly protectRoute: (onAuth: () => Promise<Response>, onAuthFail?: (() => Promise<Response>) | undefined) => Promise<Response | import("elysia/dist/error").ElysiaCustomStatusResponse<401, "No session ID found", 401> | import("elysia/dist/error").ElysiaCustomStatusResponse<401, "No session found", 401>>;
|
|
124
|
+
};
|
|
125
|
+
resolve: {};
|
|
126
|
+
schema: import("elysia").MergeSchema<{
|
|
127
|
+
body: unknown;
|
|
128
|
+
headers: unknown;
|
|
129
|
+
query: unknown;
|
|
130
|
+
params: {};
|
|
131
|
+
cookie: unknown;
|
|
132
|
+
response: {};
|
|
133
|
+
}, {}, "">;
|
|
134
|
+
}, {
|
|
135
|
+
derive: {};
|
|
136
|
+
resolve: {};
|
|
137
|
+
schema: {};
|
|
138
|
+
}>;
|