@@ -43,6 +43,28 @@ export interface StoredAuth {
4343const AUTH_DIR = join ( homedir ( ) , '.config' , 'nano-opencode' ) ;
4444const PROVIDERS_FILE = join ( AUTH_DIR , 'auth-providers.json' ) ;
4545
46+ // OAuth response types
47+ interface DeviceCodeResponse {
48+ device_code : string ;
49+ user_code : string ;
50+ verification_uri ?: string ;
51+ verification_url ?: string ;
52+ verification_uri_complete ?: string ;
53+ interval ?: number ;
54+ }
55+
56+ interface TokenResponse {
57+ access_token ?: string ;
58+ refresh_token ?: string ;
59+ expires_in ?: number ;
60+ error ?: string ;
61+ error_description ?: string ;
62+ }
63+
64+ interface CopilotTokenResponse {
65+ token : string ;
66+ }
67+
4668/**
4769 * GitHub Copilot Auth Provider
4870 * Uses device flow OAuth to authenticate with GitHub Copilot subscription
@@ -73,7 +95,8 @@ export const copilotProvider: AuthProvider = {
7395 } ) ,
7496 } ) ;
7597
76- const { device_code, user_code, verification_uri, interval } = await deviceResponse . json ( ) ;
98+ const deviceData = await deviceResponse . json ( ) as DeviceCodeResponse ;
99+ const { device_code, user_code, verification_uri, interval } = deviceData ;
77100
78101 console . log ( `\n Visit: ${ verification_uri } ` ) ;
79102 console . log ( ` Enter code: ${ user_code } \n` ) ;
@@ -99,7 +122,7 @@ export const copilotProvider: AuthProvider = {
99122 } ) ,
100123 } ) ;
101124
102- const data = await tokenResponse . json ( ) ;
125+ const data = await tokenResponse . json ( ) as TokenResponse ;
103126
104127 if ( data . access_token ) {
105128 // Get Copilot token using GitHub token
@@ -144,7 +167,7 @@ async function getCopilotToken(githubToken: string): Promise<string> {
144167 } ) ;
145168
146169 if ( ! response . ok ) throw new Error ( 'Failed to get Copilot token' ) ;
147- const data = await response . json ( ) ;
170+ const data = await response . json ( ) as CopilotTokenResponse ;
148171 return data . token ;
149172}
150173
@@ -174,7 +197,7 @@ export const antigravityProvider: AuthProvider = {
174197 } ) ,
175198 } ) ;
176199
177- const { device_code, user_code, verification_url, interval } = await deviceResponse . json ( ) ;
200+ const { device_code, user_code, verification_url, interval } = await deviceResponse . json ( ) as DeviceCodeResponse ;
178201
179202 console . log ( `\n Visit: ${ verification_url } ` ) ;
180203 console . log ( ` Enter code: ${ user_code } \n` ) ;
@@ -195,7 +218,7 @@ export const antigravityProvider: AuthProvider = {
195218 } ) ,
196219 } ) ;
197220
198- const data = await tokenResponse . json ( ) ;
221+ const data = await tokenResponse . json ( ) as TokenResponse ;
199222
200223 if ( data . access_token ) {
201224 return {
@@ -225,7 +248,7 @@ export const antigravityProvider: AuthProvider = {
225248 } ) ,
226249 } ) ;
227250
228- const data = await response . json ( ) ;
251+ const data = await response . json ( ) as TokenResponse ;
229252 if ( ! data . access_token ) throw new Error ( 'Failed to refresh token' ) ;
230253
231254 return {
@@ -266,7 +289,7 @@ export const codexProvider: AuthProvider = {
266289 } ) ,
267290 } ) ;
268291
269- const { device_code, user_code, verification_uri_complete, interval } = await deviceResponse . json ( ) ;
292+ const { device_code, user_code, verification_uri_complete, interval } = await deviceResponse . json ( ) as DeviceCodeResponse ;
270293
271294 console . log ( `\n Visit: ${ verification_uri_complete } ` ) ;
272295 console . log ( ` Code will auto-fill, just confirm.\n` ) ;
@@ -287,7 +310,7 @@ export const codexProvider: AuthProvider = {
287310 } ) ,
288311 } ) ;
289312
290- const data = await tokenResponse . json ( ) ;
313+ const data = await tokenResponse . json ( ) as TokenResponse ;
291314
292315 if ( data . access_token ) {
293316 return {
@@ -317,7 +340,7 @@ export const codexProvider: AuthProvider = {
317340 } ) ,
318341 } ) ;
319342
320- const data = await response . json ( ) ;
343+ const data = await response . json ( ) as TokenResponse ;
321344 if ( ! data . access_token ) throw new Error ( 'Failed to refresh token' ) ;
322345
323346 return {
0 commit comments