mirror of
https://github.com/outline/outline.git
synced 2026-11-21 05:24:03 +03:00
38 lines
1.0 KiB
TypeScript
38 lines
1.0 KiB
TypeScript
import { HttpsProxyAgent } from "https-proxy-agent";
|
|
import * as OAuth2StrategyModule from "passport-oauth2";
|
|
import { Request } from "express";
|
|
|
|
const { Strategy } = OAuth2StrategyModule;
|
|
|
|
type OIDCOptions = Record<string, unknown> & {
|
|
originalQuery?: Record<string, unknown>;
|
|
};
|
|
|
|
export class OIDCStrategy extends Strategy {
|
|
constructor(
|
|
options: OAuth2StrategyModule.StrategyOptionsWithRequest,
|
|
verify: OAuth2StrategyModule.VerifyFunctionWithRequest
|
|
) {
|
|
super(options, verify);
|
|
|
|
if (process.env.https_proxy) {
|
|
const httpsProxyAgent = new HttpsProxyAgent(process.env.https_proxy);
|
|
this._oauth2.setAgent(httpsProxyAgent);
|
|
}
|
|
}
|
|
|
|
authenticate(req: Request, options?: unknown) {
|
|
const opts = (options || {}) as OIDCOptions;
|
|
opts.originalQuery = req.query as Record<string, unknown>;
|
|
super.authenticate(req, opts);
|
|
}
|
|
|
|
authorizationParams(options: unknown) {
|
|
const opts = options as OIDCOptions;
|
|
return {
|
|
...(opts.originalQuery ?? {}),
|
|
...super.authorizationParams?.(options),
|
|
};
|
|
}
|
|
}
|