@@ -114,8 +114,10 @@ AuthorizeHandler.prototype.handle = function(request, response) {
114114 } )
115115 . then ( function ( authorizationCode ) {
116116 ResponseType = this . getResponseType ( request ) ;
117+ const codeChallenge = this . getCodeChallenge ( request ) ;
118+ const codeChallengeMethod = this . getCodeChallengeMethod ( request ) ;
117119
118- return this . saveAuthorizationCode ( authorizationCode , expiresAt , scope , client , uri , user ) ;
120+ return this . saveAuthorizationCode ( authorizationCode , expiresAt , scope , client , uri , user , codeChallenge , codeChallengeMethod ) ;
119121 } )
120122 . then ( function ( code ) {
121123 const responseType = new ResponseType ( code . authorizationCode ) ;
@@ -293,13 +295,20 @@ AuthorizeHandler.prototype.getRedirectUri = function(request, client) {
293295 * Save authorization code.
294296 */
295297
296- AuthorizeHandler . prototype . saveAuthorizationCode = function ( authorizationCode , expiresAt , scope , client , redirectUri , user ) {
297- const code = {
298+ AuthorizeHandler . prototype . saveAuthorizationCode = function ( authorizationCode , expiresAt , scope , client , redirectUri , user , codeChallenge , codeChallengeMethod ) {
299+ let code = {
298300 authorizationCode : authorizationCode ,
299301 expiresAt : expiresAt ,
300302 redirectUri : redirectUri ,
301303 scope : scope
302304 } ;
305+
306+ if ( codeChallenge && codeChallengeMethod ) {
307+ code = Object . assign ( {
308+ codeChallenge : codeChallenge ,
309+ codeChallengeMethod : codeChallengeMethod
310+ } , code ) ;
311+ }
303312 return promisify ( this . model . saveAuthorizationCode , 3 ) . call ( this . model , code , client , user ) ;
304313} ;
305314
@@ -369,6 +378,18 @@ AuthorizeHandler.prototype.updateResponse = function(response, redirectUri, stat
369378 response . redirect ( url . format ( redirectUri ) ) ;
370379} ;
371380
381+ AuthorizeHandler . prototype . getCodeChallenge = function ( request ) {
382+ return request . body . code_challenge ;
383+ } ;
384+
385+ /**
386+ * Get code challenge method from request or defaults to plain.
387+ * https://www.rfc-editor.org/rfc/rfc7636#section-4.3
388+ */
389+ AuthorizeHandler . prototype . getCodeChallengeMethod = function ( request ) {
390+ return request . body . code_challenge_method || 'plain' ;
391+ } ;
392+
372393/**
373394 * Export constructor.
374395 */
0 commit comments