mirror of https://github.com/coder/code-server.git
Delegate authentication to plugins
Unfortunately since plugins can now override the root this is necessary or just can't log in.
This commit is contained in:
parent
c2450d6bf3
commit
3fc556d4d5
|
@ -6,7 +6,7 @@ import * as semver from "semver"
|
||||||
import * as pluginapi from "../../typings/pluginapi"
|
import * as pluginapi from "../../typings/pluginapi"
|
||||||
import { HttpCode, HttpError } from "../common/http"
|
import { HttpCode, HttpError } from "../common/http"
|
||||||
import { version } from "./constants"
|
import { version } from "./constants"
|
||||||
import { ensureAuthenticated, replaceTemplates } from "./http"
|
import { authenticated, ensureAuthenticated, replaceTemplates } from "./http"
|
||||||
import { proxy } from "./proxy"
|
import { proxy } from "./proxy"
|
||||||
import * as util from "./util"
|
import * as util from "./util"
|
||||||
import { Router as WsRouter, WebsocketRouter, wss } from "./wsRouter"
|
import { Router as WsRouter, WebsocketRouter, wss } from "./wsRouter"
|
||||||
|
@ -28,11 +28,13 @@ require("module")._load = function (request: string, parent: object, isMain: boo
|
||||||
* The module you get when importing "code-server".
|
* The module you get when importing "code-server".
|
||||||
*/
|
*/
|
||||||
export const codeServer = {
|
export const codeServer = {
|
||||||
express,
|
|
||||||
field,
|
|
||||||
HttpCode,
|
HttpCode,
|
||||||
HttpError,
|
HttpError,
|
||||||
Level,
|
Level,
|
||||||
|
authenticated,
|
||||||
|
ensureAuthenticated,
|
||||||
|
express,
|
||||||
|
field,
|
||||||
proxy,
|
proxy,
|
||||||
replaceTemplates,
|
replaceTemplates,
|
||||||
WsRouter,
|
WsRouter,
|
||||||
|
@ -122,10 +124,10 @@ export class PluginAPI {
|
||||||
public mount(r: express.Router, wr: express.Router): void {
|
public mount(r: express.Router, wr: express.Router): void {
|
||||||
for (const [, p] of this.plugins) {
|
for (const [, p] of this.plugins) {
|
||||||
if (p.router) {
|
if (p.router) {
|
||||||
r.use(`${p.routerPath}`, ensureAuthenticated, p.router())
|
r.use(`${p.routerPath}`, p.router())
|
||||||
}
|
}
|
||||||
if (p.wsRouter) {
|
if (p.wsRouter) {
|
||||||
wr.use(`${p.routerPath}`, ensureAuthenticated, (p.wsRouter() as WebsocketRouter).router)
|
wr.use(`${p.routerPath}`, (p.wsRouter() as WebsocketRouter).router)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -142,6 +142,16 @@ export { field, Level, Logger }
|
||||||
*/
|
*/
|
||||||
export const proxy: ProxyServer
|
export const proxy: ProxyServer
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Middleware to ensure the user is authenticated. Throws if they are not.
|
||||||
|
*/
|
||||||
|
export function ensureAuthenticated(req: express.Request, res?: express.Response, next?: express.NextFunction): void
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the user is authenticated.
|
||||||
|
*/
|
||||||
|
export function authenticated(req: express.Request): boolean
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replace variables in HTML: TO, BASE, CS_STATIC_BASE, and OPTIONS.
|
* Replace variables in HTML: TO, BASE, CS_STATIC_BASE, and OPTIONS.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue