docs(relay): describe endpoint authentication schemes
Co-authored-by: codex <[email protected]>
This commit is contained in:
1 parent
1a3bd37399
commit
34b6cff753
3 files changed
+28
-6
No files matched your search
@@ -118,7 +118,7 @@ describe("relay environment authentication", () => {
|
||||
return Effect.gen(function* () {
|
||||
const auth = yield* RelayEnvironmentAuth;
|
||||
const error = yield* Effect.flip(
|
||||
auth.bearer(Effect.succeed(HttpServerResponse.empty()), {
|
||||
auth.environmentBearer(Effect.succeed(HttpServerResponse.empty()), {
|
||||
credential: Redacted.make("environment-credential"),
|
||||
endpoint: {} as never,
|
||||
group: {} as never,
|
||||
|
||||
@@ -188,7 +188,7 @@ export const relayClientAuthLayer = Layer.effect(
|
||||
Effect.gen(function* () {
|
||||
const config = yield* RelayConfiguration.RelayConfiguration;
|
||||
return {
|
||||
bearer: Effect.fn("relay.auth.client.bearer")(function* (httpEffect, { credential }) {
|
||||
clientBearer: Effect.fn("relay.auth.client.bearer")(function* (httpEffect, { credential }) {
|
||||
const token = readHttpAuthorizationCredential(credential);
|
||||
const verified = yield* verifyRelayClientBearerToken(config, token).pipe(
|
||||
Effect.tapError((error) =>
|
||||
@@ -227,7 +227,10 @@ export const relayEnvironmentAuthLayer = Layer.effect(
|
||||
Effect.gen(function* () {
|
||||
const credentials = yield* EnvironmentCredentials.EnvironmentCredentials;
|
||||
return {
|
||||
bearer: Effect.fn("relay.auth.environment.bearer")(function* (httpEffect, { credential }) {
|
||||
environmentBearer: Effect.fn("relay.auth.environment.bearer")(function* (
|
||||
httpEffect,
|
||||
{ credential },
|
||||
) {
|
||||
const token = readHttpAuthorizationCredential(credential);
|
||||
const principal = yield* credentials
|
||||
.authenticate(token)
|
||||
|
||||
@@ -490,20 +490,34 @@ export class RelayEnvironmentPrincipal extends Context.Service<
|
||||
RelayEnvironmentPrincipalShape
|
||||
>()("@t3tools/contracts/relay/RelayEnvironmentPrincipal") {}
|
||||
|
||||
const RelayClientBearerAuthorization = HttpApiSecurity.bearer.pipe(
|
||||
HttpApiSecurity.annotate(
|
||||
OpenApi.Description,
|
||||
"Clerk session or OAuth bearer token for the signed-in T3 Cloud user.",
|
||||
),
|
||||
);
|
||||
|
||||
export class RelayClientAuth extends HttpApiMiddleware.Service<
|
||||
RelayClientAuth,
|
||||
{ provides: RelayClientPrincipal }
|
||||
>()("RelayClientAuth", {
|
||||
error: RelayAuthInvalidError,
|
||||
security: { bearer: HttpApiSecurity.bearer },
|
||||
security: { clientBearer: RelayClientBearerAuthorization },
|
||||
}) {}
|
||||
|
||||
const RelayEnvironmentBearerAuthorization = HttpApiSecurity.bearer.pipe(
|
||||
HttpApiSecurity.annotate(
|
||||
OpenApi.Description,
|
||||
"Relay-issued environment credential installed when the environment is linked.",
|
||||
),
|
||||
);
|
||||
|
||||
export class RelayEnvironmentAuth extends HttpApiMiddleware.Service<
|
||||
RelayEnvironmentAuth,
|
||||
{ provides: RelayEnvironmentPrincipal }
|
||||
>()("RelayEnvironmentAuth", {
|
||||
error: [RelayAuthInvalidError, RelayInternalError],
|
||||
security: { bearer: HttpApiSecurity.bearer },
|
||||
security: { environmentBearer: RelayEnvironmentBearerAuthorization },
|
||||
}) {}
|
||||
|
||||
const RelayDpopAuthorization = HttpApiSecurity.http({ scheme: "DPoP" }).pipe(
|
||||
@@ -876,7 +890,12 @@ export const RelayExchangeDpopAccessTokenEndpoint = HttpApiEndpoint.post(
|
||||
success: RelayDpopAccessTokenResponse,
|
||||
error: RelayAuthAndInternalErrors,
|
||||
},
|
||||
).annotate(OpenApi.Summary, "Exchange a Clerk token for a DPoP access token");
|
||||
)
|
||||
.annotate(OpenApi.Summary, "Exchange a Clerk token for a DPoP access token")
|
||||
.annotate(
|
||||
OpenApi.Description,
|
||||
"Bootstrap endpoint. Send the DPoP proof JWT in the dpop header and the Clerk token in subject_token. The returned access token is bound to the proof key.",
|
||||
);
|
||||
|
||||
export const RelayTokenGroup = HttpApiGroup.make("token")
|
||||
.add(RelayExchangeDpopAccessTokenEndpoint)
|
||||
|
||||
Reference in new issue
Block a user