-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathaccess-token.test.js
More file actions
875 lines (743 loc) · 24.1 KB
/
Copy pathaccess-token.test.js
File metadata and controls
875 lines (743 loc) · 24.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
// Copyright IBM Corp. 2013,2019. All Rights Reserved.
// Node module: loopback
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
'use strict';
const assert = require('assert');
const expect = require('./helpers/expect');
const cookieParser = require('cookie-parser');
const LoopBackContext = require('loopback-context');
const contextMiddleware = require('loopback-context').perRequest;
const loopback = require('../');
const extend = require('util')._extend;
const session = require('express-session');
const request = require('supertest');
let Token, ACL, User, TestModel;
describe('loopback.token(options)', function() {
let app;
beforeEach(function(done) {
app = loopback({localRegistry: true, loadBuiltinModels: true});
app.dataSource('db', {connector: 'memory'});
ACL = app.registry.getModel('ACL');
app.model(ACL, {dataSource: 'db'});
User = app.registry.getModel('User');
app.model(User, {dataSource: 'db'});
Token = app.registry.createModel({
name: 'MyToken',
base: 'AccessToken',
});
app.model(Token, {dataSource: 'db'});
TestModel = app.registry.createModel({
name: 'TestModel',
base: 'Model',
});
TestModel.getToken = function(options, cb) {
cb(null, options && options.accessToken || null);
};
TestModel.remoteMethod('getToken', {
accepts: {arg: 'options', type: 'object', http: 'optionsFromRequest'},
returns: {arg: 'token', type: 'object'},
http: {verb: 'GET', path: '/token'},
});
app.model(TestModel, {dataSource: 'db'});
createTestingToken.call(this, done);
});
it('defaults to built-in AccessToken model', function() {
const BuiltInToken = app.registry.getModel('AccessToken');
app.model(BuiltInToken, {dataSource: 'db'});
app.enableAuth({dataSource: 'db'});
app.use(loopback.token());
app.use(loopback.rest());
return BuiltInToken.create({userId: 123}).then(function(token) {
return request(app)
.get('/TestModels/token?_format=json')
.set('authorization', token.id)
.expect(200)
.expect('Content-Type', /json/)
.then(res => {
expect(res.body.token.id).to.eql(token.id);
});
});
});
it('uses correct custom AccessToken model from model class param', function() {
User.hasMany(Token, {
as: 'accessTokens',
options: {disableInclude: true},
});
app.enableAuth();
app.use(loopback.token({model: Token}));
app.use(loopback.rest());
return Token.create({userId: 123}).then(function(token) {
return request(app)
.get('/TestModels/token?_format=json')
.set('authorization', token.id)
.expect(200)
.expect('Content-Type', /json/)
.then(res => {
expect(res.body.token.id).to.eql(token.id);
});
});
});
it('uses correct custom AccessToken model from string param', function() {
User.hasMany(Token, {
as: 'accessTokens',
options: {disableInclude: true},
});
app.enableAuth();
app.use(loopback.token({model: Token.modelName}));
app.use(loopback.rest());
return Token.create({userId: 123}).then(function(token) {
return request(app)
.get('/TestModels/token?_format=json')
.set('authorization', token.id)
.expect(200)
.expect('Content-Type', /json/)
.then(res => {
expect(res.body.token.id).to.eql(token.id);
});
});
});
it('populates req.token from the query string', function(done) {
createTestAppAndRequest(this.token, done)
.get('/?access_token=' + this.token.id)
.expect(200)
.end(done);
});
it('populates req.token from an authorization header', function(done) {
createTestAppAndRequest(this.token, done)
.get('/')
.set('authorization', this.token.id)
.expect(200)
.end(done);
});
it('populates req.token from an X-Access-Token header', function(done) {
createTestAppAndRequest(this.token, done)
.get('/')
.set('X-Access-Token', this.token.id)
.expect(200)
.end(done);
});
it('does not search default keys when searchDefaultTokenKeys is false',
function(done) {
const tokenId = this.token.id;
const app = createTestApp(
this.token,
{token: {searchDefaultTokenKeys: false}},
done,
);
const agent = request.agent(app);
// Set the token cookie
agent.get('/token').expect(200).end(function(err, res) {
if (err) return done(err);
// Make a request that sets the token in all places searched by default
agent.get('/check-access?access_token=' + tokenId)
.set('X-Access-Token', tokenId)
.set('authorization', tokenId)
// Expect 401 because there is no (non-default) place configured where
// the middleware should load the token from
.expect(401)
.end(done);
});
});
it('populates req.token from an authorization header with bearer token with base64',
function(done) {
let token = this.token.id;
token = 'Bearer ' + new Buffer(token).toString('base64');
createTestAppAndRequest(this.token, done)
.get('/')
.set('authorization', token)
.expect(200)
.end(done);
});
it('populates req.token from an authorization header with bearer token', function(done) {
let token = this.token.id;
token = 'Bearer ' + token;
createTestAppAndRequest(this.token, {token: {bearerTokenBase64Encoded: false}}, done)
.get('/')
.set('authorization', token)
.expect(200)
.end(done);
});
describe('populating req.token from HTTP Basic Auth formatted authorization header', function() {
it('parses "standalone-token"', function(done) {
let token = this.token.id;
token = 'Basic ' + new Buffer(token).toString('base64');
createTestAppAndRequest(this.token, done)
.get('/')
.set('authorization', this.token.id)
.expect(200)
.end(done);
});
it('parses "token-and-empty-password:"', function(done) {
let token = this.token.id + ':';
token = 'Basic ' + new Buffer(token).toString('base64');
createTestAppAndRequest(this.token, done)
.get('/')
.set('authorization', this.token.id)
.expect(200)
.end(done);
});
it('parses "ignored-user:token-is-password"', function(done) {
let token = 'username:' + this.token.id;
token = 'Basic ' + new Buffer(token).toString('base64');
createTestAppAndRequest(this.token, done)
.get('/')
.set('authorization', this.token.id)
.expect(200)
.end(done);
});
it('parses "token-is-username:ignored-password"', function(done) {
let token = this.token.id + ':password';
token = 'Basic ' + new Buffer(token).toString('base64');
createTestAppAndRequest(this.token, done)
.get('/')
.set('authorization', this.token.id)
.expect(200)
.end(done);
});
});
it('populates req.token from a secure cookie', function(done) {
const app = createTestApp(this.token, done);
request(app)
.get('/token')
.end(function(err, res) {
request(app)
.get('/')
.set('Cookie', res.header['set-cookie'])
.end(done);
});
});
it('populates req.token from a header or a secure cookie', function(done) {
const app = createTestApp(this.token, done);
const id = this.token.id;
request(app)
.get('/token')
.end(function(err, res) {
request(app)
.get('/')
.set('authorization', id)
.set('Cookie', res.header['set-cookie'])
.end(done);
});
});
it('rewrites url for the current user literal at the end without query',
function(done) {
const app = createTestApp(this.token, done);
const id = this.token.id;
const userId = this.token.userId;
request(app)
.get('/users/me')
.set('authorization', id)
.end(function(err, res) {
assert(!err);
assert.deepEqual(res.body, {userId: userId});
done();
});
});
it('rewrites url for the current user literal at the end with query',
function(done) {
const app = createTestApp(this.token, done);
const id = this.token.id;
const userId = this.token.userId;
request(app)
.get('/users/me?state=1')
.set('authorization', id)
.end(function(err, res) {
assert(!err);
assert.deepEqual(res.body, {userId: userId, state: 1});
done();
});
});
it('rewrites url for the current user literal in the middle',
function(done) {
const app = createTestApp(this.token, done);
const id = this.token.id;
const userId = this.token.userId;
request(app)
.get('/users/me/1')
.set('authorization', id)
.end(function(err, res) {
assert(!err);
assert.deepEqual(res.body, {userId: userId, state: 1});
done();
});
});
it('generates a 401 on a current user literal route without an authToken',
function(done) {
const app = createTestApp(null, done);
request(app)
.get('/users/me')
.set('authorization', null)
.expect(401)
.end(done);
});
it('generates a 401 on a current user literal route with empty authToken',
function(done) {
const app = createTestApp(null, done);
request(app)
.get('/users/me')
.set('authorization', '')
.expect(401)
.end(done);
});
it('generates a 401 on a current user literal route with invalid authToken',
function(done) {
const app = createTestApp(this.token, done);
request(app)
.get('/users/me')
.set('Authorization', 'invald-token-id')
.expect(401)
.end(done);
});
it('skips when req.token is already present', function(done) {
const tokenStub = {id: 'stub id'};
app.use(function(req, res, next) {
req.accessToken = tokenStub;
next();
});
app.use(loopback.token({model: Token}));
app.get('/', function(req, res, next) {
res.send(req.accessToken);
});
request(app).get('/')
.set('Authorization', this.token.id)
.expect(200)
.end(function(err, res) {
if (err) return done(err);
expect(res.body).to.eql(tokenStub);
done();
});
});
describe('loading multiple instances of token middleware', function() {
it('skips when req.token is already present and no further options are set',
function(done) {
const tokenStub = {id: 'stub id'};
app.use(function(req, res, next) {
req.accessToken = tokenStub;
next();
});
app.use(loopback.token({model: Token}));
app.get('/', function(req, res, next) {
res.send(req.accessToken);
});
request(app).get('/')
.set('Authorization', this.token.id)
.expect(200)
.end(function(err, res) {
if (err) return done(err);
expect(res.body).to.eql(tokenStub);
done();
});
});
it('does not overwrite valid existing token (has "id" property) ' +
' when overwriteExistingToken is falsy',
function(done) {
const tokenStub = {id: 'stub id'};
app.use(function(req, res, next) {
req.accessToken = tokenStub;
next();
});
app.use(loopback.token({
model: Token,
enableDoublecheck: true,
}));
app.get('/', function(req, res, next) {
res.send(req.accessToken);
});
request(app).get('/')
.set('Authorization', this.token.id)
.expect(200)
.end(function(err, res) {
if (err) return done(err);
expect(res.body).to.eql(tokenStub);
done();
});
});
it('overwrites invalid existing token (is !== undefined and has no "id" property) ' +
' when enableDoublecheck is true',
function(done) {
const token = this.token;
app.use(function(req, res, next) {
req.accessToken = null;
next();
});
app.use(loopback.token({
model: Token,
enableDoublecheck: true,
}));
app.get('/', function(req, res, next) {
res.send(req.accessToken);
});
request(app).get('/')
.set('Authorization', token.id)
.expect(200)
.end(function(err, res) {
if (err) return done(err);
expect(res.body).to.eql({
id: token.id,
ttl: token.ttl,
userId: token.userId,
created: token.created.toJSON(),
});
done();
});
});
it('overwrites existing token when enableDoublecheck ' +
'and overwriteExistingToken options are truthy',
function(done) {
const token = this.token;
const tokenStub = {id: 'stub id'};
app.use(function(req, res, next) {
req.accessToken = tokenStub;
next();
});
app.use(loopback.token({
model: Token,
enableDoublecheck: true,
overwriteExistingToken: true,
}));
app.get('/', function(req, res, next) {
res.send(req.accessToken);
});
request(app).get('/')
.set('Authorization', token.id)
.expect(200)
.end(function(err, res) {
if (err) return done(err);
expect(res.body).to.eql({
id: token.id,
ttl: token.ttl,
userId: token.userId,
created: token.created.toJSON(),
});
done();
});
});
});
});
describe('AccessToken', function() {
beforeEach(createTestingToken);
it('has getIdForRequest method', function() {
expect(typeof Token.getIdForRequest).to.eql('function');
});
it('has resolve method', function() {
expect(typeof Token.resolve).to.eql('function');
});
it('generates id automatically', function() {
assert(this.token.id);
assert.equal(this.token.id.length, 64);
});
it('generates created date automatically', function() {
assert(this.token.created);
assert(Object.prototype.toString.call(this.token.created), '[object Date]');
});
describe('.validate()', function() {
it('accepts valid tokens', function(done) {
this.token.validate(function(err, isValid) {
assert(isValid);
done();
});
});
it('rejects eternal TTL by default', function(done) {
this.token.ttl = -1;
this.token.validate(function(err, isValid) {
if (err) return done(err);
expect(isValid, 'isValid').to.equal(false);
done();
});
});
it('allows eternal tokens when enabled by User.allowEternalTokens',
function(done) {
const Token = givenLocalTokenModel();
// Overwrite User settings - enable eternal tokens
Token.app.models.User.settings.allowEternalTokens = true;
Token.create({userId: '123', ttl: -1}, function(err, token) {
if (err) return done(err);
token.validate(function(err, isValid) {
if (err) return done(err);
expect(isValid, 'isValid').to.equal(true);
done();
});
});
});
});
describe('.findForRequest()', function() {
beforeEach(createTestingToken);
it('supports two-arg variant with no options', function(done) {
const expectedTokenId = this.token.id;
const req = mockRequest({
headers: {'authorization': expectedTokenId},
});
Token.findForRequest(req, function(err, token) {
if (err) return done(err);
expect(token.id).to.eql(expectedTokenId);
done();
});
});
it('allows getIdForRequest() to be overridden', function(done) {
const expectedTokenId = this.token.id;
const current = Token.getIdForRequest;
let called = false;
Token.getIdForRequest = function(req, options) {
called = true;
return expectedTokenId;
};
const req = mockRequest({
headers: {'authorization': 'dummy'},
});
Token.findForRequest(req, function(err, token) {
Token.getIdForRequest = current;
if (err) return done(err);
expect(token.id).to.eql(expectedTokenId);
expect(called).to.be.true();
done();
});
});
it('allows resolve() to be overridden', function(done) {
const expectedTokenId = this.token.id;
const current = Token.resolve;
let called = false;
Token.resolve = function(id, cb) {
called = true;
process.nextTick(function() {
cb(null, {id: expectedTokenId});
});
};
const req = mockRequest({
headers: {'authorization': expectedTokenId},
});
Token.findForRequest(req, function(err, token) {
Token.validate = current;
if (err) return done(err);
expect(token.id).to.eql(expectedTokenId);
expect(called).to.be.true();
done();
});
});
function mockRequest(opts) {
return extend(
{
method: 'GET',
url: '/a-test-path',
headers: {},
_params: {},
// express helpers
param: function(name) { return this._params[name]; },
header: function(name) { return this.headers[name]; },
},
opts,
);
}
});
});
describe('app.enableAuth()', function() {
let app;
beforeEach(function setupAuthWithModels() {
app = loopback({localRegistry: true, loadBuiltinModels: true});
app.dataSource('db', {connector: 'memory'});
Token = app.registry.createModel({
name: 'MyToken',
base: 'AccessToken',
});
app.model(Token, {dataSource: 'db'});
ACL = app.registry.getModel('ACL');
// Fix User's "hasMany accessTokens" relation to use our new MyToken model
const User = app.registry.getModel('User');
User.settings.relations.accessTokens.model = 'MyToken';
app.enableAuth({dataSource: 'db'});
});
beforeEach(createTestingToken);
it('prevents remote call with 401 status on denied ACL', function(done) {
createTestAppAndRequest(this.token, done)
.del('/tests/123')
.expect(401)
.set('authorization', this.token.id)
.end(function(err, res) {
if (err) {
return done(err);
}
const errorResponse = res.body.error;
assert(errorResponse);
assert.equal(errorResponse.code, 'AUTHORIZATION_REQUIRED');
done();
});
});
it('denies remote call with app setting status 403', function(done) {
createTestAppAndRequest(this.token, {app: {aclErrorStatus: 403}}, done)
.del('/tests/123')
.expect(403)
.set('authorization', this.token.id)
.end(function(err, res) {
if (err) {
return done(err);
}
const errorResponse = res.body.error;
assert(errorResponse);
assert.equal(errorResponse.code, 'ACCESS_DENIED');
done();
});
});
it('denies remote call with app setting status 404', function(done) {
createTestAppAndRequest(this.token, {model: {aclErrorStatus: 404}}, done)
.del('/tests/123')
.expect(404)
.set('authorization', this.token.id)
.end(function(err, res) {
if (err) {
return done(err);
}
const errorResponse = res.body.error;
assert(errorResponse);
assert.equal(errorResponse.code, 'MODEL_NOT_FOUND');
done();
});
});
it('prevents remote call if the accessToken is missing and required', function(done) {
createTestAppAndRequest(null, done)
.del('/tests/123')
.expect(401)
.set('authorization', null)
.end(function(err, res) {
if (err) {
return done(err);
}
const errorResponse = res.body.error;
assert(errorResponse);
assert.equal(errorResponse.code, 'AUTHORIZATION_REQUIRED');
done();
});
});
it('stores token in the context', function(done) {
const TestModel = app.registry.createModel('TestModel', {base: 'Model'});
TestModel.getToken = function(cb) {
const ctx = LoopBackContext.getCurrentContext();
cb(null, ctx && ctx.get('accessToken') || null);
};
TestModel.remoteMethod('getToken', {
returns: {arg: 'token', type: 'object'},
http: {verb: 'GET', path: '/token'},
});
app.model(TestModel, {dataSource: null});
app.enableAuth();
app.use(contextMiddleware());
app.use(loopback.token({model: Token}));
app.use(loopback.rest());
const token = this.token;
request(app)
.get('/TestModels/token?_format=json')
.set('authorization', token.id)
.expect(200)
.expect('Content-Type', /json/)
.end(function(err, res) {
if (err) return done(err);
expect(res.body.token.id).to.eql(token.id);
done();
});
});
// See https://github.com/strongloop/loopback-context/issues/6
it('checks whether context is active', function(done) {
app.enableAuth();
app.use(contextMiddleware());
app.use(session({
secret: 'kitty',
saveUninitialized: true,
resave: true,
}));
app.use(loopback.token({model: Token}));
app.get('/', function(req, res) { res.send('OK'); });
app.use(loopback.rest());
request(app)
.get('/')
.set('authorization', this.token.id)
.set('cookie', 'connect.sid=s%3AFTyno9_MbGTJuOwdh9bxsYCVxlhlulTZ.' +
'PZvp85jzLXZBCBkhCsSfuUjhij%2Fb0B1K2RYZdxSQU0c')
.expect(200, 'OK')
.end(done);
});
});
function createTestingToken(done) {
const test = this;
Token.create({userId: '123'}, function(err, token) {
if (err) return done(err);
test.token = token;
done();
});
}
function createTestAppAndRequest(testToken, settings, done) {
const app = createTestApp(testToken, settings, done);
return request(app);
}
function createTestApp(testToken, settings, done) {
if (!done && typeof settings === 'function') {
done = settings;
settings = {};
}
const appSettings = settings.app || {};
const modelSettings = settings.model || {};
const tokenSettings = extend({
model: Token,
currentUserLiteral: 'me',
}, settings.token);
const app = loopback({localRegistry: true, loadBuiltinModels: true});
app.dataSource('db', {connector: 'memory'});
app.use(cookieParser('secret'));
app.use(loopback.token(tokenSettings));
app.set('remoting', {errorHandler: {debug: true, log: false}});
app.get('/token', function(req, res) {
res.cookie('authorization', testToken.id, {signed: true});
res.cookie('access_token', testToken.id, {signed: true});
res.end();
});
app.get('/', function(req, res) {
try {
assert(req.accessToken, 'req should have accessToken');
assert(req.accessToken.id === testToken.id);
} catch (e) {
return done(e);
}
res.send('ok');
});
app.get('/check-access', function(req, res) {
res.status(req.accessToken ? 200 : 401).end();
});
app.use('/users/:uid', function(req, res) {
const result = {userId: req.params.uid};
if (req.query.state) {
result.state = req.query.state;
} else if (req.url !== '/') {
result.state = req.url.substring(1);
}
res.status(200).send(result);
});
app.use(loopback.rest());
app.enableAuth({dataSource: 'db'});
Object.keys(appSettings).forEach(function(key) {
app.set(key, appSettings[key]);
});
const modelOptions = {
acls: [
{
principalType: 'ROLE',
principalId: '$everyone',
accessType: ACL.ALL,
permission: ACL.DENY,
property: 'deleteById',
},
],
};
Object.keys(modelSettings).forEach(function(key) {
modelOptions[key] = modelSettings[key];
});
const TestModel = app.registry.createModel('test', {}, modelOptions);
app.model(TestModel, {dataSource: 'db'});
return app;
}
function givenLocalTokenModel() {
const app = loopback({localRegistry: true, loadBuiltinModels: true});
app.dataSource('db', {connector: 'memory'});
const User = app.registry.getModel('User');
app.model(User, {dataSource: 'db'});
const Token = app.registry.getModel('AccessToken');
app.model(Token, {dataSource: 'db'});
return Token;
}