be41597502
routes/oauth.js has its own pageLocals object (distinct from routes/index.js's values and routes/docs.js's own copy) used by oauth_authorize.ejs/oauth_logout.ejs -- missed in the white-label change since a grep alias in this environment silently treats this particular file as binary and skips it. Caught by CI (oauth.test.js), not local testing. Added logo: conf.logo to match the other two copies of this locals object.
461 lines
16 KiB
JavaScript
461 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,
|
|
logo: conf.logo,
|
|
...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 = ' |