@boxyhq/saml-jackson 0.2.1-beta.161 → 0.2.1-beta.162
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 +16 -2
- package/package.json +1 -1
- package/src/jackson.js +2 -2
- package/src/test/api.test.js +13 -8
package/README.md
CHANGED
@@ -71,6 +71,20 @@ router.post('/api/v1/saml/config', async (req, res) => {
|
|
71
71
|
});
|
72
72
|
}
|
73
73
|
});
|
74
|
+
// fetch config
|
75
|
+
router.get('/api/v1/saml/config', async (req, res) => {
|
76
|
+
try {
|
77
|
+
// apply your authentication flow (or ensure this route has passed through your auth middleware)
|
78
|
+
...
|
79
|
+
|
80
|
+
// only when properly authenticated, call the config function
|
81
|
+
res.json(await apiController.config(req.query));
|
82
|
+
} catch (err) {
|
83
|
+
res.status(500).json({
|
84
|
+
error: err.message,
|
85
|
+
});
|
86
|
+
}
|
87
|
+
});
|
74
88
|
|
75
89
|
// OAuth 2.0 flow
|
76
90
|
router.get('/oauth/authorize', async (req, res) => {
|
@@ -198,7 +212,7 @@ The response returns a JSON with `client_id` and `client_secret` that can be sto
|
|
198
212
|
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.
|
199
213
|
|
200
214
|
```
|
201
|
-
curl --location
|
215
|
+
curl -G --location 'http://localhost:6000/api/v1/saml/config' \
|
202
216
|
--header 'Authorization: Api-Key <Jackson API Key>' \
|
203
217
|
--header 'Content-Type: application/x-www-form-urlencoded' \
|
204
218
|
--data-urlencode 'tenant=boxyhq.com' \
|
@@ -206,7 +220,7 @@ curl --location --request POST 'http://localhost:6000/api/v1/saml/config/get' \
|
|
206
220
|
```
|
207
221
|
|
208
222
|
```
|
209
|
-
curl --location
|
223
|
+
curl -G --location 'http://localhost:6000/api/v1/saml/config' \
|
210
224
|
--header 'Authorization: Api-Key <Jackson API Key>' \
|
211
225
|
--header 'Content-Type: application/x-www-form-urlencoded' \
|
212
226
|
--data-urlencode 'clientID=<Client ID>'
|
package/package.json
CHANGED
package/src/jackson.js
CHANGED
@@ -114,7 +114,7 @@ internalApp.post(apiPath + '/config', async (req, res) => {
|
|
114
114
|
}
|
115
115
|
});
|
116
116
|
|
117
|
-
internalApp.
|
117
|
+
internalApp.get(apiPath + '/config', async (req, res) => {
|
118
118
|
try {
|
119
119
|
const apiKey = extractAuthToken(req);
|
120
120
|
if (!validateApiKey(apiKey)) {
|
@@ -122,7 +122,7 @@ internalApp.post(apiPath + '/config/get', async (req, res) => {
|
|
122
122
|
return;
|
123
123
|
}
|
124
124
|
|
125
|
-
res.json(await apiController.getConfig(req.
|
125
|
+
res.json(await apiController.getConfig(req.query));
|
126
126
|
} catch (err) {
|
127
127
|
res.status(500).json({
|
128
128
|
error: err.message,
|
package/src/test/api.test.js
CHANGED
@@ -125,23 +125,28 @@ tap.test('controller/api', async (t) => {
|
|
125
125
|
|
126
126
|
t.test('when the request is good', async (t) => {
|
127
127
|
const body = Object.assign({}, config[0]);
|
128
|
+
const CLIENTID = '75edb050796a0eb1cf2cfb0da7245f85bc50baa7';
|
129
|
+
const PROVIDER = 'accounts.google.com';
|
128
130
|
|
129
|
-
sinon
|
130
|
-
|
131
|
-
.returns('75edb050796a0eb1cf2cfb0da7245f85bc50baa7');
|
132
|
-
|
133
|
-
sinon
|
131
|
+
const kdStub = sinon.stub(dbutils, 'keyDigest').returns(CLIENTID);
|
132
|
+
const rbStub = sinon
|
134
133
|
.stub(crypto, 'randomBytes')
|
135
134
|
.returns('f3b0f91eb8f4a9f7cc2254e08682d50b05b5d36262929e7f');
|
136
135
|
|
137
136
|
const response = await apiController.config(body);
|
138
|
-
|
139
|
-
t.
|
137
|
+
t.ok(kdStub.called);
|
138
|
+
t.ok(rbStub.calledOnce);
|
139
|
+
t.equal(response.client_id, CLIENTID);
|
140
140
|
t.equal(
|
141
141
|
response.client_secret,
|
142
142
|
'f3b0f91eb8f4a9f7cc2254e08682d50b05b5d36262929e7f'
|
143
143
|
);
|
144
|
-
t.equal(response.provider,
|
144
|
+
t.equal(response.provider, PROVIDER);
|
145
|
+
|
146
|
+
const savedConf = await apiController.getConfig({
|
147
|
+
clientID: CLIENTID,
|
148
|
+
});
|
149
|
+
t.equal(savedConf.provider, PROVIDER);
|
145
150
|
|
146
151
|
dbutils.keyDigest.restore();
|
147
152
|
crypto.randomBytes.restore();
|