mirror of
https://github.com/coder/code-server.git
synced 2024-11-22 19:23:16 +03:00
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 { HttpCode, HttpError } from "../common/http"
|
||||
import { version } from "./constants"
|
||||
import { ensureAuthenticated, replaceTemplates } from "./http"
|
||||
import { authenticated, ensureAuthenticated, replaceTemplates } from "./http"
|
||||
import { proxy } from "./proxy"
|
||||
import * as util from "./util"
|
||||
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".
|
||||
*/
|
||||
export const codeServer = {
|
||||
express,
|
||||
field,
|
||||
HttpCode,
|
||||
HttpError,
|
||||
Level,
|
||||
authenticated,
|
||||
ensureAuthenticated,
|
||||
express,
|
||||
field,
|
||||
proxy,
|
||||
replaceTemplates,
|
||||
WsRouter,
|
||||
@ -122,10 +124,10 @@ export class PluginAPI {
|
||||
public mount(r: express.Router, wr: express.Router): void {
|
||||
for (const [, p] of this.plugins) {
|
||||
if (p.router) {
|
||||
r.use(`${p.routerPath}`, ensureAuthenticated, p.router())
|
||||
r.use(`${p.routerPath}`, p.router())
|
||||
}
|
||||
if (p.wsRouter) {
|
||||
wr.use(`${p.routerPath}`, ensureAuthenticated, (p.wsRouter() as WebsocketRouter).router)
|
||||
wr.use(`${p.routerPath}`, (p.wsRouter() as WebsocketRouter).router)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
10
typings/pluginapi.d.ts
vendored
10
typings/pluginapi.d.ts
vendored
@ -142,6 +142,16 @@ export { field, Level, Logger }
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user