Skip to content

Commit 563a96e

Browse files
committed
Remove old AuthorizationError.
1 parent 99e84eb commit 563a96e

File tree

12 files changed

+38
-51
lines changed

12 files changed

+38
-51
lines changed

libs/lib-services/src/router/endpoint.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const executeEndpoint = async <I, O, C, P extends EndpointHandlerPayload<
1717
const authorizer_response = await endpoint.authorize?.(payload);
1818
if (authorizer_response && !authorizer_response.authorized) {
1919
if (authorizer_response.error == null) {
20-
throw new errors.AuthorizationError2(errors.ErrorCode.PSYNC_S2101, 'Authorization failed');
20+
throw new errors.AuthorizationError(errors.ErrorCode.PSYNC_S2101, 'Authorization failed');
2121
}
2222
throw authorizer_response.error;
2323
}

modules/module-postgres/src/auth/SupabaseKeyCollector.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as pgwire from '@powersync/service-jpgwire';
44
import * as jose from 'jose';
55

66
import * as types from '../types/types.js';
7-
import { AuthorizationError2, ErrorCode } from '@powersync/lib-services-framework';
7+
import { AuthorizationError, ErrorCode } from '@powersync/lib-services-framework';
88

99
/**
1010
* Fetches key from the Supabase database.
@@ -45,7 +45,7 @@ export class SupabaseKeyCollector implements auth.KeyCollector {
4545
row = rows[0] as any;
4646
} catch (e) {
4747
if (e.message?.includes('unrecognized configuration parameter')) {
48-
throw new AuthorizationError2(
48+
throw new AuthorizationError(
4949
ErrorCode.PSYNC_S2201,
5050
'No JWT secret found in Supabase database. Manually configure the secret.'
5151
);
@@ -58,7 +58,7 @@ export class SupabaseKeyCollector implements auth.KeyCollector {
5858
return {
5959
keys: [],
6060
errors: [
61-
new AuthorizationError2(
61+
new AuthorizationError(
6262
ErrorCode.PSYNC_S2201,
6363
'No JWT secret found in Supabase database. Manually configure the secret.'
6464
)

packages/rsocket-router/src/router/ReactiveSocketRouter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export class ReactiveSocketRouter<C> {
7272
// Throwing an exception in this context will be returned to the client side request
7373
if (!payload.metadata) {
7474
// Meta data is required for endpoint handler path matching
75-
throw new errors.AuthorizationError('No context meta data provided');
75+
throw new errors.AuthorizationError(ErrorCode.PSYNC_S2101, 'No context meta data provided');
7676
}
7777

7878
const context = await params.contextProvider(payload.metadata!);
@@ -167,7 +167,7 @@ export async function handleReactiveStream<Context>(
167167
});
168168
if (!isAuthorized.authorized) {
169169
return exitWithError(
170-
isAuthorized.error ?? new errors.AuthorizationError2(ErrorCode.PSYNC_S2101, 'Authorization failed')
170+
isAuthorized.error ?? new errors.AuthorizationError(ErrorCode.PSYNC_S2101, 'Authorization failed')
171171
);
172172
}
173173
}

packages/service-core/src/auth/CachedKeyCollector.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import timers from 'timers/promises';
33
import { KeySpec } from './KeySpec.js';
44
import { LeakyBucket } from './LeakyBucket.js';
55
import { KeyCollector, KeyResult } from './KeyCollector.js';
6-
import { AuthorizationError2 } from '@powersync/lib-services-framework';
6+
import { AuthorizationError } from '@powersync/lib-services-framework';
77
import { mapAuthConfigError } from './utils.js';
88

99
/**
@@ -41,7 +41,7 @@ export class CachedKeyCollector implements KeyCollector {
4141
*/
4242
private keyExpiry = 3600000;
4343

44-
private currentErrors: AuthorizationError2[] = [];
44+
private currentErrors: AuthorizationError[] = [];
4545
/**
4646
* Indicates a "fatal" error that should be retried.
4747
*/

packages/service-core/src/auth/CompoundKeyCollector.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as jose from 'jose';
22
import { KeySpec } from './KeySpec.js';
33
import { KeyCollector, KeyResult } from './KeyCollector.js';
4-
import { AuthorizationError2 } from '@powersync/lib-services-framework';
4+
import { AuthorizationError } from '@powersync/lib-services-framework';
55

