diff --git a/README.md b/README.md index 9eb937e..af7f93a 100644 --- a/README.md +++ b/README.md @@ -131,27 +131,19 @@ POST /api/v1/key ### Verify uploaded key ``` -GET /api/v1/verify?keyId=b8e4105cc9dedc77&nonce=6a314915c09368224b11df0feedbc53c +GET /api/v1/key?op=verify&keyId=b8e4105cc9dedc77&nonce=6a314915c09368224b11df0feedbc53c ``` ### Request key removal -#### Via delete request - ``` -DELETE /api/v1/key?keyId=b8e4105cc9dedc77 OR ?email=user@example.com -``` - -#### Via link - -``` -GET /api/v1/removeKey?keyId=b8e4105cc9dedc77 OR ?email=user@example.com +GET /api/v1/key?op=remove&keyId=b8e4105cc9dedc77 OR ?email=user@example.com ``` ### Verify key removal ``` -GET /api/v1/verifyRemove?keyId=b8e4105cc9dedc77&nonce=6a314915c09368224b11df0feedbc53c +GET /api/v1/key?op=verifyRemove&keyId=b8e4105cc9dedc77&nonce=6a314915c09368224b11df0feedbc53c ``` diff --git a/src/app.js b/src/app.js index ba304f8..5353ede 100644 --- a/src/app.js +++ b/src/app.js @@ -49,21 +49,7 @@ router.post('/api/v1/key', function *() { yield rest.create(this); }); router.get('/api/v1/key', function *() { - yield rest.read(this); -}); -router.del('/api/v1/key', function *() { - yield rest.remove(this); -}); - -// links for verification, removal and sharing -router.get('/api/v1/verify', function *() { - yield rest.verify(this); -}); -router.get('/api/v1/removeKey', function *() { - yield rest.remove(this); -}); -router.get('/api/v1/verifyRemove', function *() { - yield rest.verifyRemove(this); + yield rest.query(this); }); // Redirect all http traffic to https diff --git a/src/email/templates.json b/src/email/templates.json index a04f26b..533a707 100644 --- a/src/email/templates.json +++ b/src/email/templates.json @@ -1,12 +1,12 @@ { "verifyKey": { "subject": "Verify Your Key", - "text": "Hello {{name}},\n\nplease click here to verify your key:\n\n{{baseUrl}}/api/v1/verify?keyId={{keyId}}&nonce={{nonce}}", - "html": "
Hello {{name}},
please click here to verify your key.
" + "text": "Hello {{name}},\n\nplease click here to verify your key:\n\n{{baseUrl}}/api/v1/key?op=verify&keyId={{keyId}}&nonce={{nonce}}", + "html": "Hello {{name}},
please click here to verify your key.
" }, "verifyRemove": { "subject": "Verify Key Removal", - "text": "Hello {{name}},\n\nplease click here to verify the removal of your key:\n\n{{baseUrl}}/api/v1/verifyRemove?keyId={{keyId}}&nonce={{nonce}}", - "html": "Hello {{name}},
please click here to verify the removal of your key.
" + "text": "Hello {{name}},\n\nplease click here to verify the removal of your key:\n\n{{baseUrl}}/api/v1/key?op=verifyRemove&keyId={{keyId}}&nonce={{nonce}}", + "html": "Hello {{name}},
please click here to verify the removal of your key.
" } } \ No newline at end of file diff --git a/src/route/rest.js b/src/route/rest.js index c6171f9..18adcf6 100644 --- a/src/route/rest.js +++ b/src/route/rest.js @@ -50,6 +50,23 @@ class REST { ctx.status = 201; } + /** + * Public key query via http GET + * @param {Object} ctx The koa request/response context + */ + *query(ctx) { + let op = ctx.query.op; + if (this[op]) { + return yield this[op](ctx); // delegate operation + } + // do READ if no 'op' provided + let q = { keyId:ctx.query.keyId, fingerprint:ctx.query.fingerprint, email:ctx.query.email }; + if (!util.isKeyId(q.keyId) && !util.isFingerPrint(q.fingerprint) && !util.isEmail(q.email)) { + ctx.throw(400, 'Invalid request!'); + } + ctx.body = yield this._publicKey.get(q); + } + /** * Verify a public key's user id via http GET * @param {Object} ctx The koa request/response context @@ -66,18 +83,6 @@ class REST { ctx.set('Content-Type', 'text/html; charset=utf-8'); } - /** - * Public key fetch via http GET - * @param {Object} ctx The koa request/response context - */ - *read(ctx) { - let q = { keyId:ctx.query.keyId, fingerprint:ctx.query.fingerprint, email:ctx.query.email }; - if (!util.isKeyId(q.keyId) && !util.isFingerPrint(q.fingerprint) && !util.isEmail(q.email)) { - ctx.throw(400, 'Invalid request!'); - } - ctx.body = yield this._publicKey.get(q); - } - /** * Request public key removal via http DELETE * @param {Object} ctx The koa request/response context diff --git a/src/static/demo.html b/src/static/demo.html index bcc2646..cda176e 100644 --- a/src/static/demo.html +++ b/src/static/demo.html @@ -53,7 +53,8 @@