Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Commit

Permalink
feat(verify): added 'client' to /verify response
Browse files Browse the repository at this point in the history
Closes #149
  • Loading branch information
dannycoates committed Oct 21, 2014
1 parent 98f41f7 commit 4c57551
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/api.md
Expand Up @@ -420,13 +420,15 @@ 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:**

```json
{
"user": "5901bd09376fadaa076afacef5251b6a",
"client_id": "45defeda038a1c92",
"scopes": ["profile:email", "profile:avatar"]
}
```
Expand Down
3 changes: 3 additions & 0 deletions lib/routes/verify.js
Expand Up @@ -8,6 +8,8 @@ const config = require('../config');
const token = require('../token');
const validators = require('../validators');

/*jshint camelcase: false*/

module.exports = {
validate: {
payload: {
Expand All @@ -20,6 +22,7 @@ module.exports = {
response: {
schema: {
user: Joi.string().required(),
client_id: Joi.string().required(),
scope: Joi.array(),
email: Joi.string()
}
Expand Down
3 changes: 3 additions & 0 deletions lib/token.js
Expand Up @@ -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) {
Expand All @@ -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
};

Expand Down
1 change: 1 addition & 0 deletions test/api.js
Expand Up @@ -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);
Expand Down

0 comments on commit 4c57551

Please sign in to comment.