@@ -13,62 +13,64 @@ const TokenHandler = require('./handlers/token-handler');
1313 * Constructor.
1414 */
1515
16- function OAuth2Server ( options ) {
17- options = options || { } ;
16+ class OAuth2Server {
17+ constructor ( options ) {
18+ options = options || { } ;
1819
19- if ( ! options . model ) {
20- throw new InvalidArgumentError ( 'Missing parameter: `model`' ) ;
21- }
20+ if ( ! options . model ) {
21+ throw new InvalidArgumentError ( 'Missing parameter: `model`' ) ;
22+ }
2223
23- this . options = options ;
24- }
24+ this . options = options ;
25+ }
2526
26- /**
27+ /**
2728 * Authenticate a token.
2829 * Note, that callback will soon be deprecated!
2930 */
3031
31- OAuth2Server . prototype . authenticate = function ( request , response , options ) {
32- if ( typeof options === 'string' ) {
33- options = { scope : options } ;
34- }
32+ authenticate ( request , response , options ) {
33+ if ( typeof options === 'string' ) {
34+ options = { scope : options } ;
35+ }
3536
36- options = Object . assign ( {
37- addAcceptedScopesHeader : true ,
38- addAuthorizedScopesHeader : true ,
39- allowBearerTokensInQueryString : false
40- } , this . options , options ) ;
37+ options = Object . assign ( {
38+ addAcceptedScopesHeader : true ,
39+ addAuthorizedScopesHeader : true ,
40+ allowBearerTokensInQueryString : false
41+ } , this . options , options ) ;
4142
42- return new AuthenticateHandler ( options ) . handle ( request , response ) ;
43- } ;
43+ return new AuthenticateHandler ( options ) . handle ( request , response ) ;
44+ }
4445
45- /**
46+ /**
4647 * Authorize a request.
4748 */
4849
49- OAuth2Server . prototype . authorize = function ( request , response , options ) {
50- options = Object . assign ( {
51- allowEmptyState : false ,
52- authorizationCodeLifetime : 5 * 60 // 5 minutes.
53- } , this . options , options ) ;
50+ authorize ( request , response , options ) {
51+ options = Object . assign ( {
52+ allowEmptyState : false ,
53+ authorizationCodeLifetime : 5 * 60 // 5 minutes.
54+ } , this . options , options ) ;
5455
55- return new AuthorizeHandler ( options ) . handle ( request , response ) ;
56- } ;
56+ return new AuthorizeHandler ( options ) . handle ( request , response ) ;
57+ }
5758
58- /**
59+ /**
5960 * Create a token.
6061 */
6162
62- OAuth2Server . prototype . token = function ( request , response , options ) {
63- options = Object . assign ( {
64- accessTokenLifetime : 60 * 60 , // 1 hour.
65- refreshTokenLifetime : 60 * 60 * 24 * 14 , // 2 weeks.
66- allowExtendedTokenAttributes : false ,
67- requireClientAuthentication : { } // defaults to true for all grant types
68- } , this . options , options ) ;
63+ token ( request , response , options ) {
64+ options = Object . assign ( {
65+ accessTokenLifetime : 60 * 60 , // 1 hour.
66+ refreshTokenLifetime : 60 * 60 * 24 * 14 , // 2 weeks.
67+ allowExtendedTokenAttributes : false ,
68+ requireClientAuthentication : { } // defaults to true for all grant types
69+ } , this . options , options ) ;
6970
70- return new TokenHandler ( options ) . handle ( request , response ) ;
71- } ;
71+ return new TokenHandler ( options ) . handle ( request , response ) ;
72+ }
73+ }
7274
7375/**
7476 * Export constructor.
0 commit comments