@bananacool467/authtics 1.0.1 → 1.0.23

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.
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ interface AuthProps {
3
+ redirectAfterLogin: string;
4
+ redirectAfterNotLoggedIn: string;
5
+ }
6
+ export declare const AuthGateway: ({ redirectAfterLogin, redirectAfterNotLoggedIn }: AuthProps) => Promise<React.JSX.Element>;
7
+ export {};
@@ -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,95 @@ 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
+ action: null,
65
+ failed: false,
66
+ status: null,
67
+ error: null
68
+ };
69
+ const login = () => __awaiter(void 0, void 0, void 0, function* () {
70
+ window.location.href = "/api/authtics-integration/login?r=" + (window.location.pathname + (window.location.search.replace("&", "%26")));
71
+ });
72
+ const logout = () => __awaiter(void 0, void 0, void 0, function* () {
73
+ window.location.href = "/api/authtics-integration/logout?r=" + (window.location.pathname + (window.location.search.replace("&", "%26")));
74
+ });
75
+ const sendRequest = () => __awaiter(void 0, void 0, void 0, function* () {
76
+ });
77
+ return [account, login, logout, sendRequest, carriedInfo];
78
+ }),
79
+ use: (clientId, clientSecret, flow) => {
80
+ return [
81
+ cookieParser(),
82
+ (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
83
+ var _a;
84
+ if (req.path != '/api/authtics-integration/get-account' && req.path != '/api/authtics-integration/login' && req.path != '/api/authtics-integration/logout') {
85
+ const userIp = req.ip;
86
+ const token = req.query.accessToken;
87
+ const cookie = (_a = req.cookies) === null || _a === void 0 ? void 0 : _a.AUTHTICS_ACCOUNT_ACCESS_TOKEN;
88
+ if (token) {
89
+ res.cookie('AUTHTICS_ACCOUNT_ACCESS_TOKEN', token, {
90
+ httpOnly: true,
91
+ secure: true,
92
+ sameSite: 'Lax',
93
+ maxAge: 24 * 60 * 60 * 1000
94
+ });
95
+ const remainingQueries = Object.assign({}, req.query);
96
+ delete remainingQueries.access_token;
97
+ return res.redirect(req.path);
98
+ }
99
+ req.authtics_token = cookie;
100
+ next();
101
+ }
102
+ else if (req.path == '/api/authtics-integration/get-account') {
103
+ const token = req.authtics_token;
104
+ const userIp = req.ip;
105
+ if (!token)
106
+ return res.status(401).json({ error: 'No session found.', redirect: true });
107
+ 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" }]);
108
+ const extracted = yield JSON.parse(account);
109
+ if (extracted.error)
110
+ return res.status(404).json({ error: extracted.error, redirect: true });
111
+ if (extracted.message)
112
+ return res.status(404).json({ message: extracted.message, redirect: true });
113
+ res.status(200).json({ account, success: true });
114
+ next();
115
+ }
116
+ else if (req.path == '/api/authtics-integration/login') {
117
+ const { search } = req.body;
118
+ res.status(200).json({ redirect: ("https://eb29e77b-9bd2-4e3b-9469-81d3af2a8fbe-00-1ag45w1mgbsv1.picard.replit.dev/login?client_id=" + clientId + "&redirect=" + (search.replace("&", "%26"))) });
119
+ next();
120
+ }
121
+ else if (req.path == '/api/authtics-integration/logout') {
122
+ const redirect = req.query.r;
123
+ res.clearCookie('AUTHTICS_ACCOUNT_ACCESS_TOKEN', {
124
+ path: '/',
125
+ secure: true,
126
+ sameSite: 'Lax'
127
+ });
128
+ req.authtics_token = null;
129
+ res.status(200).json({ redirect: redirect });
130
+ next();
131
+ }
132
+ })
133
+ ];
134
+ }
135
+ };
46
136
  /*(async () => {
47
137
  var [output, error] = await __runCurl__(
48
138
  "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.1",
4
- "description": "Use Authtics (An Auth service) to add accounts to your site like Auth0!",
3
+ "version": "1.0.23",
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
- "@types/node": "^22.13.11"
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"}}}
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
- })();*/
package/tsconfig.json DELETED
@@ -1,11 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES6",
4
- "module": "CommonJS",
5
- "declaration": true,
6
- "outDir": "./dist",
7
- "strict": true,
8
- "esModuleInterop": true
9
- },
10
- "include": ["index.ts"]
11
- }