@boxyhq/saml-jackson 0.2.2-beta.169 → 0.2.2-beta.174

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 CHANGED
@@ -85,7 +85,21 @@ router.get('/api/v1/saml/config', async (req, res) => {
85
85
  });
86
86
  }
87
87
  });
88
+ // delete config
89
+ router.delete('/api/v1/saml/config', async (req, res) => {
90
+ try {
91
+ // apply your authentication flow (or ensure this route has passed through your auth middleware)
92
+ ...
88
93
 
94
+ // only when properly authenticated, call the config function
95
+ await apiController.deleteConfig(req.body);
96
+ res.status(200).end();
97
+ } catch (err) {
98
+ res.status(500).json({
99
+ error: err.message,
100
+ });
101
+ }
102
+ });
89
103
  // OAuth 2.0 flow
90
104
  router.get('/oauth/authorize', async (req, res) => {
91
105
  try {
@@ -228,6 +242,26 @@ curl -G --location 'http://localhost:6000/api/v1/saml/config' \
228
242
 
229
243
  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.
230
244
 
245
+ #### 2.2 SAML delete config API
246
+
247
+ This endpoint can be used to delete an existing IdP metadata.
248
+
249
+ ```
250
+ curl -X "DELETE" --location 'http://localhost:6000/api/v1/saml/config' \
251
+ --header 'Authorization: Api-Key <Jackson API Key>' \
252
+ --header 'Content-Type: application/x-www-form-urlencoded' \
253
+ --data-urlencode 'tenant=boxyhq.com' \
254
+ --data-urlencode 'product=demo'
255
+ ```
256
+
257
+ ```
258
+ curl -X "DELETE" --location 'http://localhost:6000/api/v1/saml/config' \
259
+ --header 'Authorization: Api-Key <Jackson API Key>' \
260
+ --header 'Content-Type: application/x-www-form-urlencoded' \
261
+ --data-urlencode 'clientID=<Client ID>'
262
+ --data-urlencode 'clientSecret=<Client Secret>'
263
+ ```
264
+
231
265
  ### 3. OAuth 2.0 Flow
232
266
 
233
267
  Jackson has been designed to abstract the SAML login flow as a pure OAuth 2.0 flow. This means it's compatible with any standard OAuth 2.0 library out there, both client-side and server-side. It is important to remember that SAML is configured per customer unlike OAuth 2.0 where you can have a single OAuth app supporting logins for all customers.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@boxyhq/saml-jackson",
3
- "version": "0.2.2-beta.169",
3
+ "version": "0.2.2-beta.174",
4
4
  "license": "Apache 2.0",
5
5
  "description": "SAML 2.0 service",
6
6
  "main": "src/index.js",
@@ -127,10 +127,41 @@ const getConfig = async (body) => {
127
127
  }
128
128
  };
129
129
 
130
+ const deleteConfig = async (body) => {
131
+ const { clientID, clientSecret, tenant, product } = body;
132
+
133
+ if (clientID) {
134
+ if (!clientSecret) {
135
+ throw new JacksonError('Please provide clientSecret', 400);
136
+ }
137
+ const samlConfig = await configStore.get(clientID);
138
+ if (!samlConfig) {
139
+ return;
140
+ }
141
+ if (samlConfig.clientSecret === clientSecret) {
142
+ await configStore.delete(clientID);
143
+ } else {
144
+ throw new JacksonError('clientSecret mismatch', 400);
145
+ }
146
+ } else {
147
+ const samlConfigs = await configStore.getByIndex({
148
+ name: indexNames.tenantProduct,
149
+ value: dbutils.keyFromParts(tenant, product),
150
+ });
151
+ if (!samlConfigs || !samlConfigs.length) {
152
+ return;
153
+ }
154
+ for (const conf of samlConfigs) {
155
+ await configStore.delete(conf.clientID);
156
+ }
157
+ }
158
+ };
159
+
130
160
  module.exports = (opts) => {
131
161
  configStore = opts.configStore;
132
162
  return {
133
163
  config,
134
164
  getConfig,
165
+ deleteConfig,
135
166
  };
136
167
  };
package/src/jackson.js CHANGED
@@ -130,6 +130,22 @@ internalApp.get(apiPath + '/config', async (req, res) => {
130
130
  }
131
131
  });
132
132
 
133
+ internalApp.delete(apiPath + '/config', async (req, res) => {
134
+ try {
135
+ const apiKey = extractAuthToken(req);
136
+ if (!validateApiKey(apiKey)) {
137
+ res.status(401).send('Unauthorized');
138
+ return;
139
+ }
140
+ await apiController.deleteConfig(req.body);
141
+ res.status(200).end();
142
+ } catch (err) {
143
+ res.status(500).json({
144
+ error: err.message,
145
+ });
146
+ }
147
+ });
148
+
133
149
  let internalServer = server;
134
150
  if (env.useInternalServer) {
135
151
  internalServer = internalApp.listen(env.internalHostPort, async () => {
@@ -143,10 +143,35 @@ tap.test('controller/api', async (t) => {
143
143
  );
144
144
  t.equal(response.provider, PROVIDER);
145
145
 
146
- const savedConf = await apiController.getConfig({
146
+ let savedConf = await apiController.getConfig({
147
147
  clientID: CLIENT_ID,
148
148
  });
149
149
  t.equal(savedConf.provider, PROVIDER);
150
+ try {
151
+ await apiController.deleteConfig({ clientID: CLIENT_ID });
152
+ t.fail('Expecting JacksonError.');
153
+ } catch (err) {
154
+ t.equal(err.message, 'Please provide clientSecret');
155
+ t.equal(err.statusCode, 400);
156
+ }
157
+ try {
158
+ await apiController.deleteConfig({
159
+ clientID: CLIENT_ID,
160
+ clientSecret: 'xxxxx',
161
+ });
162
+ t.fail('Expecting JacksonError.');
163
+ } catch (err) {
164
+ t.equal(err.message, 'clientSecret mismatch');
165
+ t.equal(err.statusCode, 400);
166
+ }
167
+ await apiController.deleteConfig({
168
+ clientID: CLIENT_ID,
169
+ clientSecret: 'f3b0f91eb8f4a9f7cc2254e08682d50b05b5d36262929e7f',
170
+ });
171
+ savedConf = await apiController.getConfig({
172
+ clientID: CLIENT_ID,
173
+ });
174
+ t.same(savedConf, {}, 'should return empty config');
150
175
 
151
176
  dbutils.keyDigest.restore();
152
177
  crypto.randomBytes.restore();