neonctl 0.0.7 → 0.1.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neonctl",
3
- "version": "0.0.7",
3
+ "version": "0.1.0",
4
4
  "description": "CLI tool for NeonDB Cloud management",
5
5
  "main": "index.js",
6
6
  "author": "NeonDB",
@@ -27,7 +27,7 @@
27
27
  "scripts": {
28
28
  "dev": "node dev.js",
29
29
  "debug": "node --inspect-brk dev.js",
30
- "build": "tsc && cp src/*.html dist/",
30
+ "build": "npm run clean && tsc && cp src/*.html dist/src/",
31
31
  "clean": "rm -rf dist",
32
32
  "start": "node index.js",
33
33
  "publizh": "npm run build && cd dist && npm publish"
package/src/auth.js CHANGED
@@ -19,12 +19,10 @@ const node_fs_1 = require("node:fs");
19
19
  const node_path_1 = require("node:path");
20
20
  const open_1 = __importDefault(require("open"));
21
21
  const log_1 = require("./log");
22
- // what port to listen on for incoming requests
23
- const CONFIG_LISTEN_PORT = 5555;
24
22
  // oauth server timeouts
25
23
  const SERVER_TIMEOUT = 10000;
26
24
  // where to wait for incoming redirect request from oauth server to arrive
27
- const REDIRECT_URI = 'http://127.0.0.1:5555/callback';
25
+ const REDIRECT_URI = (port) => `http://127.0.0.1:${port}/callback`;
28
26
  // These scopes cannot be cancelled, they are always needed.
29
27
  const DEFAULT_SCOPES = ['openid', 'offline'];
30
28
  const auth = ({ oauthHost, clientId }) => __awaiter(void 0, void 0, void 0, function* () {
@@ -33,10 +31,18 @@ const auth = ({ oauthHost, clientId }) => __awaiter(void 0, void 0, void 0, func
33
31
  });
34
32
  log_1.log.info('Discovering oauth server');
35
33
  const issuer = yield openid_client_1.Issuer.discover(oauthHost);
34
+ //
35
+ // Start HTTP server and wait till /callback is hit
36
+ //
37
+ const server = (0, node_http_1.createServer)();
38
+ server.listen(0, function () {
39
+ log_1.log.info(`Listening on port ${this.address().port}`);
40
+ });
41
+ const listen_port = server.address().port;
36
42
  const neonOAuthClient = new issuer.Client({
37
43
  token_endpoint_auth_method: 'none',
38
44
  client_id: clientId,
39
- redirect_uris: [REDIRECT_URI],
45
+ redirect_uris: [REDIRECT_URI(listen_port)],
40
46
  response_types: ['code'],
41
47
  });
42
48
  // https://datatracker.ietf.org/doc/html/rfc6819#section-4.4.1.8
@@ -45,10 +51,7 @@ const auth = ({ oauthHost, clientId }) => __awaiter(void 0, void 0, void 0, func
45
51
  const codeVerifier = openid_client_1.generators.codeVerifier();
46
52
  const codeChallenge = openid_client_1.generators.codeChallenge(codeVerifier);
47
53
  return new Promise((resolve) => {
48
- //
49
- // Start HTTP server and wait till /callback is hit
50
- //
51
- const server = (0, node_http_1.createServer)((request, response) => __awaiter(void 0, void 0, void 0, function* () {
54
+ server.on('request', (request, response) => __awaiter(void 0, void 0, void 0, function* () {
52
55
  var _a;
53
56
  //
54
57
  // Wait for callback and follow oauth flow.
@@ -60,7 +63,7 @@ const auth = ({ oauthHost, clientId }) => __awaiter(void 0, void 0, void 0, func
60
63
  }
61
64
  log_1.log.info(`Callback received: ${request.url}`);
62
65
  const params = neonOAuthClient.callbackParams(request);
63
- const tokenSet = yield neonOAuthClient.callback(REDIRECT_URI, params, {
66
+ const tokenSet = yield neonOAuthClient.callback(REDIRECT_URI(listen_port), params, {
64
67
  code_verifier: codeVerifier,
65
68
  state,
66
69
  });
@@ -69,9 +72,6 @@ const auth = ({ oauthHost, clientId }) => __awaiter(void 0, void 0, void 0, func
69
72
  resolve(tokenSet);
70
73
  server.close();
71
74
  }));
72
- server.listen(CONFIG_LISTEN_PORT, () => {
73
- log_1.log.info(`Listening on port ${CONFIG_LISTEN_PORT}`);
74
- });
75
75
  //
76
76
  // Open browser to let user authenticate
77
77
  //
File without changes