feat(sdk): add ForwardAuth header passthrough hydration in createAuthMiddleware
This commit is contained in:
parent
cd1d866077
commit
b4b05c37ff
@ -23,5 +23,6 @@ export const AuthService = {
|
|||||||
O: ValidateSessionResponse,
|
O: ValidateSessionResponse,
|
||||||
kind: MethodKind.Unary,
|
kind: MethodKind.Unary,
|
||||||
},
|
},
|
||||||
},
|
}
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
|
|||||||
@ -3,14 +3,7 @@
|
|||||||
/* eslint-disable */
|
/* eslint-disable */
|
||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
|
|
||||||
import type {
|
import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "@bufbuild/protobuf";
|
||||||
BinaryReadOptions,
|
|
||||||
FieldList,
|
|
||||||
JsonReadOptions,
|
|
||||||
JsonValue,
|
|
||||||
PartialMessage,
|
|
||||||
PlainMessage,
|
|
||||||
} from "@bufbuild/protobuf";
|
|
||||||
import { Message, proto3 } from "@bufbuild/protobuf";
|
import { Message, proto3 } from "@bufbuild/protobuf";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -33,37 +26,19 @@ export class ValidateSessionRequest extends Message<ValidateSessionRequest> {
|
|||||||
{ no: 1, name: "token", kind: "scalar", T: 9 /* ScalarType.STRING */ },
|
{ no: 1, name: "token", kind: "scalar", T: 9 /* ScalarType.STRING */ },
|
||||||
]);
|
]);
|
||||||
|
|
||||||
static fromBinary(
|
static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): ValidateSessionRequest {
|
||||||
bytes: Uint8Array,
|
|
||||||
options?: Partial<BinaryReadOptions>,
|
|
||||||
): ValidateSessionRequest {
|
|
||||||
return new ValidateSessionRequest().fromBinary(bytes, options);
|
return new ValidateSessionRequest().fromBinary(bytes, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
static fromJson(
|
static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): ValidateSessionRequest {
|
||||||
jsonValue: JsonValue,
|
|
||||||
options?: Partial<JsonReadOptions>,
|
|
||||||
): ValidateSessionRequest {
|
|
||||||
return new ValidateSessionRequest().fromJson(jsonValue, options);
|
return new ValidateSessionRequest().fromJson(jsonValue, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
static fromJsonString(
|
static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): ValidateSessionRequest {
|
||||||
jsonString: string,
|
|
||||||
options?: Partial<JsonReadOptions>,
|
|
||||||
): ValidateSessionRequest {
|
|
||||||
return new ValidateSessionRequest().fromJsonString(jsonString, options);
|
return new ValidateSessionRequest().fromJsonString(jsonString, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
static equals(
|
static equals(a: ValidateSessionRequest | PlainMessage<ValidateSessionRequest> | undefined, b: ValidateSessionRequest | PlainMessage<ValidateSessionRequest> | undefined): boolean {
|
||||||
a:
|
|
||||||
| ValidateSessionRequest
|
|
||||||
| PlainMessage<ValidateSessionRequest>
|
|
||||||
| undefined,
|
|
||||||
b:
|
|
||||||
| ValidateSessionRequest
|
|
||||||
| PlainMessage<ValidateSessionRequest>
|
|
||||||
| undefined,
|
|
||||||
): boolean {
|
|
||||||
return proto3.util.equals(ValidateSessionRequest, a, b);
|
return proto3.util.equals(ValidateSessionRequest, a, b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -102,47 +77,24 @@ export class ValidateSessionResponse extends Message<ValidateSessionResponse> {
|
|||||||
static readonly fields: FieldList = proto3.util.newFieldList(() => [
|
static readonly fields: FieldList = proto3.util.newFieldList(() => [
|
||||||
{ no: 1, name: "valid", kind: "scalar", T: 8 /* ScalarType.BOOL */ },
|
{ no: 1, name: "valid", kind: "scalar", T: 8 /* ScalarType.BOOL */ },
|
||||||
{ no: 2, name: "uuid", kind: "scalar", T: 9 /* ScalarType.STRING */ },
|
{ no: 2, name: "uuid", kind: "scalar", T: 9 /* ScalarType.STRING */ },
|
||||||
{
|
{ no: 3, name: "scopes", kind: "scalar", T: 9 /* ScalarType.STRING */, repeated: true },
|
||||||
no: 3,
|
|
||||||
name: "scopes",
|
|
||||||
kind: "scalar",
|
|
||||||
T: 9, /* ScalarType.STRING */
|
|
||||||
repeated: true,
|
|
||||||
},
|
|
||||||
{ no: 4, name: "error", kind: "scalar", T: 9 /* ScalarType.STRING */ },
|
{ no: 4, name: "error", kind: "scalar", T: 9 /* ScalarType.STRING */ },
|
||||||
]);
|
]);
|
||||||
|
|
||||||
static fromBinary(
|
static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): ValidateSessionResponse {
|
||||||
bytes: Uint8Array,
|
|
||||||
options?: Partial<BinaryReadOptions>,
|
|
||||||
): ValidateSessionResponse {
|
|
||||||
return new ValidateSessionResponse().fromBinary(bytes, options);
|
return new ValidateSessionResponse().fromBinary(bytes, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
static fromJson(
|
static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): ValidateSessionResponse {
|
||||||
jsonValue: JsonValue,
|
|
||||||
options?: Partial<JsonReadOptions>,
|
|
||||||
): ValidateSessionResponse {
|
|
||||||
return new ValidateSessionResponse().fromJson(jsonValue, options);
|
return new ValidateSessionResponse().fromJson(jsonValue, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
static fromJsonString(
|
static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): ValidateSessionResponse {
|
||||||
jsonString: string,
|
|
||||||
options?: Partial<JsonReadOptions>,
|
|
||||||
): ValidateSessionResponse {
|
|
||||||
return new ValidateSessionResponse().fromJsonString(jsonString, options);
|
return new ValidateSessionResponse().fromJsonString(jsonString, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
static equals(
|
static equals(a: ValidateSessionResponse | PlainMessage<ValidateSessionResponse> | undefined, b: ValidateSessionResponse | PlainMessage<ValidateSessionResponse> | undefined): boolean {
|
||||||
a:
|
|
||||||
| ValidateSessionResponse
|
|
||||||
| PlainMessage<ValidateSessionResponse>
|
|
||||||
| undefined,
|
|
||||||
b:
|
|
||||||
| ValidateSessionResponse
|
|
||||||
| PlainMessage<ValidateSessionResponse>
|
|
||||||
| undefined,
|
|
||||||
): boolean {
|
|
||||||
return proto3.util.equals(ValidateSessionResponse, a, b);
|
return proto3.util.equals(ValidateSessionResponse, a, b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
12
sdk/hono.ts
12
sdk/hono.ts
@ -10,6 +10,18 @@ import type { AuthSdk, InvalidationHandler } from "./mod.ts";
|
|||||||
*/
|
*/
|
||||||
export function createAuthMiddleware(sdk: AuthSdk) {
|
export function createAuthMiddleware(sdk: AuthSdk) {
|
||||||
return async (c: Context, next: Next) => {
|
return async (c: Context, next: Next) => {
|
||||||
|
// 1. Check Traefik ForwardAuth Ingress Headers first
|
||||||
|
const forwardedUserId = c.req.header("X-Forwarded-User-Id") ||
|
||||||
|
c.req.header("x-forwarded-user-id");
|
||||||
|
if (forwardedUserId) {
|
||||||
|
const rawScopes = c.req.header("X-Forwarded-Scopes") ||
|
||||||
|
c.req.header("x-forwarded-scopes") || "";
|
||||||
|
const scopes = rawScopes.split(",").map((s) => s.trim()).filter(Boolean);
|
||||||
|
c.set("userId", forwardedUserId);
|
||||||
|
c.set("scopes", scopes);
|
||||||
|
return await next();
|
||||||
|
}
|
||||||
|
|
||||||
let token = getCookie(c, "session_id");
|
let token = getCookie(c, "session_id");
|
||||||
|
|
||||||
if (!token) {
|
if (!token) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user