Skip to content

Commit 38295b6

Browse files
committed
Remove trailing whitespace.
1 parent 8b9631d commit 38295b6

File tree

2 files changed

+29
-29
lines changed

2 files changed

+29
-29
lines changed

__tests__/oauth-provider.test.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,7 +1631,7 @@ describe('OAuthProvider', () => {
16311631

16321632
// Verify that the TTL is from the callback, not the default
16331633
expect(newTokens.expires_in).toBe(7200);
1634-
1634+
16351635
// Verify the token contains our custom property
16361636
const apiRequest = createMockRequest(
16371637
'https://example.com/api/test',
@@ -1723,7 +1723,7 @@ describe('OAuthProvider', () => {
17231723
// The props should be the original ones (no change)
17241724
expect(apiData.user).toEqual({ userId: "test-user-123", username: "TestUser" });
17251725
});
1726-
1726+
17271727
it('should correctly handle the previous refresh token when callback updates grant props', async () => {
17281728
// This test verifies fixes for two bugs:
17291729
// 1. previousRefreshTokenWrappedKey not being re-wrapped when grant props change
@@ -1736,7 +1736,7 @@ describe('OAuthProvider', () => {
17361736
...options.props,
17371737
updatedCount: (options.props.updatedCount || 0) + 1
17381738
};
1739-
1739+
17401740
// Only return newProps to test that accessTokenProps will inherit from it
17411741
return {
17421742
// Return new props to trigger the re-encryption with a new key
@@ -1809,7 +1809,7 @@ describe('OAuthProvider', () => {
18091809

18101810
// Reset the callback invocations before refresh
18111811
callCount = 0;
1812-
1812+
18131813
// First refresh - this will update the grant props and re-encrypt them with a new key
18141814
const refreshParams = new URLSearchParams();
18151815
refreshParams.append('grant_type', 'refresh_token');
@@ -1826,13 +1826,13 @@ describe('OAuthProvider', () => {
18261826

18271827
const refreshResponse = await testProvider.fetch(refreshRequest, mockEnv, mockCtx);
18281828
expect(refreshResponse.status).toBe(200);
1829-
1829+
18301830
// The callback should have been called once for the refresh
18311831
expect(callCount).toBe(1);
1832-
1832+
18331833
// Get the new tokens from the first refresh
18341834
const newTokens = await refreshResponse.json();
1835-
1835+
18361836
// Get the refresh token's corresponding token data to verify it has the updated props
18371837
const apiRequest1 = createMockRequest(
18381838
'https://example.com/api/test',
@@ -1842,16 +1842,16 @@ describe('OAuthProvider', () => {
18421842

18431843
const apiResponse1 = await testProvider.fetch(apiRequest1, mockEnv, mockCtx);
18441844
const apiData1 = await apiResponse1.json();
1845-
1845+
18461846
// Print the actual API response to debug
18471847
console.log("First API response:", JSON.stringify(apiData1));
1848-
1848+
18491849
// Verify that the token has the updated props (updatedCount should be 1)
18501850
expect(apiData1.user.updatedCount).toBe(1);
1851-
1851+
18521852
// Reset callCount before the second refresh
18531853
callCount = 0;
1854-
1854+
18551855
// Now try to use the SAME refresh token again (which should work once due to token rotation)
18561856
// With the bug, this would fail because previousRefreshTokenWrappedKey wasn't re-wrapped with the new key
18571857
const secondRefreshRequest = createMockRequest(
@@ -1862,17 +1862,17 @@ describe('OAuthProvider', () => {
18621862
);
18631863

18641864
const secondRefreshResponse = await testProvider.fetch(secondRefreshRequest, mockEnv, mockCtx);
1865-
1866-
// With the bug, this would fail with an error.
1865+
1866+
// With the bug, this would fail with an error.
18671867
// When fixed, it should succeed because the previous refresh token is still valid once.
18681868
expect(secondRefreshResponse.status).toBe(200);
1869-
1869+
18701870
const secondTokens = await secondRefreshResponse.json();
18711871
expect(secondTokens.access_token).toBeDefined();
1872-
1872+
18731873
// The callback should have been called again
18741874
expect(callCount).toBe(1);
1875-
1875+
18761876
// Use the token to access API and verify it has the updated props
18771877
const apiRequest2 = createMockRequest(
18781878
'https://example.com/api/test',
@@ -1882,7 +1882,7 @@ describe('OAuthProvider', () => {
18821882

18831883
const apiResponse2 = await testProvider.fetch(apiRequest2, mockEnv, mockCtx);
18841884
const apiData2 = await apiResponse2.json();
1885-
1885+
18861886
// The updatedCount should be 2 now (incremented again during the second refresh)
18871887
expect(apiData2.user.updatedCount).toBe(2);
18881888
});

src/oauth-provider.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export interface TokenExchangeCallbackResult {
5050
* If not provided, the original props will be used.
5151
*/
5252
newProps?: any;
53-
53+
5454
/**
5555
* Override the default access token TTL (time-to-live) for this specific token.
5656
* This is especially useful when the application is also an OAuth client to another service
@@ -1235,7 +1235,7 @@ class OAuthProviderImpl {
12351235
const refreshTokenId = await generateTokenId(refreshToken);
12361236

12371237
const now = Math.floor(Date.now() / 1000);
1238-
1238+
12391239
// Define the access token TTL, may be updated by callback if provided
12401240
let accessTokenTTL = this.options.accessTokenTTL!;
12411241

@@ -1270,19 +1270,19 @@ class OAuthProviderImpl {
12701270
// Use the returned props if provided, otherwise keep the original props
12711271
if (callbackResult.newProps) {
12721272
grantProps = callbackResult.newProps;
1273-
1273+
12741274
// If accessTokenProps wasn't explicitly specified, use the updated newProps for the token too
12751275
// This ensures token props are updated when only newProps are specified
12761276
if (!callbackResult.accessTokenProps) {
12771277
accessTokenProps = callbackResult.newProps;
12781278
}
12791279
}
1280-
1280+
12811281
// If accessTokenProps was explicitly specified, use those
12821282
if (callbackResult.accessTokenProps) {
12831283
accessTokenProps = callbackResult.accessTokenProps;
12841284
}
1285-
1285+
12861286
// If accessTokenTTL was specified, use that for this token
12871287
if (callbackResult.accessTokenTTL !== undefined) {
12881288
accessTokenTTL = callbackResult.accessTokenTTL;
@@ -1308,7 +1308,7 @@ class OAuthProviderImpl {
13081308

13091309
// Calculate the access token expiration time (after callback might have updated TTL)
13101310
const accessTokenExpiresAt = now + accessTokenTTL;
1311-
1311+
13121312
// Wrap the keys for the new tokens
13131313
const accessTokenWrappedKey = await wrapKeyWithToken(accessToken, accessTokenEncryptionKey);
13141314
const refreshTokenWrappedKey = await wrapKeyWithToken(refreshToken, grantEncryptionKey);
@@ -1442,7 +1442,7 @@ class OAuthProviderImpl {
14421442
const newRefreshTokenId = await generateTokenId(newRefreshToken);
14431443

14441444
const now = Math.floor(Date.now() / 1000);
1445-
1445+
14461446
// Define the access token TTL, may be updated by callback if provided
14471447
let accessTokenTTL = this.options.accessTokenTTL!;
14481448

@@ -1487,19 +1487,19 @@ class OAuthProviderImpl {
14871487
if (callbackResult.newProps) {
14881488
grantProps = callbackResult.newProps;
14891489
grantPropsChanged = true;
1490-
1490+
14911491
// If accessTokenProps wasn't explicitly specified, use the updated newProps for the token too
14921492
// This ensures token props are updated when only newProps are specified
14931493
if (!callbackResult.accessTokenProps) {
14941494
accessTokenProps = callbackResult.newProps;
14951495
}
14961496
}
1497-
1497+
14981498
// If accessTokenProps was explicitly specified, use those
14991499
if (callbackResult.accessTokenProps) {
15001500
accessTokenProps = callbackResult.accessTokenProps;
15011501
}
1502-
1502+
15031503
// If accessTokenTTL was specified, use that for this token
15041504
if (callbackResult.accessTokenTTL !== undefined) {
15051505
accessTokenTTL = callbackResult.accessTokenTTL;
@@ -1511,7 +1511,7 @@ class OAuthProviderImpl {
15111511
// Re-encrypt the updated grant props
15121512
const grantResult = await encryptProps(grantProps);
15131513
grantData.encryptedProps = grantResult.encryptedData;
1514-
1514+
15151515
// If the encryption key changed, we need to re-wrap the previous token key
15161516
if (grantResult.key !== encryptionKey) {
15171517
grantEncryptionKey = grantResult.key;
@@ -1535,7 +1535,7 @@ class OAuthProviderImpl {
15351535

15361536
// Calculate the access token expiration time (after callback might have updated TTL)
15371537
const accessTokenExpiresAt = now + accessTokenTTL;
1538-
1538+
15391539
// Wrap the key for both the new access token and refresh token
15401540
const accessTokenWrappedKey = await wrapKeyWithToken(newAccessToken, accessTokenEncryptionKey);
15411541
const newRefreshTokenWrappedKey = await wrapKeyWithToken(newRefreshToken, grantEncryptionKey);

0 commit comments

Comments
 (0)