@boxyhq/saml-jackson 0.1.5-beta.137 → 0.1.5-beta.141
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 +5 -6
- package/package.json +1 -1
- package/src/controller/api.js +3 -2
- package/src/db/db.test.js +1 -1
- package/src/db/sql/entity/JacksonStore.js +0 -4
- package/src/db/sql/entity/JacksonTTL.js +23 -0
- package/src/db/sql/model/JacksonStore.js +1 -2
- package/src/db/sql/model/JacksonTTL.js +8 -0
- package/src/db/sql/sql.js +20 -9
- package/src/jackson.js +1 -1
package/README.md
CHANGED
@@ -166,12 +166,12 @@ curl --location --request POST 'http://localhost:6000/api/v1/saml/config' \
|
|
166
166
|
|
167
167
|
The response returns a JSON with `client_id` and `client_secret` that can be stored against your tenant and product for a more secure OAuth 2.0 flow. If you do not want to store the `client_id` and `client_secret` you can alternatively use `client_id=tenant=<tenantID>&product=<productID>` and any arbitrary value for `client_secret` when setting up the OAuth 2.0 flow. Additionally a `provider` attribute is also returned which indicates the domain of your Identity Provider.
|
168
168
|
|
169
|
-
#### 2.1 SAML
|
169
|
+
#### 2.1 SAML get config API
|
170
170
|
|
171
|
-
This endpoint can be used to return metadata about an existing SAML config. This can be used to check and display the details to your customers. You can use either `clientID`
|
171
|
+
This endpoint can be used to return metadata about an existing SAML config. This can be used to check and display the details to your customers. You can use either `clientID` or `tenant` and `product` combination.
|
172
172
|
|
173
173
|
```
|
174
|
-
curl --location --request
|
174
|
+
curl --location --request POST 'http://localhost:6000/api/v1/saml/config/get' \
|
175
175
|
--header 'Authorization: Api-Key <Jackson API Key>' \
|
176
176
|
--header 'Content-Type: application/x-www-form-urlencoded' \
|
177
177
|
--data-urlencode 'tenant=boxyhq.com' \
|
@@ -179,11 +179,10 @@ curl --location --request GET 'http://localhost:6000/api/v1/saml/config' \
|
|
179
179
|
```
|
180
180
|
|
181
181
|
```
|
182
|
-
curl --location --request
|
182
|
+
curl --location --request POST 'http://localhost:6000/api/v1/saml/config/get' \
|
183
183
|
--header 'Authorization: Api-Key <Jackson API Key>' \
|
184
184
|
--header 'Content-Type: application/x-www-form-urlencoded' \
|
185
|
-
--data-urlencode 'clientID=<Client ID>'
|
186
|
-
--data-urlencode 'clientSecret=<Client Secret>'
|
185
|
+
--data-urlencode 'clientID=<Client ID>'
|
187
186
|
```
|
188
187
|
|
189
188
|
The response returns a JSON with `provider` indicating the domain of your Identity Provider. If an empty JSON payload is returned then we do not have any configuration stored for the attributes you requested.
|
package/package.json
CHANGED
package/src/controller/api.js
CHANGED
@@ -78,13 +78,14 @@ const config = async (body) => {
|
|
78
78
|
return {
|
79
79
|
client_id: clientID,
|
80
80
|
client_secret: clientSecret,
|
81
|
+
provider: idpMetadata.provider,
|
81
82
|
};
|
82
83
|
};
|
83
84
|
|
84
85
|
const getConfig = async (body) => {
|
85
|
-
const { clientID,
|
86
|
+
const { clientID, tenant, product } = body;
|
86
87
|
|
87
|
-
if (clientID
|
88
|
+
if (clientID) {
|
88
89
|
const samlConfig = await configStore.get(clientID);
|
89
90
|
if (!samlConfig) {
|
90
91
|
return {};
|
package/src/db/db.test.js
CHANGED
@@ -224,7 +224,7 @@ t.test('dbs', ({ end }) => {
|
|
224
224
|
}
|
225
225
|
|
226
226
|
await new Promise((resolve) =>
|
227
|
-
setTimeout(resolve, (
|
227
|
+
setTimeout(resolve, (2*ttl + 0.5) * 1000)
|
228
228
|
);
|
229
229
|
|
230
230
|
const ret1 = await ttlStore.get(record1.id);
|
@@ -0,0 +1,23 @@
|
|
1
|
+
const EntitySchema = require('typeorm').EntitySchema;
|
2
|
+
const JacksonTTL = require('../model/JacksonTTL.js');
|
3
|
+
|
4
|
+
module.exports = new EntitySchema({
|
5
|
+
name: 'JacksonTTL',
|
6
|
+
target: JacksonTTL,
|
7
|
+
columns: {
|
8
|
+
key: {
|
9
|
+
primary: true,
|
10
|
+
type: 'varchar',
|
11
|
+
length: 1500,
|
12
|
+
},
|
13
|
+
expiresAt: {
|
14
|
+
type: 'bigint',
|
15
|
+
},
|
16
|
+
},
|
17
|
+
indices: [
|
18
|
+
{
|
19
|
+
name: '_jackson_ttl_expires_at',
|
20
|
+
columns: ['expiresAt'],
|
21
|
+
},
|
22
|
+
],
|
23
|
+
});
|
package/src/db/sql/sql.js
CHANGED
@@ -2,6 +2,7 @@ require('reflect-metadata');
|
|
2
2
|
const typeorm = require('typeorm');
|
3
3
|
const JacksonStore = require('./model/JacksonStore.js');
|
4
4
|
const JacksonIndex = require('./model/JacksonIndex.js');
|
5
|
+
const JacksonTTL = require('./model/JacksonTTL.js');
|
5
6
|
|
6
7
|
const dbutils = require('../utils.js');
|
7
8
|
|
@@ -20,6 +21,7 @@ class Sql {
|
|
20
21
|
entities: [
|
21
22
|
require('./entity/JacksonStore.js')(options.type),
|
22
23
|
require('./entity/JacksonIndex.js'),
|
24
|
+
require('./entity/JacksonTTL.js'),
|
23
25
|
],
|
24
26
|
});
|
25
27
|
|
@@ -33,22 +35,29 @@ class Sql {
|
|
33
35
|
|
34
36
|
this.storeRepository = this.connection.getRepository(JacksonStore);
|
35
37
|
this.indexRepository = this.connection.getRepository(JacksonIndex);
|
38
|
+
this.ttlRepository = this.connection.getRepository(JacksonTTL);
|
36
39
|
|
37
40
|
if (options.ttl && options.limit) {
|
38
41
|
this.ttlCleanup = async () => {
|
39
42
|
const now = Date.now();
|
40
43
|
|
41
44
|
while (true) {
|
42
|
-
const ids = await this.
|
43
|
-
|
44
|
-
|
45
|
-
|
45
|
+
const ids = await this.ttlRepository
|
46
|
+
.createQueryBuilder('jackson_ttl')
|
47
|
+
.limit(options.limit)
|
48
|
+
.where('jackson_ttl.expiresAt <= :expiresAt', { expiresAt: now })
|
49
|
+
.getMany();
|
46
50
|
|
47
51
|
if (ids.length <= 0) {
|
48
52
|
break;
|
49
53
|
}
|
50
54
|
|
55
|
+
const delIds = ids.map((id) => {
|
56
|
+
return id.key;
|
57
|
+
});
|
58
|
+
|
51
59
|
await this.storeRepository.remove(ids);
|
60
|
+
await this.ttlRepository.delete(delIds);
|
52
61
|
}
|
53
62
|
|
54
63
|
this.timerId = setTimeout(this.ttlCleanup, options.ttl * 1000);
|
@@ -99,13 +108,15 @@ class Sql {
|
|
99
108
|
|
100
109
|
async put(namespace, key, val, ttl = 0, ...indexes) {
|
101
110
|
await this.connection.transaction(async (transactionalEntityManager) => {
|
102
|
-
const
|
103
|
-
|
104
|
-
JSON.stringify(val),
|
105
|
-
ttl > 0 ? Date.now() + ttl * 1000 : null
|
106
|
-
);
|
111
|
+
const dbKey = dbutils.key(namespace, key);
|
112
|
+
const store = new JacksonStore(dbKey, JSON.stringify(val));
|
107
113
|
await transactionalEntityManager.save(store);
|
108
114
|
|
115
|
+
if (ttl) {
|
116
|
+
const ttlRec = new JacksonTTL(dbKey, Date.now() + ttl * 1000);
|
117
|
+
await transactionalEntityManager.save(ttlRec);
|
118
|
+
}
|
119
|
+
|
109
120
|
// no ttl support for secondary indexes
|
110
121
|
for (const idx of indexes || []) {
|
111
122
|
const key = dbutils.keyForIndex(namespace, idx);
|
package/src/jackson.js
CHANGED
@@ -87,7 +87,7 @@ internalApp.post(apiPath + '/config', async (req, res) => {
|
|
87
87
|
}
|
88
88
|
});
|
89
89
|
|
90
|
-
internalApp.
|
90
|
+
internalApp.post(apiPath + '/config/get', async (req, res) => {
|
91
91
|
try {
|
92
92
|
const apiKey = extractAuthToken(req);
|
93
93
|
if (!validateApiKey(apiKey)) {
|