1
- import { AuthenticationSession as AuthSession , AuthenticationSession } from 'vscode'
1
+ import { AuthenticationSession as AuthSession , AuthenticationProviderSessionOptions , AuthenticationSession } from 'vscode'
2
2
import { genVerifyChallengePair } from '@/service/code-challenge'
3
3
import {
4
4
authentication ,
@@ -22,7 +22,7 @@ import { LocalState } from '@/ctx/local-state'
22
22
import { ExtConst } from '@/ctx/ext-const'
23
23
import { UserService } from '@/service/user.service'
24
24
25
- async function browserSignIn ( challengeCode : string , scopes : string [ ] ) {
25
+ async function browserSignIn ( challengeCode : string , scopes : readonly string [ ] ) {
26
26
const para = consUrlPara (
27
27
[ 'client_id' , ExtConst . CLIENT_ID ] ,
28
28
[ 'client_secret' , ExtConst . CLIENT_SEC ] ,
@@ -39,7 +39,7 @@ async function browserSignIn(challengeCode: string, scopes: string[]) {
39
39
try {
40
40
await env . openExternal ( uri )
41
41
} catch ( e ) {
42
- void Alert . err ( `重定向失败: ${ < string > e } ` )
42
+ void Alert . err ( `重定向失败: ${ e as string } ` )
43
43
}
44
44
}
45
45
@@ -73,18 +73,18 @@ export class AuthProvider implements AuthenticationProvider, Disposable {
73
73
this . _usePat = true
74
74
}
75
75
76
- async getSessions ( scopes ?: string [ ] ) : Promise < readonly AuthSession [ ] > {
76
+ async getSessions ( scopes : readonly string [ ] | undefined , options : AuthenticationProviderSessionOptions ) :
77
+ Promise < AuthenticationSession [ ] > {
77
78
const sessions = await this . getAllSessions ( )
78
79
const parsedScopes = this . ensureScopes ( scopes )
79
-
80
80
return sessions . filter ( ( { scopes : sessionScopes } ) => parsedScopes . every ( x => sessionScopes . includes ( x ) ) )
81
81
}
82
82
83
83
createSession ( scopes : string [ ] ) {
84
84
return this . _usePat ? this . createSessionFromPat ( scopes ) : this . createSessionFromBrowser ( scopes )
85
85
}
86
86
87
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
87
+
88
88
async createSessionFromPat ( scopes : string [ ] ) {
89
89
const validateInput = ( value : string ) => {
90
90
if ( value . trim ( ) . length === 0 )
@@ -181,7 +181,7 @@ export class AuthProvider implements AuthenticationProvider, Disposable {
181
181
else keep . push ( s )
182
182
return { remove, keep }
183
183
} ,
184
- { remove : < AuthSession [ ] > [ ] , keep : < AuthSession [ ] > [ ] }
184
+ { remove : [ ] as AuthSession [ ] , keep : [ ] as AuthSession [ ] }
185
185
)
186
186
await LocalState . setSecret ( ExtConst . EXT_SESSION_STORAGE_KEY , JSON . stringify ( data . keep ) )
187
187
this . _sessionChangeEmitter . fire ( { removed : data . remove , added : undefined , changed : undefined } )
@@ -204,15 +204,15 @@ export class AuthProvider implements AuthenticationProvider, Disposable {
204
204
205
205
const { accountId, displayName } = userInfo
206
206
207
- const session = < AuthenticationSession > {
207
+ const session = {
208
208
account : {
209
209
id : new Number ( accountId ) . toString ( ) ,
210
210
label : displayName ,
211
211
} ,
212
212
id : `${ this . providerId } -${ userInfo . accountId } ` ,
213
213
accessToken : token ,
214
- scopes : this . ensureScopes ( null ) ,
215
- }
214
+ scopes : this . ensureScopes ( undefined ) ,
215
+ } as AuthenticationSession
216
216
217
217
await LocalState . setSecret ( ExtConst . EXT_SESSION_STORAGE_KEY , JSON . stringify ( [ session ] ) )
218
218
@@ -239,9 +239,9 @@ export class AuthProvider implements AuthenticationProvider, Disposable {
239
239
}
240
240
241
241
private ensureScopes (
242
- scopes : string [ ] | null | undefined ,
242
+ scopes : readonly string [ ] | undefined ,
243
243
{ default : defaultScopes = ExtConst . OAUTH_SCOPES } = { }
244
- ) : string [ ] {
244
+ ) : readonly string [ ] {
245
245
return scopes == null || scopes . length <= 0 ? defaultScopes : scopes
246
246
}
247
247
}
0 commit comments