@@ -19,6 +19,7 @@ const UnauthorizedClientError = require('../errors/unauthorized-client-error');
1919const UnsupportedGrantTypeError = require ( '../errors/unsupported-grant-type-error' ) ;
2020const auth = require ( 'basic-auth' ) ;
2121const is = require ( '../validator/is' ) ;
22+ const pkce = require ( '../pkce/pkce' ) ;
2223
2324/**
2425 * Grant types.
@@ -114,12 +115,14 @@ TokenHandler.prototype.handle = function(request, response) {
114115TokenHandler . prototype . getClient = function ( request , response ) {
115116 const credentials = this . getClientCredentials ( request ) ;
116117 const grantType = request . body . grant_type ;
118+ const codeVerifier = request . body . code_verifier ;
119+ const isPkce = pkce . isPKCERequest ( { grantType, codeVerifier } ) ;
117120
118121 if ( ! credentials . clientId ) {
119122 throw new InvalidRequestError ( 'Missing parameter: `client_id`' ) ;
120123 }
121124
122- if ( this . isClientAuthenticationRequired ( grantType ) && ! credentials . clientSecret ) {
125+ if ( this . isClientAuthenticationRequired ( grantType ) && ! credentials . clientSecret && ! isPkce ) {
123126 throw new InvalidRequestError ( 'Missing parameter: `client_secret`' ) ;
124127 }
125128
@@ -174,6 +177,7 @@ TokenHandler.prototype.getClient = function(request, response) {
174177TokenHandler . prototype . getClientCredentials = function ( request ) {
175178 const credentials = auth ( request ) ;
176179 const grantType = request . body . grant_type ;
180+ const codeVerifier = request . body . code_verifier ;
177181
178182 if ( credentials ) {
179183 return { clientId : credentials . name , clientSecret : credentials . pass } ;
@@ -183,6 +187,12 @@ TokenHandler.prototype.getClientCredentials = function(request) {
183187 return { clientId : request . body . client_id , clientSecret : request . body . client_secret } ;
184188 }
185189
190+ if ( pkce . isPKCERequest ( { grantType, codeVerifier } ) ) {
191+ if ( request . body . client_id ) {
192+ return { clientId : request . body . client_id } ;
193+ }
194+ }
195+
186196 if ( ! this . isClientAuthenticationRequired ( grantType ) ) {
187197 if ( request . body . client_id ) {
188198 return { clientId : request . body . client_id } ;
0 commit comments