1- import { AuthenticationSession as AuthSession , AuthenticationSession } from 'vscode'
1+ import { AuthenticationSession as AuthSession , AuthenticationProviderSessionOptions , AuthenticationSession } from 'vscode'
22import { genVerifyChallengePair } from '@/service/code-challenge'
33import {
44 authentication ,
@@ -22,7 +22,7 @@ import { LocalState } from '@/ctx/local-state'
2222import { ExtConst } from '@/ctx/ext-const'
2323import { UserService } from '@/service/user.service'
2424
25- async function browserSignIn ( challengeCode : string , scopes : string [ ] ) {
25+ async function browserSignIn ( challengeCode : string , scopes : readonly string [ ] ) {
2626 const para = consUrlPara (
2727 [ 'client_id' , ExtConst . CLIENT_ID ] ,
2828 [ 'client_secret' , ExtConst . CLIENT_SEC ] ,
@@ -39,7 +39,7 @@ async function browserSignIn(challengeCode: string, scopes: string[]) {
3939 try {
4040 await env . openExternal ( uri )
4141 } catch ( e ) {
42- void Alert . err ( `重定向失败: ${ < string > e } ` )
42+ void Alert . err ( `重定向失败: ${ e as string } ` )
4343 }
4444}
4545
@@ -73,18 +73,18 @@ export class AuthProvider implements AuthenticationProvider, Disposable {
7373 this . _usePat = true
7474 }
7575
76- async getSessions ( scopes ?: string [ ] ) : Promise < readonly AuthSession [ ] > {
76+ async getSessions ( scopes : readonly string [ ] | undefined , options : AuthenticationProviderSessionOptions ) :
77+ Promise < AuthenticationSession [ ] > {
7778 const sessions = await this . getAllSessions ( )
7879 const parsedScopes = this . ensureScopes ( scopes )
79-
8080 return sessions . filter ( ( { scopes : sessionScopes } ) => parsedScopes . every ( x => sessionScopes . includes ( x ) ) )
8181 }
8282
8383 createSession ( scopes : string [ ] ) {
8484 return this . _usePat ? this . createSessionFromPat ( scopes ) : this . createSessionFromBrowser ( scopes )
8585 }
8686
87- // eslint-disable-next-line @typescript-eslint/no-unused-vars
87+
8888 async createSessionFromPat ( scopes : string [ ] ) {
8989 const validateInput = ( value : string ) => {
9090 if ( value . trim ( ) . length === 0 )
@@ -181,7 +181,7 @@ export class AuthProvider implements AuthenticationProvider, Disposable {
181181 else keep . push ( s )
182182 return { remove, keep }
183183 } ,
184- { remove : < AuthSession [ ] > [ ] , keep : < AuthSession [ ] > [ ] }
184+ { remove : [ ] as AuthSession [ ] , keep : [ ] as AuthSession [ ] }
185185 )
186186 await LocalState . setSecret ( ExtConst . EXT_SESSION_STORAGE_KEY , JSON . stringify ( data . keep ) )
187187 this . _sessionChangeEmitter . fire ( { removed : data . remove , added : undefined , changed : undefined } )
@@ -204,15 +204,15 @@ export class AuthProvider implements AuthenticationProvider, Disposable {
204204
205205 const { accountId, displayName } = userInfo
206206
207- const session = < AuthenticationSession > {
207+ const session = {
208208 account : {
209209 id : new Number ( accountId ) . toString ( ) ,
210210 label : displayName ,
211211 } ,
212212 id : `${ this . providerId } -${ userInfo . accountId } ` ,
213213 accessToken : token ,
214- scopes : this . ensureScopes ( null ) ,
215- }
214+ scopes : this . ensureScopes ( undefined ) ,
215+ } as AuthenticationSession
216216
217217 await LocalState . setSecret ( ExtConst . EXT_SESSION_STORAGE_KEY , JSON . stringify ( [ session ] ) )
218218
@@ -239,9 +239,9 @@ export class AuthProvider implements AuthenticationProvider, Disposable {
239239 }
240240
241241 private ensureScopes (
242- scopes : string [ ] | null | undefined ,
242+ scopes : readonly string [ ] | undefined ,
243243 { default : defaultScopes = ExtConst . OAUTH_SCOPES } = { }
244- ) : string [ ] {
244+ ) : readonly string [ ] {
245245 return scopes == null || scopes . length <= 0 ? defaultScopes : scopes
246246 }
247247}
0 commit comments