Skip to content

Commit f3d77ad

Browse files
committed
fix: support number and strings for id params but pass original params to model
1 parent 11de06a commit f3d77ad

5 files changed

Lines changed: 11 additions & 4 deletions

File tree

lib/grant-types/authorization-code-grant-type.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,15 @@ class AuthorizationCodeGrantType extends AbstractGrantType {
8484
throw new InvalidRequestError('Invalid parameter: `code`');
8585
}
8686

87+
// normalize string|number to string
8788
const requestCode = toString(request.body.code);
8889

8990
if (!isFormat.vschar(requestCode)) {
9091
throw new InvalidRequestError('Invalid parameter: `code`');
9192
}
9293

93-
const code = await this.model.getAuthorizationCode(requestCode);
94+
// XXX: still passing the original value from request to model
95+
const code = await this.model.getAuthorizationCode(request.body.code);
9496

9597
if (!code) {
9698
throw new InvalidGrantError('Invalid grant: authorization code is invalid');

lib/grant-types/refresh-token-grant-type.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class RefreshTokenGrantType extends AbstractGrantType {
8181
throw new InvalidRequestError('Invalid parameter: `refresh_token`');
8282
}
8383

84-
const token = await this.model.getRefreshToken(refreshToken);
84+
const token = await this.model.getRefreshToken(request.body.refresh_token);
8585

8686
if (!token) {
8787
throw new InvalidGrantError('Invalid grant: refresh token is invalid');

lib/handlers/authorize-handler.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ class AuthorizeHandler {
173173

174174
const redirectUri = request.body.redirect_uri || request.query.redirect_uri;
175175

176+
// XXX: why is there no 'Missing parameter: `redirect_uri`' error?
176177
if (isDefined(redirectUri) && (!isString(redirectUri) || !isFormat.uri(redirectUri))) {
177178
throw new InvalidRequestError('Invalid request: `redirect_uri` is not a valid URI');
178179
}

lib/handlers/token-handler.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ const UnsupportedGrantTypeError = require('../errors/unsupported-grant-type-erro
1818
const auth = require('basic-auth');
1919
const pkce = require('../pkce/pkce');
2020
const isFormat = require('@node-oauth/formats');
21+
const { isInTypes, toString } = require('../utils/param-util');
22+
const isStringOrNumber = isInTypes('string', 'number');
2123

2224
/**
2325
* Grant types.
@@ -123,7 +125,7 @@ class TokenHandler {
123125
throw new InvalidRequestError('Missing parameter: `client_secret`');
124126
}
125127

126-
if (!isFormat.vschar(credentials.clientId)) {
128+
if (!isStringOrNumber(credentials.clientId) || !isFormat.vschar(toString(credentials.clientId))) {
127129
throw new InvalidRequestError('Invalid parameter: `client_id`');
128130
}
129131

lib/utils/scope-util.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
const isFormat = require('@node-oauth/formats');
22
const InvalidScopeError = require('../errors/invalid-scope-error');
3+
const { isInTypes } = require('../utils/param-util');
34
const whiteSpace = /\s+/g;
5+
const isString = isInTypes('string');
46

57
/**
68
* @module ScopeUtil
@@ -22,7 +24,7 @@ function parseScope (requestedScope) {
2224
return undefined;
2325
}
2426

25-
if (typeof requestedScope !== 'string') {
27+
if (!isString(requestedScope)) {
2628
throw new InvalidScopeError('Invalid parameter: `scope`');
2729
}
2830

0 commit comments

Comments
 (0)