@bananacool467/authtics 1.0.54 → 1.0.58

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/README.md ADDED
@@ -0,0 +1,3 @@
1
+ This package was made by bananakitssu.
2
+
3
+ Authtics and this package is currently underdevelopment. It is not recommended to be used yet.
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@
2
2
  * Authtics - Open Source Authentication Utility
3
3
  * Developed by bananakitssu (github.com/bananakitssu)
4
4
  * This software is provided "as-is" for the community.
5
+ * (Authtics and this package is currently underdevelopment.)
5
6
  */
6
7
  /**
7
8
  * Gets the user based on the accessToken.
@@ -9,6 +10,6 @@
9
10
  */
10
11
  export declare const getAccount: (accessToken: string, clientId: string, clientSecret: string, userIp: string) => Promise<any>;
11
12
  export declare const authtics: {
12
- useAccount: () => any[];
13
+ useAccount: () => Object[];
13
14
  use: (clientId: string, clientSecret: string, flow: boolean) => any[];
14
15
  };
package/dist/index.js CHANGED
@@ -3,6 +3,7 @@
3
3
  * Authtics - Open Source Authentication Utility
4
4
  * Developed by bananakitssu (github.com/bananakitssu)
5
5
  * This software is provided "as-is" for the community.
6
+ * (Authtics and this package is currently underdevelopment.)
6
7
  */
7
8
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
8
9
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
@@ -47,8 +48,28 @@ const getAccount = (accessToken, clientId, clientSecret, userIp) => __awaiter(vo
47
48
  exports.getAccount = getAccount;
48
49
  exports.authtics = {
49
50
  useAccount: () => {
51
+ const searchParams = new URLSearchParams(window.location.search);
50
52
  const [account, setAccount] = react.useState({});
53
+ const [authorized, setAuthorized] = react.useState(false);
51
54
  react.useEffect(() => {
55
+ const handleCode = () => __awaiter(void 0, void 0, void 0, function* () {
56
+ if (searchParams.get('code')) {
57
+ const code = yield fetch('/api/authtics-integration/code-exchanger', {
58
+ method: 'POST',
59
+ headers: {
60
+ "Content-Type": "application/json"
61
+ },
62
+ body: JSON.stringify({ code: searchParams.get('code') })
63
+ });
64
+ if (code.status != 200) {
65
+ }
66
+ else {
67
+ const json = yield code.json();
68
+ const newLink = window.location.href.replace('?code=' + searchParams.get('code'), '?access_token=' + json.accessToken).replace('&code=' + searchParams.get('code'), '&access_token=' + json.accessToken);
69
+ window.location.href = newLink;
70
+ }
71
+ }
72
+ });
52
73
  const getAccount = () => __awaiter(void 0, void 0, void 0, function* () {
53
74
  const a = yield fetch('/api/authtics-integration/get-account', {
54
75
  method: 'POST',
@@ -59,12 +80,15 @@ exports.authtics = {
59
80
  });
60
81
  if (a.status != 200) {
61
82
  setAccount({});
83
+ setAuthorized(false);
62
84
  }
63
85
  else {
64
86
  setAccount(yield a.json());
87
+ setAuthorized(true);
65
88
  }
66
89
  });
67
90
  getAccount();
91
+ handleCode();
68
92
  }, []);
69
93
  const carriedInfo = {
70
94
  action: null,
@@ -80,14 +104,14 @@ exports.authtics = {
80
104
  });
81
105
  const sendRequest = () => __awaiter(void 0, void 0, void 0, function* () {
82
106
  });
83
- return [account, login, logout, sendRequest, carriedInfo];
107
+ return [account, authorized, login, logout, sendRequest, carriedInfo];
84
108
  },
85
109
  use: (clientId, clientSecret, flow) => {
86
110
  return [
87
111
  cookieParser(),
88
112
  (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
89
113
  var _a;
90
- if (req.path != '/api/authtics-integration/get-account' && req.path != '/api/authtics-integration/login' && req.path != '/api/authtics-integration/logout') {
114
+ 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
115
  const userIp = req.ip;
92
116
  const token = req.query.accessToken;
93
117
  const cookie = (_a = req.cookies) === null || _a === void 0 ? void 0 : _a.AUTHTICS_ACCOUNT_ACCESS_TOKEN;
@@ -110,8 +134,10 @@ exports.authtics = {
110
134
  const userIp = req.ip;
111
135
  if (!token)
112
136
  return res.status(401).json({ error: 'No session found.', redirect: true });
113
- 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" }]);
137
+ 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: "x-user-ip", v: userIp }, { k: "Content-Type", v: "application/json" }]);
114
138
  const extracted = yield JSON.parse(account);
139
+ if (error)
140
+ return res.status(404).text(error);
115
141
  if (extracted.error)
116
142
  return res.status(404).json({ error: extracted.error, redirect: true });
117
143
  if (extracted.message)
@@ -143,6 +169,24 @@ exports.authtics = {
143
169
  res.status(200).json({ redirect: redirect });
144
170
  next();
145
171
  }
172
+ else if (req.path == '/api/authtics-integration/code-exchanger') {
173
+ const codeExchanged = yield fetch('https://eb29e77b-9bd2-4e3b-9469-81d3af2a8fbe-00-1ag45w1mgbsv1.picard.replit.dev/api/authtics/code-exchange', {
174
+ method: 'POST',
175
+ headers: {
176
+ "Content-Type": "application/json"
177
+ },
178
+ body: JSON.stringify({
179
+ code: req.body.code,
180
+ clientId: clientId
181
+ })
182
+ });
183
+ if (codeExchanged.status != 200) {
184
+ res.status(codeExchanged.status).json(yield codeExchanged.json());
185
+ }
186
+ else {
187
+ res.status(200).json({ accessToken: (yield codeExchanged.json()).accessToken });
188
+ }
189
+ }
146
190
  })
147
191
  ];
148
192
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bananacool467/authtics",
3
- "version": "1.0.54",
3
+ "version": "1.0.58",
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",