@@ -21,17 +21,28 @@ export class GitHubClient {
2121 return this . _repo ;
2222 }
2323
24- private async getAuthToken ( ) : Promise < string | undefined > {
24+ private async getAuthToken ( reAuthenticate = false ) : Promise < string | undefined > {
2525 try {
26- const session = await authentication . getSession ( 'github' , [ 'repo' ] , { createIfNone : true } ) ;
26+ const scope = [ 'repo' ] ;
27+ const session = reAuthenticate
28+ ? await authentication . getSession ( 'github' , scope , {
29+ forceNewSession : true ,
30+ clearSessionPreference : true ,
31+ } )
32+ : await authentication . getSession ( 'github' , scope , { createIfNone : true } ) ;
2733 return session . accessToken ;
2834 } catch ( error ) {
2935 throw new Error ( `GitHub authentication failed: ${ error } ` ) ;
3036 }
3137 }
3238
33- private async makeRequest < T > ( endpoint : string , method : string = 'GET' , body ?: any ) : Promise < T > {
34- const token = await this . getAuthToken ( ) ;
39+ private async makeRequest < T > (
40+ endpoint : string ,
41+ method : string = 'GET' ,
42+ body ?: any ,
43+ reAuthenticate = false
44+ ) : Promise < T > {
45+ const token = await this . getAuthToken ( reAuthenticate ) ;
3546 const url = `${ GitHubClient . BASE_URL } ${ endpoint } ` ;
3647
3748 const headers : { [ key : string ] : string } = {
@@ -62,6 +73,10 @@ export class GitHubClient {
6273 } ) ;
6374
6475 res . on ( 'end' , ( ) => {
76+ if ( res . statusCode && res . statusCode === 403 ) {
77+ // todo: add reauthenticate method and retry
78+ }
79+
6580 if ( res . statusCode && res . statusCode >= 200 && res . statusCode < 300 ) {
6681 try {
6782 resolve ( JSON . parse ( data ) ) ;
0 commit comments