MCPcopy Create free account
hub / github.com/arctic-cli/interface / authorize

Function authorize

packages/arctic/src/auth/github-copilot-oauth/plugin.ts:195–280  ·  view source on GitHub ↗
(inputs = {})

Source from the content-addressed store, hash-verified

193 },
194 ],
195 async authorize(inputs = {}) {
196 const deploymentType = (inputs as any).deploymentType || "github.com"
197
198 let domain = "github.com"
199 let actualProvider = "github-copilot"
200
201 if (deploymentType === "enterprise") {
202 const enterpriseUrl = (inputs as any).enterpriseUrl as string
203 domain = normalizeDomain(enterpriseUrl)
204 actualProvider = "github-copilot-enterprise"
205 }
206
207 const urls = getUrls(domain)
208
209 const deviceResponse = await fetch(urls.DEVICE_CODE_URL, {
210 method: "POST",
211 headers: {
212 Accept: "application/json",
213 "Content-Type": "application/json",
214 "User-Agent": "GitHubCopilotChat/0.35.0",
215 },
216 body: JSON.stringify({
217 client_id: CLIENT_ID,
218 scope: "read:user",
219 }),
220 })
221
222 if (!deviceResponse.ok) {
223 throw new Error("Failed to initiate device authorization")
224 }
225
226 const deviceData = await deviceResponse.json()
227
228 return {
229 url: deviceData.verification_uri,
230 instructions: `Enter code: ${deviceData.user_code}`,
231 method: "auto" as const,
232 callback: async () => {
233 while (true) {
234 const response = await fetch(urls.ACCESS_TOKEN_URL, {
235 method: "POST",
236 headers: {
237 Accept: "application/json",
238 "Content-Type": "application/json",
239 "User-Agent": "GitHubCopilotChat/0.35.0",
240 },
241 body: JSON.stringify({
242 client_id: CLIENT_ID,
243 device_code: deviceData.device_code,
244 grant_type: "urn:ietf:params:oauth:grant-type:device_code",
245 }),
246 })
247
248 if (!response.ok) return { type: "failed" as const }
249
250 const data = await response.json()
251
252 if (data.access_token) {

Callers

nothing calls this directly

Calls 4

normalizeDomainFunction · 0.85
getUrlsFunction · 0.85
fetchFunction · 0.70
jsonMethod · 0.65

Tested by

no test coverage detected