@bananacool467/authtics 1.0.1 → 1.0.11
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/components.d.ts +7 -0
- package/dist/components.js +77 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +70 -1
- package/package.json +11 -3
- package/.replit +0 -29
- package/.upm/store.json +0 -1
- package/generated-icon.png +0 -0
- package/index.ts +0 -60
- package/tsconfig.json +0 -11
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.AuthGateway = void 0;
|
|
46
|
+
const react_1 = __importStar(require("react"));
|
|
47
|
+
const AuthGateway = (_a) => __awaiter(void 0, [_a], void 0, function* ({ redirectAfterLogin, redirectAfterNotLoggedIn }) {
|
|
48
|
+
const [account, setAccount] = (0, react_1.useState)({});
|
|
49
|
+
(0, react_1.useEffect)(() => {
|
|
50
|
+
const getAccount = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
51
|
+
const a = yield fetch('/api/authtics-integration/get-account', {
|
|
52
|
+
method: 'POST',
|
|
53
|
+
headers: {
|
|
54
|
+
"Content-Type": "application/json"
|
|
55
|
+
},
|
|
56
|
+
body: JSON.stringify({})
|
|
57
|
+
});
|
|
58
|
+
if (a.status != 200) {
|
|
59
|
+
const r = yield fetch('/api/authtics-integration/login', {
|
|
60
|
+
method: 'POST',
|
|
61
|
+
headers: {
|
|
62
|
+
"Content-Type": "application/json"
|
|
63
|
+
},
|
|
64
|
+
body: JSON.stringify({ search: window.location.search })
|
|
65
|
+
});
|
|
66
|
+
const json = yield r.json();
|
|
67
|
+
window.location.href = json.redirect;
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
setAccount(yield a.json());
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
getAccount();
|
|
74
|
+
}, []);
|
|
75
|
+
return (react_1.default.createElement(react_1.default.Fragment, null));
|
|
76
|
+
});
|
|
77
|
+
exports.AuthGateway = AuthGateway;
|
package/dist/index.d.ts
CHANGED
|
@@ -8,3 +8,7 @@
|
|
|
8
8
|
* The IP is required to lock all sessions for security reasons.
|
|
9
9
|
*/
|
|
10
10
|
export declare const getAccount: (accessToken: string, clientId: string, clientSecret: string, userIp: string) => Promise<any>;
|
|
11
|
+
export declare const authtics: {
|
|
12
|
+
useAccount: () => Promise<{}[]>;
|
|
13
|
+
use: (clientId: string, clientSecret: string, flow: boolean) => any[];
|
|
14
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -14,8 +14,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
14
14
|
});
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.getAccount = void 0;
|
|
17
|
+
exports.authtics = exports.getAccount = void 0;
|
|
18
18
|
const child_process_1 = require("child_process");
|
|
19
|
+
const cookieParser = require("cookie-parser");
|
|
19
20
|
const __runCurl__ = (url_1, ...args_1) => __awaiter(void 0, [url_1, ...args_1], void 0, function* (url, headers = []) {
|
|
20
21
|
var outp;
|
|
21
22
|
var oute;
|
|
@@ -43,6 +44,74 @@ const getAccount = (accessToken, clientId, clientSecret, userIp) => __awaiter(vo
|
|
|
43
44
|
return (yield JSON.parse(output)) || error;
|
|
44
45
|
});
|
|
45
46
|
exports.getAccount = getAccount;
|
|
47
|
+
exports.authtics = {
|
|
48
|
+
useAccount: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
49
|
+
var account = {};
|
|
50
|
+
const a = yield fetch('/api/authtics-integration/get-account', {
|
|
51
|
+
method: 'POST',
|
|
52
|
+
headers: {
|
|
53
|
+
"Content-Type": "application/json"
|
|
54
|
+
},
|
|
55
|
+
body: JSON.stringify({})
|
|
56
|
+
});
|
|
57
|
+
if (a.status != 200) {
|
|
58
|
+
account = {};
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
account = yield a.json();
|
|
62
|
+
}
|
|
63
|
+
const carriedInfo = {};
|
|
64
|
+
const login = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
65
|
+
window.location.href = "/api/authtics-integration/login?r=" + (window.location.pathname + (window.location.search.replace("&", "%26")));
|
|
66
|
+
});
|
|
67
|
+
const logout = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
68
|
+
window.location.href = "/api/authtics-integration/logout?r=" + (window.location.pathname + (window.location.search.replace("&", "%26")));
|
|
69
|
+
});
|
|
70
|
+
const sendRequest = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
71
|
+
});
|
|
72
|
+
return [account, login, logout, sendRequest, carriedInfo];
|
|
73
|
+
}),
|
|
74
|
+
use: (clientId, clientSecret, flow) => {
|
|
75
|
+
return [
|
|
76
|
+
cookieParser(),
|
|
77
|
+
(req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
78
|
+
var _a;
|
|
79
|
+
if (req.path != '/api/authtics-integration/get-account') {
|
|
80
|
+
const userIp = req.ip;
|
|
81
|
+
const token = req.query.accessToken;
|
|
82
|
+
const cookie = (_a = req.cookies) === null || _a === void 0 ? void 0 : _a.AUTHTICS_ACCOUNT_ACCESS_TOKEN;
|
|
83
|
+
if (token) {
|
|
84
|
+
res.cookie('AUTHTICS_ACCOUNT_ACCESS_TOKEN', token, {
|
|
85
|
+
httpOnly: true,
|
|
86
|
+
secure: true,
|
|
87
|
+
sameSite: 'Lax',
|
|
88
|
+
maxAge: 24 * 60 * 60 * 1000
|
|
89
|
+
});
|
|
90
|
+
const remainingQueries = Object.assign({}, req.query);
|
|
91
|
+
delete remainingQueries.access_token;
|
|
92
|
+
return res.redirect(req.path);
|
|
93
|
+
}
|
|
94
|
+
req.authtics_token = cookie;
|
|
95
|
+
next();
|
|
96
|
+
}
|
|
97
|
+
else if (req.path == '/api/authtics-integration/get-account') {
|
|
98
|
+
const token = req.authtics_token;
|
|
99
|
+
const userIp = req.ip;
|
|
100
|
+
if (!token)
|
|
101
|
+
return res.status(401).json({ error: 'No session found.', redirect: true });
|
|
102
|
+
const [account, error] = yield __runCurl__("https://eb29e77b-9bd2-4e3b-9469-81d3af2a8fbe-00-1ag45w1mgbsv1.picard.replit.dev/api/authtics/me", [{ k: "Authorization", v: token }, { k: "x-client-id", v: clientId }, { k: "x-client-secret", v: clientSecret }, { k: "Content-Type", v: "application/json" }]);
|
|
103
|
+
const extracted = yield JSON.parse(account);
|
|
104
|
+
if (extracted.error)
|
|
105
|
+
return res.status(404).json({ error: extracted.error, redirect: true });
|
|
106
|
+
if (extracted.message)
|
|
107
|
+
return res.status(404).json({ message: extracted.message, redirect: true });
|
|
108
|
+
res.status(200).json({ account, success: true });
|
|
109
|
+
next();
|
|
110
|
+
}
|
|
111
|
+
})
|
|
112
|
+
];
|
|
113
|
+
}
|
|
114
|
+
};
|
|
46
115
|
/*(async () => {
|
|
47
116
|
var [output, error] = await __runCurl__(
|
|
48
117
|
"https://eb29e77b-9bd2-4e3b-9469-81d3af2a8fbe-00-1ag45w1mgbsv1.picard.replit.dev/api/authtics/me",
|
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bananacool467/authtics",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Use Authtics (An Auth service) to add accounts to your site like Auth0!",
|
|
3
|
+
"version": "1.0.11",
|
|
4
|
+
"description": "Use Authtics (An Auth service) to add accounts to your site like Auth0! (This is currently underdevelopment. Issues are expected.)",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
7
10
|
"scripts": {
|
|
8
11
|
"build": "tsc",
|
|
9
12
|
"prepublishOnly": "npm run build"
|
|
@@ -12,9 +15,14 @@
|
|
|
12
15
|
"author": "bananacool467",
|
|
13
16
|
"license": "ISC",
|
|
14
17
|
"dependencies": {
|
|
15
|
-
"@
|
|
18
|
+
"@bananacool467/authtics": "^1.0.1",
|
|
19
|
+
"@types/node": "^22.13.11",
|
|
20
|
+
"cookie-parser": "^1.4.7",
|
|
21
|
+
"react-cookie": "^8.0.1"
|
|
16
22
|
},
|
|
17
23
|
"devDependencies": {
|
|
24
|
+
"@types/react": "^19.2.13",
|
|
25
|
+
"@types/react-dom": "^19.2.3",
|
|
18
26
|
"typescript": "^5.9.3"
|
|
19
27
|
}
|
|
20
28
|
}
|
package/.replit
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
entrypoint = "index.ts"
|
|
2
|
-
modules = ["nodejs-22"]
|
|
3
|
-
hidden = [".config", "package-lock.json"]
|
|
4
|
-
|
|
5
|
-
[gitHubImport]
|
|
6
|
-
requiredFiles = [".replit", "replit.nix", "package.json", "package-lock.json"]
|
|
7
|
-
|
|
8
|
-
[nix]
|
|
9
|
-
channel = "stable-24_11"
|
|
10
|
-
|
|
11
|
-
[deployment]
|
|
12
|
-
run = ["node", "index.js"]
|
|
13
|
-
deploymentTarget = "autoscale"
|
|
14
|
-
ignorePorts = false
|
|
15
|
-
|
|
16
|
-
[agent]
|
|
17
|
-
expertMode = true
|
|
18
|
-
|
|
19
|
-
[workflows]
|
|
20
|
-
runButton = "Run"
|
|
21
|
-
|
|
22
|
-
[[workflows.workflow]]
|
|
23
|
-
name = "Run"
|
|
24
|
-
mode = "sequential"
|
|
25
|
-
author = 38094588
|
|
26
|
-
|
|
27
|
-
[[workflows.workflow.tasks]]
|
|
28
|
-
task = "shell.exec"
|
|
29
|
-
args = "npx ts-node index.ts"
|
package/.upm/store.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":2,"languages":{"nodejs-npm":{"specfileHash":"d18cf0a26e6a6fae007898f8dce8efbf","lockfileHash":"9047b0d07f978c7218a90637e3edc20f"}}}
|
package/generated-icon.png
DELETED
|
Binary file
|
package/index.ts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Authtics - Open Source Authentication Utility
|
|
3
|
-
* Developed by bananakitssu (github.com/bananakitssu)
|
|
4
|
-
* This software is provided "as-is" for the community.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { exec } from "child_process";
|
|
8
|
-
|
|
9
|
-
interface CurlHeader {
|
|
10
|
-
k: string;
|
|
11
|
-
v: string;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
interface AuthticsUser {
|
|
15
|
-
uid: string;
|
|
16
|
-
name: string;
|
|
17
|
-
profileImage: string;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const __runCurl__ = async (url: string, headers: CurlHeader[] = []) => {
|
|
21
|
-
var outp;
|
|
22
|
-
var oute;
|
|
23
|
-
var curlReadableHeaders = headers
|
|
24
|
-
.map((h: CurlHeader) => `-H "${h.k}: ${h.v}"`)
|
|
25
|
-
.join(" ");
|
|
26
|
-
return new Promise<[String?, String?]>((r) => {
|
|
27
|
-
exec(
|
|
28
|
-
`curl -X GET "${url}" ${curlReadableHeaders}`,
|
|
29
|
-
(error, stdout, stderr) => {
|
|
30
|
-
if (error) {
|
|
31
|
-
oute = error.message;
|
|
32
|
-
r([undefined, oute]);
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
outp = stdout;
|
|
36
|
-
r([outp, undefined]);
|
|
37
|
-
},
|
|
38
|
-
);
|
|
39
|
-
});
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Gets the user based on the accessToken.
|
|
44
|
-
* The IP is required to lock all sessions for security reasons.
|
|
45
|
-
*/
|
|
46
|
-
export const getAccount = async (accessToken: string, clientId: string, clientSecret: string, userIp: string) => {
|
|
47
|
-
var [output, error] = await __runCurl__("https://eb29e77b-9bd2-4e3b-9469-81d3af2a8fbe-00-1ag45w1mgbsv1.picard.replit.dev/api/authtics/me", [{k: "Authorization", v: accessToken}, {k: "x-client-id", v: clientId}, {k: "x-client-secret", v: clientSecret}, {k: "x-user-ip", v: userIp}, {k: "Content-Type", v: "application/json"}]);
|
|
48
|
-
return (await JSON.parse(output as string)) || error;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/*(async () => {
|
|
52
|
-
var [output, error] = await __runCurl__(
|
|
53
|
-
"https://eb29e77b-9bd2-4e3b-9469-81d3af2a8fbe-00-1ag45w1mgbsv1.picard.replit.dev/api/authtics/me",
|
|
54
|
-
[
|
|
55
|
-
{ k: "Authorization", v: "5" },
|
|
56
|
-
{ k: "client_id", v: "xxx" },
|
|
57
|
-
],
|
|
58
|
-
);
|
|
59
|
-
console.log(output, error);
|
|
60
|
-
})();*/
|