4c6b1e38b1
theta42/proxy fronts an arbitrary number of hosts behind SSO, each with its own callback URL (https://<host>/__proxy_auth/callback) — proxy's own code comment already assumed "a wildcard redirect URI covers all", but no wildcard matching existed here, so every proxied host's callback had to be registered on the shared OAuth client individually or /oauth/authorize would reject it with InvalidRedirectURI. Add `*` (one hostname label) / `**` (any number of labels) wildcard support to redirect_uri matching, e.g. `https://**.example.com/__proxy_auth/callback` now covers every host proxy fronts under example.com. Exact matches still work exactly as before. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
460 lines
16 KiB
JavaScript
460 lines
16 KiB
JavaScript
'use strict';
|
|
|
|
const crypto = require('crypto');
|
|
const jwt = require('jsonwebtoken');
|
|
const express = require('express');
|
|
const conf = require('@simpleworkjs/conf');
|
|
const { OAuthClient } = require('../models/oauth_client');
|
|
const { OAuthCode, OAuthAccessToken, OAuthRefreshToken } = require('../models/oauth_code');
|
|
const { User } = require('../models/user');
|
|
const { Group } = require('../models/group_ldap');
|
|
const buildInfo = require('../utils/build_info');
|
|
|
|
const oauthConf = conf.oauth || {};
|
|
const issuer = oauthConf.issuer || `http://localhost:${conf.port || 3000}`;
|
|
const jwtSecret = oauthConf.jwtSecret || 'change-me-in-secrets';
|
|
|
|
const pageLocals = {
|
|
title: conf.environment !== 'production' ? 'dev' : '',
|
|
titleIcon: conf.environment !== 'production' ? '<i class="fa-brands fa-dev"></i>' : '',
|
|
name: conf.name,
|
|
...buildInfo,
|
|
};
|
|
|
|
// --- helpers ---
|
|
|
|
function makeError(name, message, status) {
|
|
const error = new Error(name);
|
|
error.name = name;
|
|
error.message = message;
|
|
error.status = status;
|
|
return error;
|
|
}
|
|
|
|
// A registered redirect_uri may use `*` (one hostname label, no '.' or '/') or
|
|
// `**` (anything) as a wildcard — e.g. `https://*.example.com/__proxy_auth/callback`
|
|
// covers every host theta42/proxy fronts under example.com, so operators don't
|
|
// have to register each proxied host's callback individually. Mirrors the
|
|
// */** wildcard convention proxy's own Host.host field already uses.
|
|
function redirectUriAllowed(patterns, uri) {
|
|
if (!Array.isArray(patterns) || !uri) return false;
|
|
for (const pattern of patterns) {
|
|
if (pattern === uri) return true;
|
|
if (typeof pattern !== 'string' || pattern.indexOf('*') === -1) continue;
|
|
|
|
const DOUBLE = ' |