mirror of
https://github.com/anomalyco/opencode.git
synced 2026-07-21 10:16:03 +00:00
fix(server): preserve v1 auth compatibility
This commit is contained in:
@@ -13,11 +13,12 @@ export type DecodedCredentials = {
|
||||
|
||||
export type Info = {
|
||||
readonly password: Option.Option<string>
|
||||
readonly username: string
|
||||
}
|
||||
|
||||
export class Config extends Context.Service<Config, Info>()("@opencode/ServerAuthConfig") {
|
||||
static configLayer(input: Info) {
|
||||
return Layer.succeed(this, this.of(input))
|
||||
static configLayer(input: Pick<Info, "password">) {
|
||||
return Layer.succeed(this, this.of({ ...input, username: "opencode" }))
|
||||
}
|
||||
|
||||
static get layer() {
|
||||
@@ -32,7 +33,7 @@ export function required(config: Info) {
|
||||
export function authorized(credentials: DecodedCredentials, config: Info) {
|
||||
return (
|
||||
Option.isSome(config.password) &&
|
||||
credentials.username === "opencode" &&
|
||||
credentials.username === config.username &&
|
||||
Redacted.value(credentials.password) === config.password.value
|
||||
)
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ function dispatch(
|
||||
application: Ref.Ref<Option.Option<App>>,
|
||||
shutdown: Deferred.Deferred<void>,
|
||||
): App {
|
||||
const auth = ServerAuth.Config.of({ password: Option.some(password) })
|
||||
const auth = ServerAuth.Config.of({ password: Option.some(password), username: "opencode" })
|
||||
return Effect.gen(function* () {
|
||||
const request = yield* HttpServerRequest.HttpServerRequest
|
||||
const url = new URL(request.url, "http://localhost")
|
||||
|
||||
@@ -3,7 +3,7 @@ import { ServerAuth } from "@opencode-ai/server/auth"
|
||||
import { Option, Redacted } from "effect"
|
||||
|
||||
test("accepts only the fixed opencode username", () => {
|
||||
const config = { password: Option.some("secret") }
|
||||
const config = { password: Option.some("secret"), username: "opencode" }
|
||||
expect(ServerAuth.authorized({ username: "opencode", password: Redacted.make("secret") }, config)).toBe(true)
|
||||
expect(ServerAuth.authorized({ username: "custom", password: Redacted.make("secret") }, config)).toBe(false)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user