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

Commit 9d3aea6

Browse files
committed
feat(token): return the uid from the /token endpoint
Fixes https://github.com/mozilla/fxa-auth-server/pull/2985/files#r268891903
1 parent 57f5891 commit 9d3aea6

13 files changed

+29
-0
lines changed

fxa-oauth-server/lib/grant.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ module.exports.generateTokens = async function generateTokens(grant) {
119119
const access = await db.generateAccessToken(grant);
120120
const result = {
121121
access_token: access.token.toString('hex'),
122+
user: access.userId.toString('hex'),
122123
token_type: access.type,
123124
scope: access.scope.toString()
124125
};

fxa-oauth-server/lib/routes/authorization.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ module.exports = {
111111
code: Joi.string(),
112112
state: Joi.string(),
113113
access_token: validators.token,
114+
user: validators.uid,
114115
token_type: Joi.string().valid('bearer'),
115116
scope: Joi.string().allow(''),
116117
auth_at: Joi.number(),

fxa-oauth-server/lib/routes/token.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ module.exports = {
166166
access_token: validators.token.required(),
167167
refresh_token: validators.token,
168168
id_token: validators.assertion,
169+
user: validators.uid.required(),
169170
scope: validators.scope.required(),
170171
token_type: Joi.string().valid('bearer').required(),
171172
expires_in: Joi.number().max(MAX_TTL_S).required(),

fxa-oauth-server/lib/validators.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ exports.token = Joi.string()
2929
.length(config.get('unique.token') * 2)
3030
.regex(exports.HEX_STRING);
3131

32+
exports.uid = Joi.string()
33+
.length(32)
34+
.regex(exports.HEX_STRING);
35+
3236
const scopeString = Joi.string().max(256);
3337

3438
exports.scope = Joi.extend({

fxa-oauth-server/test/api.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,7 @@ describe('/v1', function() {
814814
assert.equal(res.statusCode, 200);
815815
assertSecurityHeaders(res);
816816
assert(res.result.access_token);
817+
assert(res.result.user);
817818
assert.equal(res.result.token_type, 'bearer');
818819
assert(res.result.scope);
819820
assert(res.result.expires_in <= defaultExpiresIn);
@@ -1096,6 +1097,7 @@ describe('/v1', function() {
10961097
assert.equal(res.statusCode, 200);
10971098
assertSecurityHeaders(res);
10981099
assert.ok(res.result.access_token);
1100+
assert.ok(res.result.user);
10991101
assert.equal(res.result.token_type, 'bearer');
11001102
assert.ok(res.result.auth_at);
11011103
assert.ok(res.result.expires_in);

lib/oauthdb/grant-tokens-from-authorization-code.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ module.exports = (config) => {
2828
refresh_token: validators.refreshToken.optional(),
2929
id_token: validators.assertion.optional(),
3030
scope: validators.scope.required(),
31+
user: validators.uid.required(),
3132
token_type: Joi.string().valid('bearer').required(),
3233
expires_in: Joi.number().required(),
3334
auth_at: Joi.number().required(),

lib/oauthdb/grant-tokens-from-credentials.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ module.exports = (config) => {
2626
access_token: validators.accessToken.required(),
2727
refresh_token: validators.refreshToken.optional(),
2828
id_token: validators.assertion.optional(),
29+
user: validators.uid.required(),
2930
scope: validators.scope.required(),
3031
auth_at: Joi.number().required(),
3132
token_type: Joi.string().valid('bearer').required(),

lib/oauthdb/grant-tokens-from-refresh-token.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ module.exports = (config) => {
2424
}),
2525
response: Joi.object({
2626
access_token: validators.accessToken.required(),
27+
user: validators.uid.required(),
2728
scope: validators.scope.required(),
2829
token_type: Joi.string().valid('bearer').required(),
2930
expires_in: Joi.number().required()

lib/routes/validators.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ module.exports.clientId = module.exports.hexString.length(16);
8686
module.exports.clientSecret = module.exports.hexString;
8787
module.exports.accessToken = module.exports.hexString.length(64);
8888
module.exports.refreshToken = module.exports.hexString.length(64);
89+
module.exports.uid = module.exports.hexString.length(32);
8990
module.exports.authorizationCode = module.exports.hexString.length(64);
9091
// Note that the empty string is a valid scope value (meaning "no permissions").
9192
module.exports.scope = isA.string().max(256).regex(/^[a-zA-Z0-9 _\/.:-]*$/).allow('');

test/local/oauthdb/grant-tokens-from-authorization-code.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const oauthdbModule = require('../../../lib/oauthdb');
1010
const error = require('../../../lib/error');
1111
const { mockLog } = require('../../mocks');
1212

13+
const MOCK_USER_ID = '5A6773A8D23E49FDAFCC976882E0B57E';
1314
const MOCK_CLIENT_ID = '0123456789ABCDEF';
1415
const MOCK_AUTHORIZATION_CODE = '1111112222223333334444445555556611111122222233333344444455555566';
1516
const MOCK_ACCESS_TOKEN = 'aaaaaa2222223333334444445555556611111122222233333344444455555566';
@@ -39,6 +40,7 @@ describe('oauthdb/grantTokensFromAuthorizationCode', () => {
3940
mockOAuthServer.post('/v1/token', body => true)
4041
.reply(200, {
4142
access_token: MOCK_ACCESS_TOKEN,
43+
user: MOCK_USER_ID,
4244
scope: '',
4345
token_type: 'bearer',
4446
expires_in: 123,
@@ -52,6 +54,7 @@ describe('oauthdb/grantTokensFromAuthorizationCode', () => {
5254
});
5355
assert.deepEqual(res, {
5456
access_token: MOCK_ACCESS_TOKEN,
57+
user: MOCK_USER_ID,
5558
scope: '',
5659
token_type: 'bearer',
5760
expires_in: 123,

0 commit comments

Comments
 (0)