File tree Expand file tree Collapse file tree 3 files changed +28
-2
lines changed Expand file tree Collapse file tree 3 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -37,10 +37,11 @@ ExpressOAuthServer.prototype.authenticate = function() {
3737
3838 return function ( req , res , next ) {
3939 var request = new Request ( req ) ;
40+ var response = new Response ( res ) ;
4041
4142 return Promise . bind ( this )
4243 . then ( function ( ) {
43- return server . authenticate ( request ) ;
44+ return server . authenticate ( request , response ) ;
4445 } )
4546 . tap ( function ( token ) {
4647 req . app . locals . oauth = { token : token } ;
Original file line number Diff line number Diff line change @@ -55,6 +55,30 @@ describe('ExpressOAuthServer', function() {
5555 . expect ( { error : 'invalid_argument' , error_description : 'Invalid argument: model does not implement `getAccessToken()`' } )
5656 . end ( done ) ;
5757 } ) ;
58+
59+ it ( 'should authenticate the request' , function ( done ) {
60+ var token = { user : { } } ;
61+ var model = {
62+ getAccessToken : function ( ) {
63+ return token ;
64+ }
65+ } ;
66+ var oauth = new ExpressOAuthServer ( { model : model } ) ;
67+
68+ app . use ( oauth . authenticate ( ) ) ;
69+
70+ app . use ( function ( req , res , next ) {
71+ res . send ( ) ;
72+
73+ next ( ) ;
74+ } ) ;
75+
76+ request ( app . listen ( ) )
77+ . get ( '/' )
78+ . set ( 'Authorization' , 'Bearer foobar' )
79+ . expect ( 200 )
80+ . end ( done ) ;
81+ } ) ;
5882 } ) ;
5983
6084 describe ( 'authorize()' , function ( ) {
Original file line number Diff line number Diff line change @@ -33,8 +33,9 @@ describe('ExpressOAuthServer', function() {
3333 . get ( '/' )
3434 . end ( function ( ) {
3535 oauth . server . authenticate . callCount . should . equal ( 1 ) ;
36- oauth . server . authenticate . firstCall . args . should . have . length ( 1 ) ;
36+ oauth . server . authenticate . firstCall . args . should . have . length ( 2 ) ;
3737 oauth . server . authenticate . firstCall . args [ 0 ] . should . be . an . instanceOf ( Request ) ;
38+ oauth . server . authenticate . firstCall . args [ 1 ] . should . be . an . instanceOf ( Response ) ;
3839 oauth . server . authenticate . restore ( ) ;
3940
4041 done ( ) ;
You can’t perform that action at this time.
0 commit comments