66
export class CompoundKeyCollector implements KeyCollector {
77
private collectors: KeyCollector[];
@@ -16,7 +16,7 @@ export class CompoundKeyCollector implements KeyCollector {
1616

1717
async getKeys(): Promise<KeyResult> {
1818
let keys: KeySpec[] = [];
19-
let errors: AuthorizationError2[] = [];
19+
let errors: AuthorizationError[] = [];
2020
const promises = this.collectors.map((collector) =>
2121
collector.getKeys().then((result) => {
2222
keys.push(...result.keys);

packages/service-core/src/auth/KeyCollector.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AuthorizationError2 } from '@powersync/lib-services-framework';
1+
import { AuthorizationError } from '@powersync/lib-services-framework';
22
import { KeySpec } from './KeySpec.js';
33

44
export interface KeyCollector {
@@ -22,6 +22,6 @@ export interface KeyCollector {
2222
}
2323

2424
export interface KeyResult {
25-
errors: AuthorizationError2[];
25+
errors: AuthorizationError[];
2626
keys: KeySpec[];
2727
}

packages/service-core/src/auth/KeyStore.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { logger, errors, AuthorizationError2, ErrorCode } from '@powersync/lib-services-framework';
1+
import { logger, errors, AuthorizationError, ErrorCode } from '@powersync/lib-services-framework';
22
import * as jose from 'jose';
33
import secs from '../util/secs.js';
44
import { JwtPayload } from './JwtPayload.js';
@@ -69,7 +69,7 @@ export class KeyStore<Collector extends KeyCollector = KeyCollector> {
6969
return audiences.includes(a);
7070
})
7171
) {
72-
throw new AuthorizationError2(
72+
throw new AuthorizationError(
7373
ErrorCode.PSYNC_S2105,
7474
`Unexpected "aud" claim value: ${JSON.stringify(tokenPayload.aud)}`,
7575
{ sensitiveDetails: `Current configuration allows these audience values: ${JSON.stringify(audiences)}` }
@@ -82,15 +82,15 @@ export class KeyStore<Collector extends KeyCollector = KeyCollector> {
8282
// is too far into the future.
8383
const maxAge = keyOptions.maxLifetimeSeconds ?? secs(options.maxAge);
8484
if (tokenDuration > maxAge) {
85-
throw new AuthorizationError2(
85+
throw new AuthorizationError(
8686
ErrorCode.PSYNC_S2104,
8787
`Token must expire in a maximum of ${maxAge} seconds, got ${tokenDuration}s`
8888
);
8989
}
9090

9191
const parameters = tokenPayload.parameters;
9292
if (parameters != null && (Array.isArray(parameters) || typeof parameters != 'object')) {
93-
throw new AuthorizationError2(ErrorCode.PSYNC_S2101, `Payload parameters must be an object`);
93+
throw new AuthorizationError(ErrorCode.PSYNC_S2101, `Payload parameters must be an object`);
9494
}
9595

9696
return tokenPayload as JwtPayload;
@@ -119,7 +119,7 @@ export class KeyStore<Collector extends KeyCollector = KeyCollector> {
119119
for (let key of keys) {
120120
if (key.kid == kid) {
121121
if (!key.matchesAlgorithm(header.alg)) {
122-
throw new AuthorizationError2(ErrorCode.PSYNC_S2101, `Unexpected token algorithm ${header.alg}`, {
122+
throw new AuthorizationError(ErrorCode.PSYNC_S2101, `Unexpected token algorithm ${header.alg}`, {
123123
sensitiveDetails: `Key kid: ${key.source.kid}, alg: ${key.source.alg}, kty: ${key.source.kty}`
124124
});
125125
}
@@ -154,7 +154,7 @@ export class KeyStore<Collector extends KeyCollector = KeyCollector> {
154154
logger.error(`Failed to refresh keys`, e);
155155
});
156156

157-
throw new AuthorizationError2(
157+
throw new AuthorizationError(
158158
ErrorCode.PSYNC_S2101,
159159
'Could not find an appropriate key in the keystore. The key is missing or no key matched the token KID',
160160
{

packages/service-core/src/auth/RemoteJWKSCollector.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as jose from 'jose';
44
import fetch from 'node-fetch';
55

66
import {
7-
AuthorizationError2,
7+
AuthorizationError,
88
ErrorCode,
99
LookupOptions,
1010
makeHostnameLookupFunction,
@@ -63,7 +63,7 @@ export class RemoteJWKSCollector implements KeyCollector {
6363
});
6464

6565
if (!res.ok) {
66-
throw new AuthorizationError2(ErrorCode.PSYNC_S2204, `JWKS request failed with ${res.statusText}`, {
66+
throw new AuthorizationError(ErrorCode.PSYNC_S2204, `JWKS request failed with ${res.statusText}`, {
6767
sensitiveDetails: `JWKS URL: ${this.url}`
6868
});
6969
}
@@ -81,7 +81,7 @@ export class RemoteJWKSCollector implements KeyCollector {
8181
return {
8282
keys: [],
8383
errors: [
84-
new AuthorizationError2(ErrorCode.PSYNC_S2204, `JWKS request failed with ${res.statusText}`, {
84+
new AuthorizationError(ErrorCode.PSYNC_S2204, `JWKS request failed with ${res.statusText}`, {
8585
sensitiveDetails: `JWKS URL: ${this.url}. Response:\n${JSON.stringify(data, null, 2)}`
8686
})
8787
]
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
import { AuthorizationError2, ErrorCode } from '@powersync/lib-services-framework';
1+
import { AuthorizationError, ErrorCode } from '@powersync/lib-services-framework';
22
import * as jose from 'jose';
33

4-
export function mapJoseError(error: jose.errors.JOSEError): AuthorizationError2 {
4+
export function mapJoseError(error: jose.errors.JOSEError): AuthorizationError {
55
// TODO: improved message for exp issues, etc
66
if (error.code === 'ERR_JWS_INVALID' || error.code === 'ERR_JWT_INVALID') {
7-
throw new AuthorizationError2(ErrorCode.PSYNC_S2101, 'Token is not a well-formed JWT. Check the token format.', {
7+
throw new AuthorizationError(ErrorCode.PSYNC_S2101, 'Token is not a well-formed JWT. Check the token format.', {
88
details: error.message
99
});
1010
}
11-
return new AuthorizationError2(ErrorCode.PSYNC_S2101, error.message, { cause: error });
11+
return new AuthorizationError(ErrorCode.PSYNC_S2101, error.message, { cause: error });
1212
}
1313

14-
export function mapAuthError(error: any): AuthorizationError2 {
15-
if (error instanceof AuthorizationError2) {
14+
export function mapAuthError(error: any): AuthorizationError {
15+
if (error instanceof AuthorizationError) {
1616
return error;
1717
} else if (error instanceof jose.errors.JOSEError) {
1818
return mapJoseError(error);
1919
}
20-
return new AuthorizationError2(ErrorCode.PSYNC_S2101, error.message, { cause: error });
20+
return new AuthorizationError(ErrorCode.PSYNC_S2101, error.message, { cause: error });
2121
}
2222

23-
export function mapJoseConfigError(error: jose.errors.JOSEError): AuthorizationError2 {
24-
return new AuthorizationError2(ErrorCode.PSYNC_S2201, error.message, { cause: error });
23+
export function mapJoseConfigError(error: jose.errors.JOSEError): AuthorizationError {
24+
return new AuthorizationError(ErrorCode.PSYNC_S2201, error.message, { cause: error });
2525
}
2626

27-
export function mapAuthConfigError(error: any): AuthorizationError2 {
28-
if (error instanceof AuthorizationError2) {
27+
export function mapAuthConfigError(error: any): AuthorizationError {
28+
if (error instanceof AuthorizationError) {
2929
return error;
3030
} else if (error instanceof jose.errors.JOSEError) {
3131
return mapJoseConfigError(error);
3232
}
33-
return new AuthorizationError2(ErrorCode.PSYNC_S2201, error.message, { cause: error });
33+
return new AuthorizationError(ErrorCode.PSYNC_S2201, error.message, { cause: error });
3434
}

packages/service-core/src/routes/auth.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as auth from '../auth/auth-index.js';
44
import { ServiceContext } from '../system/ServiceContext.js';
55
import * as util from '../util/util-index.js';
66
import { BasicRouterRequest, Context, RequestEndpointHandlerPayload } from './router.js';
7-
import { AuthorizationError2, AuthorizationResponse, ErrorCode, ServiceError } from '@powersync/lib-services-framework';
7+
import { AuthorizationError, AuthorizationResponse, ErrorCode, ServiceError } from '@powersync/lib-services-framework';
88

99
export function endpoint(req: BasicRouterRequest) {
1010
const protocol = req.headers['x-forwarded-proto'] ?? req.protocol;
@@ -105,7 +105,7 @@ export async function authorizeUser(context: Context, authHeader: string = ''):
105105
if (token == null) {
106106
return {
107107
authorized: false,
108-
error: new AuthorizationError2(ErrorCode.PSYNC_S2106, 'Authentication required')
108+
error: new AuthorizationError(ErrorCode.PSYNC_S2106, 'Authentication required')
109109
};
110110
}
111111

0 commit comments

Comments
 (0)