From 4c5755164ceba608497cf36377746a6a3fbc41a8 Mon Sep 17 00:00:00 2001 From: Danny Coates Date: Tue, 21 Oct 2014 13:46:33 -0700 Subject: [PATCH] feat(verify): added 'client' to /verify response Closes #149 --- docs/api.md | 2 ++ lib/routes/verify.js | 3 +++ lib/token.js | 3 +++ test/api.js | 1 + 4 files changed, 9 insertions(+) diff --git a/docs/api.md b/docs/api.md index 639ab207d..2ccbdb8b0 100644 --- a/docs/api.md +++ b/docs/api.md @@ -420,6 +420,7 @@ curl -v \ A valid request will return JSON with these properties: - `user`: The uid of the respective user. +- `client_id`: The client_id of the respective client. - `scopes`: An array of scopes allowed for this token. **Example:** @@ -427,6 +428,7 @@ A valid request will return JSON with these properties: ```json { "user": "5901bd09376fadaa076afacef5251b6a", + "client_id": "45defeda038a1c92", "scopes": ["profile:email", "profile:avatar"] } ``` diff --git a/lib/routes/verify.js b/lib/routes/verify.js index 288366726..3097f28b8 100644 --- a/lib/routes/verify.js +++ b/lib/routes/verify.js @@ -8,6 +8,8 @@ const config = require('../config'); const token = require('../token'); const validators = require('../validators'); +/*jshint camelcase: false*/ + module.exports = { validate: { payload: { @@ -20,6 +22,7 @@ module.exports = { response: { schema: { user: Joi.string().required(), + client_id: Joi.string().required(), scope: Joi.array(), email: Joi.string() } diff --git a/lib/token.js b/lib/token.js index e0876fda7..cb167d9e0 100644 --- a/lib/token.js +++ b/lib/token.js @@ -7,6 +7,8 @@ const auth = require('./auth'); const db = require('./db'); const encrypt = require('./encrypt'); +/*jshint camelcase: false*/ + exports.verify = function verify(token) { return db.getToken(encrypt.hash(token)) .then(function(token) { @@ -15,6 +17,7 @@ exports.verify = function verify(token) { } var tokenInfo = { user: token.userId.toString('hex'), + client_id: token.clientId.toString('hex'), scope: token.scope }; diff --git a/test/api.js b/test/api.js index d093188f3..2b8dfa240 100644 --- a/test/api.js +++ b/test/api.js @@ -937,6 +937,7 @@ describe('/v1', function() { }).then(function(res) { assert.equal(res.statusCode, 200); assert.equal(res.result.user, USERID); + assert.equal(res.result.client_id, clientId); assert.equal(res.result.scope[0], 'profile'); assert.equal(res.result.email, VEMAIL); }).done(done, done);