Skip to content

Commit ab424e2

Browse files
authored
Add JWT auth option (#656)
1 parent 66fee24 commit ab424e2

File tree

5 files changed

+51
-6
lines changed

5 files changed

+51
-6
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Add `JWT` auth option (#656). This is a ClickHouse Cloud feature.
13+
14+
### Changed
15+
16+
- Improved connection test (#655).
17+
- Updated dependencies.
18+
1019
## [0.8.0] - 2024-11-11
1120

1221
### Added

connection.schema.json

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@
4949
"type": "string",
5050
"default": "default"
5151
},
52-
"username": {
53-
"title": "Username",
54-
"type": "string",
55-
"default": "default"
52+
"useJWT": {
53+
"type": "boolean",
54+
"title": "Use JWT token instead of password",
55+
"default": false
5656
},
5757
"passwordMode": {
5858
"title": "Password mode",
@@ -117,6 +117,29 @@
117117
}
118118
]
119119
},
120+
"useJWT": {
121+
"oneOf": [
122+
{
123+
"properties": {
124+
"useJWT": {
125+
"enum": [false]
126+
},
127+
"username": {
128+
"title": "Username",
129+
"type": "string",
130+
"default": "default"
131+
}
132+
}
133+
},
134+
{
135+
"properties": {
136+
"useJWT": {
137+
"enum": [true]
138+
}
139+
}
140+
}
141+
]
142+
},
120143
"enableTls": {
121144
"oneOf": [
122145
{

src/extension.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ export async function activate(
6969
connInfo.server = "http://" + connInfo.server;
7070
}
7171

72+
if (connInfo.useJWT) {
73+
propsToRemove.push("username");
74+
}
75+
7276
if (connInfo.passwordMode) {
7377
if (connInfo.passwordMode.toString().toLowerCase().includes("ask")) {
7478
connInfo.askForPassword = true;

src/ls/driver.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,20 @@ export default class ClickHouseDriver
6060

6161
const opts = {
6262
url: url,
63-
username: this.credentials.username,
64-
password: this.credentials.password,
6563
role: this.credentials.role,
6664
request_timeout: this.credentials.requestTimeout,
6765
application: "sqltools-clickhouse-driver",
6866
database: this.credentials.database,
6967
tls: tlsConfig,
7068
} as ClickHouseClientConfigOptions;
7169

70+
if (this.credentials.useJWT) {
71+
opts.access_token = this.credentials.password;
72+
} else {
73+
opts.username = this.credentials.username;
74+
opts.password = this.credentials.password;
75+
}
76+
7277
this.connection = Promise.resolve(createClient(opts));
7378
return this.connection;
7479
}

ui.schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"server",
44
"port",
55
"database",
6+
"useJWT",
67
"username",
78
"passwordMode",
89
"password",
@@ -12,6 +13,9 @@
1213
"tls"
1314
],
1415
"password": { "ui:widget": "password" },
16+
"useJWT": {
17+
"ui:help": "This is a ClickHouse Cloud feature. Put token in password field"
18+
},
1519
"role": {
1620
"ui:help": "Only for ClickHouse >=24.4! See https://clickhouse.com/docs/en/interfaces/http#setting-role-with-query-parameters"
1721
},

0 commit comments

Comments
 (0)