MCPcopy Index your code
hub / github.com/anomalyco/opencode / oauth

Function oauth

packages/core/src/plugin/provider/opencode.ts:37–75  ·  view source on GitHub ↗
(http: HttpClient.HttpClient)

Source from the content-addressed store, hash-verified

35const Org = Schema.Struct({ id: Schema.String, name: Schema.String })
36
37function oauth(http: HttpClient.HttpClient) {
38 return {
39 integrationID: Integration.ID.make("opencode"),
40 method: {
41 id: methodID,
42 type: "oauth",
43 label: "OpenCode Console account",
44 },
45 authorize: () =>
46 Effect.gen(function* () {
47 const device = yield* post(http, `${defaultServer}/auth/device/code`, { client_id: clientID }, Device)
48 return {
49 mode: "auto" as const,
50 url: `${defaultServer}${device.verification_uri_complete}`,
51 instructions: `Enter code: ${device.user_code}`,
52 callback: poll(http, defaultServer, device.device_code, Duration.seconds(device.interval)),
53 }
54 }),
55 refresh: (credential) =>
56 Effect.gen(function* () {
57 const server = typeof credential.metadata?.server === "string" ? credential.metadata.server : defaultServer
58 const token = yield* post(
59 http,
60 `${server}/auth/device/token`,
61 { grant_type: "refresh_token", refresh_token: credential.refresh, client_id: clientID },
62 Token,
63 )
64 return {
65 ...credential,
66 access: token.access_token,
67 refresh: token.refresh_token,
68 expires: Date.now() + token.expires_in * 1000,
69 }
70 }),
71 label: (credential) => {
72 return typeof credential.metadata?.orgName === "string" ? credential.metadata.orgName : undefined
73 },
74 } satisfies IntegrationOAuthMethodRegistration
75}
76
77export const OpencodePlugin = define<HttpClient.HttpClient | EventV2.Service | Scope.Scope>({
78 id: "opencode",

Callers 1

opencode.tsFile · 0.85

Calls 3

postFunction · 0.70
pollFunction · 0.70
makeMethod · 0.45

Tested by

no test coverage detected