Skip to content

Commit ef7b61f

Browse files
committed
fix(core): make formatting line width and array commas on par with original format
1 parent 73fd0f9 commit ef7b61f

39 files changed

Lines changed: 305 additions & 931 deletions

biome.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@
4343
"javascript": {
4444
"formatter": {
4545
"quoteStyle": "single",
46-
"indentStyle": "space"
46+
"indentStyle": "space",
47+
"trailingCommas": "es5",
48+
"lineWidth": 120
4749
}
4850
},
4951
"assist": {

lib/errors/oauth-error.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ class OAuthError extends Error {
1818
constructor(messageOrError, properties) {
1919
super(messageOrError, properties);
2020

21-
let message =
22-
messageOrError instanceof Error ? messageOrError.message : messageOrError;
21+
let message = messageOrError instanceof Error ? messageOrError.message : messageOrError;
2322
const error = messageOrError instanceof Error ? messageOrError : null;
2423

2524
if (properties == null || !Object.entries(properties).length) {

lib/grant-types/abstract-grant-type.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ class AbstractGrantType {
2828
options = options || {};
2929

3030
if (!options.accessTokenLifetime) {
31-
throw new InvalidArgumentError(
32-
'Missing parameter: `accessTokenLifetime`',
33-
);
31+
throw new InvalidArgumentError('Missing parameter: `accessTokenLifetime`');
3432
}
3533

3634
if (!options.model) {
@@ -114,16 +112,10 @@ class AbstractGrantType {
114112
*/
115113
async validateScope(user, client, scope) {
116114
if (this.model.validateScope) {
117-
const validatedScope = await this.model.validateScope(
118-
user,
119-
client,
120-
scope,
121-
);
115+
const validatedScope = await this.model.validateScope(user, client, scope);
122116

123117
if (!validatedScope) {
124-
throw new InvalidScopeError(
125-
'Invalid scope: Requested scope is invalid',
126-
);
118+
throw new InvalidScopeError('Invalid scope: Requested scope is invalid');
127119
}
128120

129121
return validatedScope;

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

Lines changed: 22 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,15 @@ class AuthorizationCodeGrantType extends AbstractGrantType {
2727
}
2828

2929
if (!options.model.getAuthorizationCode) {
30-
throw new InvalidArgumentError(
31-
'Invalid argument: model does not implement `getAuthorizationCode()`',
32-
);
30+
throw new InvalidArgumentError('Invalid argument: model does not implement `getAuthorizationCode()`');
3331
}
3432

3533
if (!options.model.revokeAuthorizationCode) {
36-
throw new InvalidArgumentError(
37-
'Invalid argument: model does not implement `revokeAuthorizationCode()`',
38-
);
34+
throw new InvalidArgumentError('Invalid argument: model does not implement `revokeAuthorizationCode()`');
3935
}
4036

4137
if (!options.model.saveToken) {
42-
throw new InvalidArgumentError(
43-
'Invalid argument: model does not implement `saveToken()`',
44-
);
38+
throw new InvalidArgumentError('Invalid argument: model does not implement `saveToken()`');
4539
}
4640

4741
super(options);
@@ -75,12 +69,7 @@ class AuthorizationCodeGrantType extends AbstractGrantType {
7569
await this.verifyPKCE(request, code);
7670
await this.validateRedirectUri(request, code);
7771

78-
return this.saveToken(
79-
code.user,
80-
client,
81-
code.authorizationCode,
82-
code.scope,
83-
);
72+
return this.saveToken(code.user, client, code.authorizationCode, code.scope);
8473
}
8574

8675
/**
@@ -102,45 +91,31 @@ class AuthorizationCodeGrantType extends AbstractGrantType {
10291
const code = await this.model.getAuthorizationCode(request.body.code);
10392

10493
if (!code) {
105-
throw new InvalidGrantError(
106-
'Invalid grant: authorization code is invalid',
107-
);
94+
throw new InvalidGrantError('Invalid grant: authorization code is invalid');
10895
}
10996

11097
if (!code.client) {
111-
throw new ServerError(
112-
'Server error: `getAuthorizationCode()` did not return a `client` object',
113-
);
98+
throw new ServerError('Server error: `getAuthorizationCode()` did not return a `client` object');
11499
}
115100

116101
if (!code.user) {
117-
throw new ServerError(
118-
'Server error: `getAuthorizationCode()` did not return a `user` object',
119-
);
102+
throw new ServerError('Server error: `getAuthorizationCode()` did not return a `user` object');
120103
}
121104

122105
if (code.client.id !== client.id) {
123-
throw new InvalidGrantError(
124-
'Invalid grant: authorization code is invalid',
125-
);
106+
throw new InvalidGrantError('Invalid grant: authorization code is invalid');
126107
}
127108

128109
if (!(code.expiresAt instanceof Date)) {
129-
throw new ServerError(
130-
'Server error: `expiresAt` must be a Date instance',
131-
);
110+
throw new ServerError('Server error: `expiresAt` must be a Date instance');
132111
}
133112

134113
if (code.expiresAt < new Date()) {
135-
throw new InvalidGrantError(
136-
'Invalid grant: authorization code has expired',
137-
);
114+
throw new InvalidGrantError('Invalid grant: authorization code has expired');
138115
}
139116

140117
if (code.redirectUri && !isFormat.uri(code.redirectUri)) {
141-
throw new InvalidGrantError(
142-
'Invalid grant: `redirect_uri` is not a valid URI',
143-
);
118+
throw new InvalidGrantError('Invalid grant: `redirect_uri` is not a valid URI');
144119
}
145120

146121
return code;
@@ -163,9 +138,7 @@ class AuthorizationCodeGrantType extends AbstractGrantType {
163138
const method = this.getCodeChallengeMethod(code.codeChallengeMethod);
164139

165140
if (!this.enablePlainPKCE && method === 'plain') {
166-
throw new InvalidRequestError(
167-
'Invalid request: `code_challenge_method` "plain" is not allowed; use "S256"',
168-
);
141+
throw new InvalidRequestError('Invalid request: `code_challenge_method` "plain" is not allowed; use "S256"');
169142
}
170143

171144
if (!request.body.code_verifier) {
@@ -182,9 +155,7 @@ class AuthorizationCodeGrantType extends AbstractGrantType {
182155
});
183156

184157
if (!hash) {
185-
throw new ServerError(
186-
'Server error: no valid hash algorithm available to verify `code_verifier`',
187-
);
158+
throw new ServerError('Server error: no valid hash algorithm available to verify `code_verifier`');
188159
}
189160

190161
// xxx: Use timingSafeEqual to prevent against timing attacks when comparing
@@ -201,21 +172,12 @@ class AuthorizationCodeGrantType extends AbstractGrantType {
201172
}
202173

203174
hashesAreEqual(trusted, untrusted) {
204-
const trustedBuf = Buffer.isBuffer(trusted)
205-
? trusted
206-
: Buffer.from(trusted);
207-
const untrustedBuf = Buffer.isBuffer(untrusted)
208-
? untrusted
209-
: Buffer.from(untrusted);
175+
const trustedBuf = Buffer.isBuffer(trusted) ? trusted : Buffer.from(trusted);
176+
const untrustedBuf = Buffer.isBuffer(untrusted) ? untrusted : Buffer.from(untrusted);
210177
const equalLength = trustedBuf.byteLength === untrustedBuf.byteLength;
211178
// if the buffers are the same length, compare them,
212179
// otherwise only compare with the trusted buffer but return false anyway
213-
return (
214-
crypto.timingSafeEqual(
215-
trustedBuf,
216-
equalLength ? untrustedBuf : trustedBuf,
217-
) && equalLength
218-
);
180+
return crypto.timingSafeEqual(trustedBuf, equalLength ? untrustedBuf : trustedBuf) && equalLength;
219181
}
220182

221183
getCodeChallengeMethod(method) {
@@ -247,15 +209,11 @@ class AuthorizationCodeGrantType extends AbstractGrantType {
247209
const redirectUri = request.body.redirect_uri || request.query.redirect_uri;
248210

249211
if (!isFormat.uri(redirectUri)) {
250-
throw new InvalidRequestError(
251-
'Invalid request: `redirect_uri` is not a valid URI',
252-
);
212+
throw new InvalidRequestError('Invalid request: `redirect_uri` is not a valid URI');
253213
}
254214

255215
if (redirectUri !== code.redirectUri) {
256-
throw new InvalidRequestError(
257-
'Invalid request: `redirect_uri` is invalid',
258-
);
216+
throw new InvalidRequestError('Invalid request: `redirect_uri` is invalid');
259217
}
260218
}
261219

@@ -273,9 +231,7 @@ class AuthorizationCodeGrantType extends AbstractGrantType {
273231
const status = await this.model.revokeAuthorizationCode(code);
274232

275233
if (!status) {
276-
throw new InvalidGrantError(
277-
'Invalid grant: authorization code is invalid',
278-
);
234+
throw new InvalidGrantError('Invalid grant: authorization code is invalid');
279235
}
280236

281237
return code;
@@ -292,21 +248,9 @@ class AuthorizationCodeGrantType extends AbstractGrantType {
292248
*/
293249

294250
async saveToken(user, client, authorizationCode, requestedScope) {
295-
const validatedScope = await this.validateScope(
296-
user,
297-
client,
298-
requestedScope,
299-
);
300-
const accessToken = await this.generateAccessToken(
301-
client,
302-
user,
303-
validatedScope,
304-
);
305-
const refreshToken = await this.generateRefreshToken(
306-
client,
307-
user,
308-
validatedScope,
309-
);
251+
const validatedScope = await this.validateScope(user, client, requestedScope);
252+
const accessToken = await this.generateAccessToken(client, user, validatedScope);
253+
const refreshToken = await this.generateRefreshToken(client, user, validatedScope);
310254
const accessTokenExpiresAt = await this.getAccessTokenExpiresAt();
311255
const refreshTokenExpiresAt = await this.getRefreshTokenExpiresAt();
312256

lib/grant-types/client-credentials-grant-type.js

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,11 @@ class ClientCredentialsGrantType extends AbstractGrantType {
1919
}
2020

2121
if (!options.model.getUserFromClient) {
22-
throw new InvalidArgumentError(
23-
'Invalid argument: model does not implement `getUserFromClient()`',
24-
);
22+
throw new InvalidArgumentError('Invalid argument: model does not implement `getUserFromClient()`');
2523
}
2624

2725
if (!options.model.saveToken) {
28-
throw new InvalidArgumentError(
29-
'Invalid argument: model does not implement `saveToken()`',
30-
);
26+
throw new InvalidArgumentError('Invalid argument: model does not implement `saveToken()`');
3127
}
3228

3329
super(options);
@@ -62,9 +58,7 @@ class ClientCredentialsGrantType extends AbstractGrantType {
6258
const user = await this.model.getUserFromClient(client);
6359

6460
if (!user) {
65-
throw new InvalidGrantError(
66-
'Invalid grant: user credentials are invalid',
67-
);
61+
throw new InvalidGrantError('Invalid grant: user credentials are invalid');
6862
}
6963

7064
return user;
@@ -75,21 +69,9 @@ class ClientCredentialsGrantType extends AbstractGrantType {
7569
*/
7670

7771
async saveToken(user, client, requestedScope) {
78-
const validatedScope = await this.validateScope(
79-
user,
80-
client,
81-
requestedScope,
82-
);
83-
const accessToken = await this.generateAccessToken(
84-
client,
85-
user,
86-
validatedScope,
87-
);
88-
const accessTokenExpiresAt = await this.getAccessTokenExpiresAt(
89-
client,
90-
user,
91-
validatedScope,
92-
);
72+
const validatedScope = await this.validateScope(user, client, requestedScope);
73+
const accessToken = await this.generateAccessToken(client, user, validatedScope);
74+
const accessTokenExpiresAt = await this.getAccessTokenExpiresAt(client, user, validatedScope);
9375
const token = {
9476
accessToken,
9577
accessTokenExpiresAt,

lib/grant-types/password-grant-type.js

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,11 @@ class PasswordGrantType extends AbstractGrantType {
2222
}
2323

2424
if (!options.model.getUser) {
25-
throw new InvalidArgumentError(
26-
'Invalid argument: model does not implement `getUser()`',
27-
);
25+
throw new InvalidArgumentError('Invalid argument: model does not implement `getUser()`');
2826
}
2927

3028
if (!options.model.saveToken) {
31-
throw new InvalidArgumentError(
32-
'Invalid argument: model does not implement `saveToken()`',
33-
);
29+
throw new InvalidArgumentError('Invalid argument: model does not implement `saveToken()`');
3430
}
3531

3632
super(options);
@@ -78,16 +74,10 @@ class PasswordGrantType extends AbstractGrantType {
7874
throw new InvalidRequestError('Invalid parameter: `password`');
7975
}
8076

81-
const user = await this.model.getUser(
82-
request.body.username,
83-
request.body.password,
84-
client,
85-
);
77+
const user = await this.model.getUser(request.body.username, request.body.password, client);
8678

8779
if (!user) {
88-
throw new InvalidGrantError(
89-
'Invalid grant: user credentials are invalid',
90-
);
80+
throw new InvalidGrantError('Invalid grant: user credentials are invalid');
9181
}
9282

9383
return user;
@@ -98,21 +88,9 @@ class PasswordGrantType extends AbstractGrantType {
9888
*/
9989

10090
async saveToken(user, client, requestedScope) {
101-
const validatedScope = await this.validateScope(
102-
user,
103-
client,
104-
requestedScope,
105-
);
106-
const accessToken = await this.generateAccessToken(
107-
client,
108-
user,
109-
validatedScope,
110-
);
111-
const refreshToken = await this.generateRefreshToken(
112-
client,
113-
user,
114-
validatedScope,
115-
);
91+
const validatedScope = await this.validateScope(user, client, requestedScope);
92+
const accessToken = await this.generateAccessToken(client, user, validatedScope);
93+
const refreshToken = await this.generateRefreshToken(client, user, validatedScope);
11694
const accessTokenExpiresAt = await this.getAccessTokenExpiresAt();
11795
const refreshTokenExpiresAt = await this.getRefreshTokenExpiresAt();
11896

0 commit comments

Comments
 (0)