File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -75,12 +75,14 @@ class RefreshTokenGrantType extends AbstractGrantType {
7575 throw new InvalidRequestError ( 'Invalid parameter: `refresh_token`' ) ;
7676 }
7777
78+ // normalize string|number to string
7879 const refreshToken = toString ( request . body . refresh_token ) ;
7980
8081 if ( ! isFormat . vschar ( refreshToken ) ) {
8182 throw new InvalidRequestError ( 'Invalid parameter: `refresh_token`' ) ;
8283 }
8384
85+ // XXX: still passing the original value from request to model
8486 const token = await this . model . getRefreshToken ( request . body . refresh_token ) ;
8587
8688 if ( ! token ) {
Original file line number Diff line number Diff line change @@ -129,7 +129,7 @@ class TokenHandler {
129129 throw new InvalidRequestError ( 'Invalid parameter: `client_id`' ) ;
130130 }
131131
132- if ( credentials . clientSecret && ! isFormat . vschar ( credentials . clientSecret ) ) {
132+ if ( credentials . clientSecret && ( ! isStringOrNumber ( credentials . clientSecret ) || ! isFormat . vschar ( toString ( credentials . clientSecret ) ) ) ) {
133133 throw new InvalidRequestError ( 'Invalid parameter: `client_secret`' ) ;
134134 }
135135
Original file line number Diff line number Diff line change @@ -36,19 +36,25 @@ function isDefined (value) {
3636 * @return {string }
3737 */
3838function toString ( value ) {
39- if ( typeof value === 'string' ) {
39+ const type = typeof value ;
40+ if ( type === 'string' ) {
4041 return value ;
4142 }
4243
43- if ( Object . prototype . hasOwnProperty . call ( value , 'toString' ) ) {
44- return value . toString ( ) ;
44+ if ( type === 'undefined' || value === null ) {
45+ throw new TypeError ( `Cannot convert ${ value } to a string` ) ;
4546 }
4647
47- if ( value === null || value === undefined ) {
48- return '' ;
48+ if ( type === 'number' || type === 'bigint' ) {
49+ const val = String ( value ) ;
50+ if ( val === 'NaN' || val === 'Infinity' || val === '-Infinity' ) {
51+ throw new TypeError ( `Invalid numeric value ${ value } , cannot be converted to a string (${ val } )` ) ;
52+ }
53+ return val ;
4954 }
5055
51- return String ( value ) ;
56+
57+ throw new TypeError ( `Cannot convert value ${ value } of type ${ type } to a string` ) ;
5258}
5359
5460module . exports = { isInTypes, isDefined, toString } ;
You can’t perform that action at this time.
0 commit comments