Skip to content

Commit 3fc556d

Browse files
committed
Delegate authentication to plugins
Unfortunately since plugins can now override the root this is necessary or just can't log in.
1 parent c2450d6 commit 3fc556d

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/node/plugin.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as semver from "semver"
66
import * as pluginapi from "../../typings/pluginapi"
77
import { HttpCode, HttpError } from "../common/http"
88
import { version } from "./constants"
9-
import { ensureAuthenticated, replaceTemplates } from "./http"
9+
import { authenticated, ensureAuthenticated, replaceTemplates } from "./http"
1010
import { proxy } from "./proxy"
1111
import * as util from "./util"
1212
import { Router as WsRouter, WebsocketRouter, wss } from "./wsRouter"
@@ -28,11 +28,13 @@ require("module")._load = function (request: string, parent: object, isMain: boo
2828
* The module you get when importing "code-server".
2929
*/
3030
export const codeServer = {
31-
express,
32-
field,
3331
HttpCode,
3432
HttpError,
3533
Level,
34+
authenticated,
35+
ensureAuthenticated,
36+
express,
37+
field,
3638
proxy,
3739
replaceTemplates,
3840
WsRouter,
@@ -122,10 +124,10 @@ export class PluginAPI {
122124
public mount(r: express.Router, wr: express.Router): void {
123125
for (const [, p] of this.plugins) {
124126
if (p.router) {
125-
r.use(`${p.routerPath}`, ensureAuthenticated, p.router())
127+
r.use(`${p.routerPath}`, p.router())
126128
}
127129
if (p.wsRouter) {
128-
wr.use(`${p.routerPath}`, ensureAuthenticated, (p.wsRouter() as WebsocketRouter).router)
130+
wr.use(`${p.routerPath}`, (p.wsRouter() as WebsocketRouter).router)
129131
}
130132
}
131133
}

typings/pluginapi.d.ts

+10
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,16 @@ export { field, Level, Logger }
142142
*/
143143
export const proxy: ProxyServer
144144

145+
/**
146+
* Middleware to ensure the user is authenticated. Throws if they are not.
147+
*/
148+
export function ensureAuthenticated(req: express.Request, res?: express.Response, next?: express.NextFunction): void
149+
150+
/**
151+
* Returns true if the user is authenticated.
152+
*/
153+
export function authenticated(req: express.Request): boolean
154+
145155
/**
146156
* Replace variables in HTML: TO, BASE, CS_STATIC_BASE, and OPTIONS.
147157
*/

0 commit comments

Comments
 (0)