@@ -12,7 +12,6 @@ import {
12
12
UpdateAuthInfoEvent ,
13
13
emptyAuthInfo ,
14
14
getSecretForAuthInfo ,
15
- getSiteInfoKey ,
16
15
isOAuthInfo ,
17
16
oauthProviderForSite ,
18
17
} from './authInfo' ;
@@ -92,7 +91,7 @@ export class CredentialManager implements Disposable {
92
91
}
93
92
}
94
93
95
- this . _memStore . set ( site . product . key , productAuths . set ( getSiteInfoKey ( site ) , info ) ) ;
94
+ this . _memStore . set ( site . product . key , productAuths . set ( site . credentialId , info ) ) ;
96
95
97
96
const hasNewInfo =
98
97
! existingInfo ||
@@ -108,7 +107,7 @@ export class CredentialManager implements Disposable {
108
107
}
109
108
110
109
try {
111
- this . addSiteInformationToSecretStorage ( site , info ) ;
110
+ this . addSiteInformationToSecretStorage ( site . product . key , site . credentialId , info ) ;
112
111
const updateEvent : UpdateAuthInfoEvent = { type : AuthChangeType . Update , site : site } ;
113
112
this . _onDidAuthChange . fire ( updateEvent ) ;
114
113
} catch ( e ) {
@@ -125,8 +124,8 @@ export class CredentialManager implements Disposable {
125
124
let foundInfo : AuthInfo | undefined = undefined ;
126
125
const productAuths = this . _memStore . get ( site . product . key ) ;
127
126
128
- if ( allowCache && productAuths && productAuths . has ( getSiteInfoKey ( site ) ) ) {
129
- foundInfo = productAuths . get ( getSiteInfoKey ( site ) ) ;
127
+ if ( allowCache && productAuths && productAuths . has ( site . credentialId ) ) {
128
+ foundInfo = productAuths . get ( site . credentialId ) ;
130
129
if ( foundInfo ) {
131
130
// clone the object so editing it and saving it back doesn't trip up equality checks
132
131
// in saveAuthInfo
@@ -136,20 +135,24 @@ export class CredentialManager implements Disposable {
136
135
137
136
if ( ! foundInfo ) {
138
137
try {
139
- let infoEntry = await this . getAuthInfoFromSecretStorage ( site ) ;
138
+ let infoEntry = await this . getAuthInfoFromSecretStorage ( site . product . key , site . credentialId ) ;
140
139
// if no authinfo found in secretstorage
141
140
if ( ! infoEntry ) {
142
141
// we first check if keychain exists and if it does then we migrate users from keychain to secretstorage
143
142
// without them having to relogin manually
144
143
if ( keychain ) {
145
- infoEntry = await this . getAuthInfoFromKeychain ( site ) ;
144
+ infoEntry = await this . getAuthInfoFromKeychain ( site . product . key , site . credentialId ) ;
146
145
if ( infoEntry ) {
147
146
Logger . debug (
148
147
`adding info from keychain to secretstorage for product: ${ site . product . key } credentialID: ${ site . credentialId } ` ,
149
148
) ;
150
- await this . addSiteInformationToSecretStorage ( site , infoEntry ) ;
149
+ await this . addSiteInformationToSecretStorage (
150
+ site . product . key ,
151
+ site . credentialId ,
152
+ infoEntry ,
153
+ ) ;
151
154
// Once authinfo has been stored in the secretstorage, info in keychain is no longer needed so removing it
152
- await this . removeSiteInformationFromKeychain ( site ) ;
155
+ await this . removeSiteInformationFromKeychain ( site . product . key , site . credentialId ) ;
153
156
} else if ( Container . siteManager . getSiteForId ( site . product , site . id ) ) {
154
157
// if keychain does not have any auth info for the current site but the site has been saved, we need to remove it
155
158
Logger . debug (
@@ -176,7 +179,7 @@ export class CredentialManager implements Disposable {
176
179
}
177
180
}
178
181
if ( infoEntry && productAuths ) {
179
- this . _memStore . set ( site . product . key , productAuths . set ( getSiteInfoKey ( site ) , infoEntry ) ) ;
182
+ this . _memStore . set ( site . product . key , productAuths . set ( site . credentialId , infoEntry ) ) ;
180
183
181
184
foundInfo = infoEntry ;
182
185
}
@@ -206,48 +209,54 @@ export class CredentialManager implements Disposable {
206
209
}
207
210
}
208
211
209
- private async addSiteInformationToSecretStorage ( site : DetailedSiteInfo , info : AuthInfo ) {
212
+ private async addSiteInformationToSecretStorage ( productKey : string , credentialId : string , info : AuthInfo ) {
210
213
await this . _queue . add (
211
214
async ( ) => {
212
215
try {
213
- await Container . context . secrets . store ( getSiteInfoKey ( site ) , JSON . stringify ( info ) ) ;
216
+ await Container . context . secrets . store ( ` ${ productKey } - ${ credentialId } ` , JSON . stringify ( info ) ) ;
214
217
} catch ( e ) {
215
218
Logger . error ( e , `Error writing to secretstorage` ) ;
216
219
}
217
220
} ,
218
221
{ priority : Priority . Write } ,
219
222
) ;
220
223
}
221
- private async getSiteInformationFromSecretStorage ( site : DetailedSiteInfo ) : Promise < string | undefined > {
224
+ private async getSiteInformationFromSecretStorage (
225
+ productKey : string ,
226
+ credentialId : string ,
227
+ ) : Promise < string | undefined > {
222
228
let info : string | undefined = undefined ;
223
229
await this . _queue . add (
224
230
async ( ) => {
225
- info = await Container . context . secrets . get ( getSiteInfoKey ( site ) ) ;
231
+ info = await Container . context . secrets . get ( ` ${ productKey } - ${ credentialId } ` ) ;
226
232
} ,
227
233
{ priority : Priority . Read } ,
228
234
) ;
229
235
return info ;
230
236
}
231
- private async removeSiteInformationFromSecretStorage ( site : DetailedSiteInfo ) : Promise < boolean > {
237
+ private async removeSiteInformationFromSecretStorage ( productKey : string , credentialId : string ) : Promise < boolean > {
232
238
let wasKeyDeleted = false ;
233
239
await this . _queue . add (
234
240
async ( ) => {
235
- const storedInfo = await Container . context . secrets . get ( getSiteInfoKey ( site ) ) ;
241
+ const storedInfo = await Container . context . secrets . get ( ` ${ productKey } - ${ credentialId } ` ) ;
236
242
if ( storedInfo ) {
237
- await Container . context . secrets . delete ( getSiteInfoKey ( site ) ) ;
243
+ await Container . context . secrets . delete ( ` ${ productKey } - ${ credentialId } ` ) ;
238
244
wasKeyDeleted = true ;
239
245
}
240
246
} ,
241
247
{ priority : Priority . Write } ,
242
248
) ;
243
249
return wasKeyDeleted ;
244
250
}
245
- private async removeSiteInformationFromKeychain ( site : DetailedSiteInfo ) : Promise < boolean > {
251
+ private async removeSiteInformationFromKeychain ( productKey : string , credentialId : string ) : Promise < boolean > {
246
252
let wasKeyDeleted = false ;
247
253
await this . _queue . add (
248
254
async ( ) => {
249
255
if ( keychain ) {
250
- wasKeyDeleted = await keychain . deletePassword ( keychainServiceNameV3 , getSiteInfoKey ( site ) ) ;
256
+ wasKeyDeleted = await keychain . deletePassword (
257
+ keychainServiceNameV3 ,
258
+ `${ productKey } -${ credentialId } ` ,
259
+ ) ;
251
260
}
252
261
} ,
253
262
{ priority : Priority . Write } ,
@@ -256,14 +265,13 @@ export class CredentialManager implements Disposable {
256
265
}
257
266
258
267
private async getAuthInfoFromSecretStorage (
259
- site : DetailedSiteInfo ,
268
+ productKey : string ,
269
+ credentialId : string ,
260
270
serviceName ?: string ,
261
271
) : Promise < AuthInfo | undefined > {
262
- Logger . debug (
263
- `Retrieving secretstorage info for product: ${ site . product . key } credentialID: ${ site . credentialId } ` ,
264
- ) ;
272
+ Logger . debug ( `Retrieving secretstorage info for product: ${ productKey } credentialID: ${ credentialId } ` ) ;
265
273
let authInfo : string | undefined = undefined ;
266
- authInfo = await this . getSiteInformationFromSecretStorage ( site ) ;
274
+ authInfo = await this . getSiteInformationFromSecretStorage ( productKey , credentialId ) ;
267
275
if ( ! authInfo ) {
268
276
return undefined ;
269
277
}
@@ -275,8 +283,12 @@ export class CredentialManager implements Disposable {
275
283
}
276
284
return info ;
277
285
}
278
- private async getAuthInfoFromKeychain ( site : DetailedSiteInfo , serviceName ?: string ) : Promise < AuthInfo | undefined > {
279
- Logger . debug ( `Retrieving keychain info for product: ${ site . product . key } credentialID: ${ site . credentialId } ` ) ;
286
+ private async getAuthInfoFromKeychain (
287
+ productKey : string ,
288
+ credentialId : string ,
289
+ serviceName ?: string ,
290
+ ) : Promise < AuthInfo | undefined > {
291
+ Logger . debug ( `Retrieving keychain info for product: ${ productKey } credentialID: ${ credentialId } ` ) ;
280
292
let svcName = keychainServiceNameV3 ;
281
293
282
294
if ( serviceName ) {
@@ -287,7 +299,7 @@ export class CredentialManager implements Disposable {
287
299
await this . _queue . add (
288
300
async ( ) => {
289
301
if ( keychain ) {
290
- authInfo = await keychain . getPassword ( svcName , getSiteInfoKey ( site ) ) ;
302
+ authInfo = await keychain . getPassword ( svcName , ` ${ productKey } - ${ credentialId } ` ) ;
291
303
}
292
304
} ,
293
305
{ priority : Priority . Read } ,
@@ -348,11 +360,11 @@ export class CredentialManager implements Disposable {
348
360
let wasKeyDeleted = false ;
349
361
let wasMemDeleted = false ;
350
362
if ( productAuths ) {
351
- wasMemDeleted = productAuths . delete ( getSiteInfoKey ( site ) ) ;
363
+ wasMemDeleted = productAuths . delete ( site . credentialId ) ;
352
364
this . _memStore . set ( site . product . key , productAuths ) ;
353
365
}
354
366
355
- wasKeyDeleted = await this . removeSiteInformationFromSecretStorage ( site ) ;
367
+ wasKeyDeleted = await this . removeSiteInformationFromSecretStorage ( site . product . key , site . credentialId ) ;
356
368
if ( wasMemDeleted || wasKeyDeleted ) {
357
369
const cmdctx = this . commandContextFor ( site . product ) ;
358
370
if ( cmdctx ) {
@@ -365,7 +377,6 @@ export class CredentialManager implements Disposable {
365
377
type : AuthChangeType . Remove ,
366
378
product : site . product ,
367
379
credentialId : site . credentialId ,
368
- host : site . host ,
369
380
} ;
370
381
this . _onDidAuthChange . fire ( removeEvent ) ;
371
382
0 commit comments