Skip to content

Commit 7a02eee

Browse files
chore: generate
1 parent cf45a8d commit 7a02eee

1 file changed

Lines changed: 24 additions & 19 deletions

File tree

  • packages/opencode/src/server/routes/instance/httpapi

packages/opencode/src/server/routes/instance/httpapi/auth.ts

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@ class Unauthorized extends Schema.TaggedErrorClass<Unauthorized>()(
88
{ httpApiStatus: 401 },
99
) {}
1010

11-
export class Authorization extends HttpApiMiddleware.Service<Authorization>()("@opencode/ExperimentalHttpApiAuthorization", {
12-
error: Unauthorized,
13-
security: {
14-
basic: HttpApiSecurity.basic,
15-
authToken: HttpApiSecurity.apiKey({ in: "query", key: "auth_token" }),
11+
export class Authorization extends HttpApiMiddleware.Service<Authorization>()(
12+
"@opencode/ExperimentalHttpApiAuthorization",
13+
{
14+
error: Unauthorized,
15+
security: {
16+
basic: HttpApiSecurity.basic,
17+
authToken: HttpApiSecurity.apiKey({ in: "query", key: "auth_token" }),
18+
},
1619
},
17-
}) {}
20+
) {}
1821

1922
const emptyCredential = {
2023
username: "",
@@ -39,19 +42,21 @@ function validateCredential<A, E, R>(
3942
}
4043

4144
function decodeCredential(input: string) {
42-
return Encoding.decodeBase64String(input).asEffect().pipe(
43-
Effect.match({
44-
onFailure: () => emptyCredential,
45-
onSuccess: (header) => {
46-
const parts = header.split(":")
47-
if (parts.length !== 2) return emptyCredential
48-
return {
49-
username: parts[0],
50-
password: Redacted.make(parts[1]),
51-
}
52-
},
53-
}),
54-
)
45+
return Encoding.decodeBase64String(input)
46+
.asEffect()
47+
.pipe(
48+
Effect.match({
49+
onFailure: () => emptyCredential,
50+
onSuccess: (header) => {
51+
const parts = header.split(":")
52+
if (parts.length !== 2) return emptyCredential
53+
return {
54+
username: parts[0],
55+
password: Redacted.make(parts[1]),
56+
}
57+
},
58+
}),
59+
)
5560
}
5661

5762
export const authorizationLayer = Layer.succeed(

0 commit comments

Comments
 (0)