mirror of
https://github.com/kyantech/Palmr.git
synced 2026-01-09 06:02:28 +08:00
Fix OIDC authentication behind multiple proxies (#377)
This commit is contained in:
commit
35facfef55
@ -48,8 +48,12 @@ export class AuthProvidersController {
|
||||
}
|
||||
|
||||
private buildRequestContext(request: FastifyRequest): RequestContext {
|
||||
// Handle multiple protocols in x-forwarded-proto (e.g., "https, https" from multiple proxies)
|
||||
const forwardedProto = request.headers["x-forwarded-proto"] as string;
|
||||
const protocol = forwardedProto ? forwardedProto.split(",")[0].trim() : request.protocol;
|
||||
|
||||
return {
|
||||
protocol: (request.headers["x-forwarded-proto"] as string) || request.protocol,
|
||||
protocol,
|
||||
host: (request.headers["x-forwarded-host"] as string) || (request.headers.host as string),
|
||||
headers: request.headers,
|
||||
};
|
||||
|
||||
@ -40,7 +40,9 @@ async function getAppInfo() {
|
||||
|
||||
async function getBaseUrl(): Promise<string> {
|
||||
const headersList = await headers();
|
||||
const protocol = headersList.get("x-forwarded-proto") || "http";
|
||||
// Handle multiple protocols in x-forwarded-proto (e.g., "https, https" from multiple proxies)
|
||||
const forwardedProto = headersList.get("x-forwarded-proto");
|
||||
const protocol = forwardedProto ? forwardedProto.split(",")[0].trim() : "http";
|
||||
const host = headersList.get("x-forwarded-host") || headersList.get("host") || "localhost:3000";
|
||||
return `${protocol}://${host}`;
|
||||
}
|
||||
|
||||
@ -45,7 +45,9 @@ async function getAppInfo() {
|
||||
|
||||
async function getBaseUrl(): Promise<string> {
|
||||
const headersList = await headers();
|
||||
const protocol = headersList.get("x-forwarded-proto") || "http";
|
||||
// Handle multiple protocols in x-forwarded-proto (e.g., "https, https" from multiple proxies)
|
||||
const forwardedProto = headersList.get("x-forwarded-proto");
|
||||
const protocol = forwardedProto ? forwardedProto.split(",")[0].trim() : "http";
|
||||
const host = headersList.get("x-forwarded-host") || headersList.get("host") || "localhost:3000";
|
||||
return `${protocol}://${host}`;
|
||||
}
|
||||
|
||||
@ -8,7 +8,9 @@ export async function GET(request: NextRequest, { params }: { params: Promise<{
|
||||
const url = new URL(request.url);
|
||||
const queryString = url.search;
|
||||
const originalHost = request.headers.get("host") || url.host;
|
||||
const originalProtocol = request.headers.get("x-forwarded-proto") || url.protocol.replace(":", "");
|
||||
// Handle multiple protocols in x-forwarded-proto (e.g., "https, https" from multiple proxies)
|
||||
const forwardedProto = request.headers.get("x-forwarded-proto");
|
||||
const originalProtocol = forwardedProto ? forwardedProto.split(",")[0].trim() : url.protocol.replace(":", "");
|
||||
const authorizeUrl = `${API_BASE_URL}/auth/providers/${provider}/authorize${queryString}`;
|
||||
|
||||
const apiRes = await fetch(authorizeUrl, {
|
||||
|
||||
@ -8,7 +8,9 @@ export async function GET(request: NextRequest, { params }: { params: Promise<{
|
||||
const url = new URL(request.url);
|
||||
const queryString = url.search;
|
||||
const originalHost = request.headers.get("host") || url.host;
|
||||
const originalProtocol = request.headers.get("x-forwarded-proto") || url.protocol.replace(":", "");
|
||||
// Handle multiple protocols in x-forwarded-proto (e.g., "https, https" from multiple proxies)
|
||||
const forwardedProto = request.headers.get("x-forwarded-proto");
|
||||
const originalProtocol = forwardedProto ? forwardedProto.split(",")[0].trim() : url.protocol.replace(":", "");
|
||||
const callbackUrl = `${API_BASE_URL}/auth/providers/${provider}/callback${queryString}`;
|
||||
|
||||
const apiRes = await fetch(callbackUrl, {
|
||||
|
||||
@ -8,7 +8,9 @@ export async function GET(request: NextRequest) {
|
||||
const queryString = url.search;
|
||||
|
||||
const originalHost = request.headers.get("host") || url.host;
|
||||
const originalProtocol = request.headers.get("x-forwarded-proto") || url.protocol.replace(":", "");
|
||||
// Handle multiple protocols in x-forwarded-proto (e.g., "https, https" from multiple proxies)
|
||||
const forwardedProto = request.headers.get("x-forwarded-proto");
|
||||
const originalProtocol = forwardedProto ? forwardedProto.split(",")[0].trim() : url.protocol.replace(":", "");
|
||||
const listUrl = `${API_BASE_URL}/auth/providers${queryString}`;
|
||||
|
||||
const apiRes = await fetch(listUrl, {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user