mirror of
https://github.com/sst/opencode.git
synced 2025-07-07 16:14:59 +00:00
feat: open browser for github auth
This commit is contained in:
parent
d043f67761
commit
6feeccdf6e
2 changed files with 18 additions and 12 deletions
|
@ -46,11 +46,11 @@ export namespace AuthGithubCopilot {
|
|||
})
|
||||
const deviceData: DeviceCodeResponse = await deviceResponse.json()
|
||||
return {
|
||||
device: deviceData.device_code,
|
||||
user: deviceData.user_code,
|
||||
verification: deviceData.verification_uri,
|
||||
deviceCode: deviceData.device_code,
|
||||
userCode: deviceData.user_code,
|
||||
verificationUri: deviceData.verification_uri,
|
||||
interval: deviceData.interval || 5,
|
||||
expiry: deviceData.expires_in,
|
||||
expiryIn: deviceData.expires_in,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -184,20 +184,26 @@ export const AuthLoginCommand = cmd({
|
|||
const copilot = await AuthCopilot()
|
||||
if (provider === "github-copilot" && copilot) {
|
||||
await new Promise((resolve) => setTimeout(resolve, 10))
|
||||
const deviceInfo = await copilot.authorize()
|
||||
const { userCode, deviceCode, verificationUri, interval } =
|
||||
await copilot.authorize()
|
||||
|
||||
prompts.note(
|
||||
`Please visit: ${deviceInfo.verification}\nEnter code: ${deviceInfo.user}`,
|
||||
)
|
||||
prompts.note(`Enter the following code: ${userCode} when prompted`)
|
||||
prompts.note("Trying to open browser...")
|
||||
try {
|
||||
await open(verificationUri)
|
||||
} catch (e) {
|
||||
prompts.log.error(
|
||||
"Failed to open browser perhaps you are running without a display or X server, please open the following URL in your browser:",
|
||||
)
|
||||
}
|
||||
prompts.log.info(verificationUri)
|
||||
|
||||
const spinner = prompts.spinner()
|
||||
spinner.start("Waiting for authorization...")
|
||||
|
||||
while (true) {
|
||||
await new Promise((resolve) =>
|
||||
setTimeout(resolve, deviceInfo.interval * 1000),
|
||||
)
|
||||
const response = await copilot.poll(deviceInfo.device)
|
||||
await new Promise((resolve) => setTimeout(resolve, interval * 1000))
|
||||
const response = await copilot.poll(deviceCode)
|
||||
if (response.status === "pending") continue
|
||||
if (response.status === "success") {
|
||||
await Auth.set("github-copilot", {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue