diff --git a/apps/server/src/server.test.ts b/apps/server/src/server.test.ts index 9feef4e520..b4182ef447 100644 --- a/apps/server/src/server.test.ts +++ b/apps/server/src/server.test.ts @@ -3132,6 +3132,10 @@ it.layer(NodeServices.layer)("server router seam", (it) => { assert.equal(rpcError._tag, "EnvironmentAuthorizationError"); if (rpcError._tag === "EnvironmentAuthorizationError") { assert.equal(rpcError.requiredScope, "orchestration:read"); + assert.equal( + rpcError.message, + "The authenticated token is missing required scope: orchestration:read.", + ); } }).pipe(Effect.provide(NodeHttpServer.layerTest)), ); diff --git a/apps/server/src/ws.ts b/apps/server/src/ws.ts index 7f483f8357..857582dcb6 100644 --- a/apps/server/src/ws.ts +++ b/apps/server/src/ws.ts @@ -463,25 +463,20 @@ const makeWsRpcLayer = (currentSession: EnvironmentAuth.AuthenticatedSession) => const processDiagnostics = yield* ProcessDiagnostics.ProcessDiagnostics; const processResourceMonitor = yield* ProcessResourceMonitor.ProcessResourceMonitor; const relayClient = yield* RelayClient.RelayClient; - const authorizationError = (requiredScope: AuthEnvironmentScope) => - new EnvironmentAuthorizationError({ - message: `The authenticated token is missing required scope: ${requiredScope}.`, - requiredScope, - }); const authorizeEffect = ( requiredScope: AuthEnvironmentScope, effect: Effect.Effect, ): Effect.Effect => currentSession.scopes.includes(requiredScope) ? effect - : Effect.fail(authorizationError(requiredScope)); + : Effect.fail(new EnvironmentAuthorizationError({ requiredScope })); const authorizeStream = ( requiredScope: AuthEnvironmentScope, stream: Stream.Stream, ): Stream.Stream => currentSession.scopes.includes(requiredScope) ? stream - : Stream.fail(authorizationError(requiredScope)); + : Stream.fail(new EnvironmentAuthorizationError({ requiredScope })); const requiredScopeForMethod = (method: string): AuthEnvironmentScope => { const requiredScope = RPC_REQUIRED_SCOPE.get(method); if (requiredScope === undefined) { diff --git a/packages/contracts/src/auth.ts b/packages/contracts/src/auth.ts index 04467729ab..590444dfe5 100644 --- a/packages/contracts/src/auth.ts +++ b/packages/contracts/src/auth.ts @@ -300,10 +300,13 @@ export class AuthAccessStreamError extends Schema.TaggedErrorClass()( "EnvironmentAuthorizationError", { - message: Schema.String, requiredScope: AuthEnvironmentScope, }, -) {} +) { + override get message(): string { + return `The authenticated token is missing required scope: ${this.requiredScope}.`; + } +} export const AuthAccessStreamClientUpsertedEvent = Schema.Struct({ version: Schema.Literal(1),