11const debug = require ( 'debug' ) ( 'oauth:routes' ) ;
2- const param = require ( '@cesine/swagger-node-express/Common/node/paramTypes.js ' ) ;
2+ const param = require ( '@cesine/swagger-node-express/Common/node/paramTypes' ) ;
33const querystring = require ( 'querystring' ) ;
44
5- const errorMiddleware = require ( '../middleware/error-handler' ) . errorHandler ;
65const oauth = require ( '../middleware/oauth' ) ;
76
87/**
@@ -27,7 +26,6 @@ exports.getAuthorize = {
2726 nickname : 'getAuthorize' ,
2827 } ,
2928 action : function getAuthorize ( req , res , next ) {
30- let middleware ;
3129 debug ( 'getAuthorize res.locals' , res . locals ) ;
3230 debug ( 'req.path' , req . path ) ;
3331 debug ( 'req.query' , req . query ) ;
@@ -42,11 +40,13 @@ exports.getAuthorize = {
4240 // https://oauth2-server.readthedocs.io/en/latest/api/oauth2-server.html#authorize-request-response-options-callback
4341 const authenticateHandler = {
4442 handle ( request , response ) {
43+ debug ( 'request' , request ) ;
44+ debug ( 'response' , response ) ;
4545 return res . locals . user ;
4646 } ,
4747 } ;
4848
49- middleware = oauth . authorize ( {
49+ const middleware = oauth . authorize ( {
5050 scope : req . query . scope ,
5151 authenticateHandler,
5252 continueMiddleware : true , // does not call through
@@ -61,6 +61,7 @@ exports.getAuthorize = {
6161 return next ( err ) ;
6262 }
6363 // next(); // cannot set headers after they are set
64+ return null ;
6465 } ) ;
6566 } ,
6667} ;
@@ -86,11 +87,10 @@ exports.postToken = {
8687 nickname : 'postToken' ,
8788 } ,
8889 action : function postToken ( req , res , next ) {
89- let middleware ;
9090 debug ( 'postToken' , req . query , req . body , res . headers ) ;
9191 // req.user = res.locals.user; TODO where does the user that is passed to client come from
9292
93- middleware = oauth . token ( {
93+ const middleware = oauth . token ( {
9494 // continueMiddleware: true,
9595 } ) ;
9696
@@ -103,8 +103,8 @@ exports.postToken = {
103103 }
104104 // TODO this has no effect
105105 // instead working around it by return jwt in saveToken response as accesToken
106- res . set ( 'Authorization' , `Bearer ${ res . locals . oauth . token . jwt } ` ) ;
107-
106+ // res.set('Authorization', `Bearer ${res.locals.oauth.token.jwt}`);
107+ return null ;
108108 // next();
109109 } ) ;
110110 } ,
0 commit comments