Skip to content

Customizable authentication #4068

Closed
Closed
@sdissegna-maystreet

Description

@sdissegna-maystreet

This is something I've been working on and I will soon submit an implementation of.

The idea is to allow users of code-server to plug in their own custom authentication method without relying on proxies and without forking the repository.

To this end, my proposal is to add a new authentication type, called custom, to the --auth configuration option. When custom is specified, the user will then need to pass in a --custom-auth-module configuration option, which should point to a module on disk that can be loaded with require, and which export a customAuth property that implements the following interface:

import type { Request, Response, Router } from "express"

/**
 * Modules assigned to the custom-auth-module configuration option
 * must export a "customAuth" property implementing this interface.
 */
export interface CodeServerCustomAuth {
  /**
   * A GET request to the "/" path of the loginRouter is made when the user needs to login.
   */
  readonly loginRouter: Router

  /**
   * A GET request to the "/" path of the logoutRouter is made when the user needs to logout.
   */
  readonly logoutRouter: Router

  /**
   * Runs once when code-server starts. It will block startup until the returned
   * promise resolves.
   */
  initialize(): Promise<void>

  /**
   * Tells if the user is authenticated and authorized.
   *
   * @param req the request that needs to be authorized.
   * @param res the current response.
   * @returns true if the user is authorized, false otherwise.
   */
  authenticated(req: Request, res: Response): Promise<boolean>
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew user visible feature

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions