@bananacool467/authtics 1.0.52 → 1.0.56
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 +48 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -47,8 +47,28 @@ const getAccount = (accessToken, clientId, clientSecret, userIp) => __awaiter(vo
|
|
|
47
47
|
exports.getAccount = getAccount;
|
|
48
48
|
exports.authtics = {
|
|
49
49
|
useAccount: () => {
|
|
50
|
+
const searchParams = new URLSearchParams(window.location.search);
|
|
50
51
|
const [account, setAccount] = react.useState({});
|
|
52
|
+
const [authorized, setAuthorized] = react.useState(false);
|
|
51
53
|
react.useEffect(() => {
|
|
54
|
+
const handleCode = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
55
|
+
if (searchParams.get('code')) {
|
|
56
|
+
const code = yield fetch('/api/authtics-integration/code-exchanger', {
|
|
57
|
+
method: 'POST',
|
|
58
|
+
headers: {
|
|
59
|
+
"Content-Type": "application/json"
|
|
60
|
+
},
|
|
61
|
+
body: JSON.stringify({ code: searchParams.get('code') })
|
|
62
|
+
});
|
|
63
|
+
if (code.status != 200) {
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
const json = yield code.json();
|
|
67
|
+
const newLink = window.location.href.replace('?code=' + searchParams.get('code'), json.accessToken).replace('&code=' + searchParams.get('code'), '&access_token=' + json.accessToken);
|
|
68
|
+
window.location.href = newLink;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
});
|
|
52
72
|
const getAccount = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
53
73
|
const a = yield fetch('/api/authtics-integration/get-account', {
|
|
54
74
|
method: 'POST',
|
|
@@ -59,12 +79,15 @@ exports.authtics = {
|
|
|
59
79
|
});
|
|
60
80
|
if (a.status != 200) {
|
|
61
81
|
setAccount({});
|
|
82
|
+
setAuthorized(false);
|
|
62
83
|
}
|
|
63
84
|
else {
|
|
64
85
|
setAccount(yield a.json());
|
|
86
|
+
setAuthorized(true);
|
|
65
87
|
}
|
|
66
88
|
});
|
|
67
89
|
getAccount();
|
|
90
|
+
handleCode();
|
|
68
91
|
}, []);
|
|
69
92
|
const carriedInfo = {
|
|
70
93
|
action: null,
|
|
@@ -87,7 +110,7 @@ exports.authtics = {
|
|
|
87
110
|
cookieParser(),
|
|
88
111
|
(req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
89
112
|
var _a;
|
|
90
|
-
if (req.path != '/api/authtics-integration/get-account' && req.path != '/api/authtics-integration/login' && req.path != '/api/authtics-integration/logout') {
|
|
113
|
+
if (req.path != '/api/authtics-integration/get-account' && req.path != '/api/authtics-integration/login' && req.path != '/api/authtics-integration/logout' && req.path != '/api/authtics-integration/code-exchanger') {
|
|
91
114
|
const userIp = req.ip;
|
|
92
115
|
const token = req.query.accessToken;
|
|
93
116
|
const cookie = (_a = req.cookies) === null || _a === void 0 ? void 0 : _a.AUTHTICS_ACCOUNT_ACCESS_TOKEN;
|
|
@@ -124,7 +147,12 @@ exports.authtics = {
|
|
|
124
147
|
if (req.body && req.body.search) {
|
|
125
148
|
search = req.body.search;
|
|
126
149
|
}
|
|
127
|
-
|
|
150
|
+
if (search && search.replace) {
|
|
151
|
+
res.status(200).json({ redirect: ("https://eb29e77b-9bd2-4e3b-9469-81d3af2a8fbe-00-1ag45w1mgbsv1.picard.replit.dev/login?client_id=" + clientId + "&redirect=" + (((search != null) && search.replace) ? search.replace("&", "%26") : req.query.r)) });
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
res.redirect("https://eb29e77b-9bd2-4e3b-9469-81d3af2a8fbe-00-1ag45w1mgbsv1.picard.replit.dev/login?client_id=" + clientId + "&redirect=" + req.query.r);
|
|
155
|
+
}
|
|
128
156
|
next();
|
|
129
157
|
}
|
|
130
158
|
else if (req.path == '/api/authtics-integration/logout') {
|
|
@@ -138,6 +166,24 @@ exports.authtics = {
|
|
|
138
166
|
res.status(200).json({ redirect: redirect });
|
|
139
167
|
next();
|
|
140
168
|
}
|
|
169
|
+
else if (req.path == '/api/authtics-integration/code-exchanger') {
|
|
170
|
+
const codeExchanged = yield fetch('https://eb29e77b-9bd2-4e3b-9469-81d3af2a8fbe-00-1ag45w1mgbsv1.picard.replit.dev/api/authtics/code-exchange', {
|
|
171
|
+
method: 'POST',
|
|
172
|
+
headers: {
|
|
173
|
+
"Content-Type": "application/json"
|
|
174
|
+
},
|
|
175
|
+
body: JSON.stringify({
|
|
176
|
+
code: req.body.code,
|
|
177
|
+
clientId: clientId
|
|
178
|
+
})
|
|
179
|
+
});
|
|
180
|
+
if (codeExchanged.status != 200) {
|
|
181
|
+
res.status(codeExchanged.status).json(yield codeExchanged.json());
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
res.status(200).json({ accessToken: (yield codeExchanged.json()).accessToken });
|
|
185
|
+
}
|
|
186
|
+
}
|
|
141
187
|
})
|
|
142
188
|
];
|
|
143
189
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bananacool467/authtics",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.56",
|
|
4
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",
|