Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(nodejs): authenticate with user id and private key only #22

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 10 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,16 @@ run()
const { Sender } = require('@questdb/nodejs-client');

async function run() {
// construct a JsonWebKey
// authentication details
const CLIENT_ID = 'testapp';
const PRIVATE_KEY = '9b9x5WhJywDEuo1KGQWSPNxtX-6X6R2BRCKhYMMY6n8';
const PUBLIC_KEY = {
x: 'aultdA0PjhD_cWViqKKyL5chm6H1n-BiZBo_48T-uqc',
y: '__ptaol41JWSpTTL525yVEfzmY8A6Vi_QrW1FjKcHMg'
};
const JWK = {
...PUBLIC_KEY,
d: PRIVATE_KEY,
const AUTH = {
kid: CLIENT_ID,
kty: 'EC',
crv: 'P-256',
d: PRIVATE_KEY
};

// pass the JsonWebKey to the sender
// will use it for authentication
const sender = new Sender({jwk: JWK});
// pass the authentication details to the sender
const sender = new Sender({auth: AUTH});

// connect() takes an optional second argument
// if 'true' passed the connection is secured with TLS encryption
Expand All @@ -99,24 +91,16 @@ run().catch(console.error);
import { Sender } from '@questdb/nodejs-client';

async function run(): Promise<number> {
// construct a JsonWebKey
// authentication details
const CLIENT_ID: string = 'testapp';
const PRIVATE_KEY: string = '9b9x5WhJywDEuo1KGQWSPNxtX-6X6R2BRCKhYMMY6n8';
const PUBLIC_KEY: { x: string, y: string } = {
x: 'aultdA0PjhD_cWViqKKyL5chm6H1n-BiZBo_48T-uqc',
y: '__ptaol41JWSpTTL525yVEfzmY8A6Vi_QrW1FjKcHMg'
};
const JWK: { x: string, y: string, kid: string, kty: string, d: string, crv: string } = {
...PUBLIC_KEY,
d: PRIVATE_KEY,
const AUTH: { kid: string, d: string } = {
kid: CLIENT_ID,
kty: 'EC',
crv: 'P-256',
d: PRIVATE_KEY
};

// pass the JsonWebKey to the sender
// will use it for authentication
const sender: Sender = new Sender({jwk: JWK});
// pass the authentication details to the sender
const sender: Sender = new Sender({auth: AUTH});

// connect() takes an optional second argument
// if 'true' passed the connection is secured with TLS encryption
Expand Down
49 changes: 27 additions & 22 deletions docs/Sender.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,18 @@ <h1 class="page-title">Class: Sender</h1>

<h2><span class="attribs"><span class="type-signature"></span></span>Sender<span class="signature">(options)</span><span class="type-signature"></span></h2>

<div class="class-description">The QuestDB client's API provides methods to connect to the database, ingest data and close the connection.
<div class="class-description">The QuestDB client's API provides methods to connect to the database, ingest data, and close the connection.
<p>
The client supports authentication. <br>
A JsonWebKey can be passed to the Sender in its constructor, the JsonWebKey will be used for authentication. <br>
If no JsonWebKey specified the client will not attempt to authenticate itself with the server. <br>
Details on how to configure QuestDB authentication: <a href="https://questdb.io/docs/reference/api/ilp/authenticate">https://questdb.io/docs/reference/api/ilp/authenticate</a>
Authentication details can be passed to the Sender in its configuration options. <br>
The user id and the user's private key are required for authentication. <br>
More details on configuration options can be found in the description of the constructor. <br>
Please, note that authentication is enabled by default in QuestDB Enterprise only. <br>
Details on how to configure authentication in the open source version of QuestDB: <a href="https://questdb.io/docs/reference/api/ilp/authenticate">https://questdb.io/docs/reference/api/ilp/authenticate</a>
</p>
<p>
The client also supports TLS encryption to provide a secure connection. <br>
However, QuestDB does not support TLS yet and requires an external reverse-proxy, such as Nginx to enable encryption.
Please, note that the open source version of QuestDB does not support TLS, and requires an external reverse-proxy, such as Nginx to enable encryption.
</p></div>


Expand Down Expand Up @@ -128,7 +130,10 @@ <h5>Parameters:</h5>
If the value passed is not a boolean, the setting is ignored. </li>
<li>jwk: <i>{x: string, y: string, kid: string, kty: string, d: string, crv: string}</i> - JsonWebKey for authentication. <br>
If not provided, client is not authenticated and server might reject the connection depending on configuration. <br>
No type checks performed on the object passed. </li>
No type checks performed on the object passed. <br>
<b>Deprecated</b>, please, use the <i>auth</i> option instead. </li>
<li>auth: <i>{kid: string, d: string}</i> - Authentication details, `kid` is the username, `d` is the user's private key. <br>
If not provided, client is not authenticated and server might reject the connection depending on configuration. </li>
<li>log: <i>(level: 'error'|'warn'|'info'|'debug', message: string) => void</i> - logging function. <br>
If not provided, default logging is used which writes to the console with logging level <i>info</i>. <br>
If not a function passed, the setting is ignored. </li>
Expand Down Expand Up @@ -174,7 +179,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line27">line 27</a>
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line36">line 36</a>
</li></ul></dd>


Expand Down Expand Up @@ -389,7 +394,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line366">line 366</a>
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line376">line 376</a>
</li></ul></dd>


Expand Down Expand Up @@ -478,7 +483,7 @@ <h4 class="name" id="atNow"><span class="type-signature"></span>atNow<span class

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line386">line 386</a>
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line396">line 396</a>
</li></ul></dd>


Expand Down Expand Up @@ -638,7 +643,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line294">line 294</a>
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line304">line 304</a>
</li></ul></dd>


Expand Down Expand Up @@ -749,7 +754,7 @@ <h4 class="name" id="close"><span class="type-signature">(async) </span>close<sp

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line174">line 174</a>
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line184">line 184</a>
</li></ul></dd>


Expand Down Expand Up @@ -944,7 +949,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line118">line 118</a>
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line128">line 128</a>
</li></ul></dd>


Expand Down Expand Up @@ -1126,7 +1131,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line309">line 309</a>
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line319">line 319</a>
</li></ul></dd>


Expand Down Expand Up @@ -1237,7 +1242,7 @@ <h4 class="name" id="flush"><span class="type-signature">(async) </span>flush<sp

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line187">line 187</a>
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line197">line 197</a>
</li></ul></dd>


Expand Down Expand Up @@ -1419,7 +1424,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line325">line 325</a>
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line335">line 335</a>
</li></ul></dd>


Expand Down Expand Up @@ -1530,7 +1535,7 @@ <h4 class="name" id="reset"><span class="type-signature"></span>reset<span class

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line104">line 104</a>
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line114">line 114</a>
</li></ul></dd>


Expand Down Expand Up @@ -1691,7 +1696,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line89">line 89</a>
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line99">line 99</a>
</li></ul></dd>


Expand Down Expand Up @@ -1851,7 +1856,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line277">line 277</a>
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line287">line 287</a>
</li></ul></dd>


Expand Down Expand Up @@ -2033,7 +2038,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line252">line 252</a>
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line262">line 262</a>
</li></ul></dd>


Expand Down Expand Up @@ -2192,7 +2197,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line231">line 231</a>
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line241">line 241</a>
</li></ul></dd>


Expand Down Expand Up @@ -2444,7 +2449,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line346">line 346</a>
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line356">line 356</a>
</li></ul></dd>


Expand Down Expand Up @@ -2518,7 +2523,7 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-@q
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Mon Oct 09 2023 10:21:55 GMT+0300 (Eastern European Summer Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Mon Nov 27 2023 17:39:18 GMT+0000 (Greenwich Mean Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
38 changes: 11 additions & 27 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,24 +91,16 @@ <h3>Authentication and secure connection</h3>
<pre class="prettyprint source lang-javascript"><code>const { Sender } = require('@questdb/nodejs-client');

async function run() {
// construct a JsonWebKey
// authentication details
const CLIENT_ID = 'testapp';
const PRIVATE_KEY = '9b9x5WhJywDEuo1KGQWSPNxtX-6X6R2BRCKhYMMY6n8';
const PUBLIC_KEY = {
x: 'aultdA0PjhD_cWViqKKyL5chm6H1n-BiZBo_48T-uqc',
y: '__ptaol41JWSpTTL525yVEfzmY8A6Vi_QrW1FjKcHMg'
};
const JWK = {
...PUBLIC_KEY,
d: PRIVATE_KEY,
const AUTH = {
kid: CLIENT_ID,
kty: 'EC',
crv: 'P-256',
d: PRIVATE_KEY
};

// pass the JsonWebKey to the sender
// will use it for authentication
const sender = new Sender({jwk: JWK});
// pass the authentication details to the sender
const sender = new Sender({auth: AUTH});

// connect() takes an optional second argument
// if 'true' passed the connection is secured with TLS encryption
Expand All @@ -130,24 +122,16 @@ <h3>TypeScript example</h3>
<pre class="prettyprint source lang-typescript"><code>import { Sender } from '@questdb/nodejs-client';

async function run(): Promise&lt;number> {
// construct a JsonWebKey
// authentication details
const CLIENT_ID: string = 'testapp';
const PRIVATE_KEY: string = '9b9x5WhJywDEuo1KGQWSPNxtX-6X6R2BRCKhYMMY6n8';
const PUBLIC_KEY: { x: string, y: string } = {
x: 'aultdA0PjhD_cWViqKKyL5chm6H1n-BiZBo_48T-uqc',
y: '__ptaol41JWSpTTL525yVEfzmY8A6Vi_QrW1FjKcHMg'
};
const JWK: { x: string, y: string, kid: string, kty: string, d: string, crv: string } = {
...PUBLIC_KEY,
d: PRIVATE_KEY,
const AUTH: { kid: string, d: string } = {
kid: CLIENT_ID,
kty: 'EC',
crv: 'P-256',
d: PRIVATE_KEY
};

// pass the JsonWebKey to the sender
// will use it for authentication
const sender: Sender = new Sender({jwk: JWK});
// pass the authentication details to the sender
const sender: Sender = new Sender({auth: AUTH});

// connect() takes an optional second argument
// if 'true' passed the connection is secured with TLS encryption
Expand Down Expand Up @@ -256,7 +240,7 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-@q
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Mon Oct 09 2023 10:21:55 GMT+0300 (Eastern European Summer Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Mon Nov 27 2023 17:39:18 GMT+0000 (Greenwich Mean Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion docs/index.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-@q
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Mon Oct 09 2023 10:21:55 GMT+0300 (Eastern European Summer Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Mon Nov 27 2023 17:39:18 GMT+0000 (Greenwich Mean Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion docs/module-@questdb_nodejs-client.html
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-@q
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Mon Oct 09 2023 10:21:55 GMT+0300 (Eastern European Summer Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Mon Nov 27 2023 17:39:18 GMT+0000 (Greenwich Mean Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
Loading