@@ -18,7 +18,6 @@ const warnOnce = onceChanged((s: string, url: string) => {
18
18
showMessageWithUrl ( s , url , undefined , 'error' )
19
19
} )
20
20
21
- export const ssoScope = 'sso:account:access'
22
21
export const codecatalystScopes = [ 'codecatalyst:read_write' ]
23
22
export const ssoAccountAccessScopes = [ 'sso:account:access' ]
24
23
export const codewhispererScopes = [ 'codewhisperer:completions' , 'codewhisperer:analysis' ]
@@ -256,13 +255,14 @@ export async function loadIamProfilesIntoStore(store: ProfileStore, manager: Cre
256
255
}
257
256
258
257
/**
259
- * Fetches profiles from the given SSO ("IAM Identity Center", "IdC") connection.
258
+ * Gets credentials profiles constructed from roles ("Permission Sets") discovered from the given
259
+ * SSO ("IAM Identity Center", "IdC") connection.
260
260
*/
261
261
export async function * loadLinkedProfilesIntoStore (
262
262
store : ProfileStore ,
263
- source : SsoConnection [ 'id' ] ,
264
- client : SsoClient ,
265
- startUrl : string
263
+ sourceId : SsoConnection [ 'id' ] ,
264
+ ssoProfile : StoredProfile < SsoProfile > ,
265
+ client : SsoClient
266
266
) {
267
267
const accounts = new Set < string > ( )
268
268
const found = new Set < Connection [ 'id' ] > ( )
@@ -278,7 +278,7 @@ export async function* loadLinkedProfilesIntoStore(
278
278
279
279
for await ( const info of stream ) {
280
280
const name = `${ info . roleName } -${ info . accountId } `
281
- const id = `sso:${ source } #${ name } `
281
+ const id = `sso:${ sourceId } #${ name } `
282
282
found . add ( id )
283
283
284
284
if ( store . getProfile ( id ) !== undefined ) {
@@ -289,21 +289,21 @@ export async function* loadLinkedProfilesIntoStore(
289
289
name,
290
290
type : 'iam' ,
291
291
subtype : 'linked' ,
292
- ssoSession : source ,
292
+ ssoSession : sourceId ,
293
293
ssoRoleName : info . roleName ,
294
294
ssoAccountId : info . accountId ,
295
295
} )
296
296
297
297
yield [ id , profile ] as const
298
298
}
299
299
300
- const isBuilderId = startUrl === builderIdStartUrl // Special case.
301
- if ( ! isBuilderId && ( accounts . size === 0 || found . size === 0 ) ) {
302
- const name = truncateStartUrl ( startUrl )
303
- // Possible causes:
304
- // - SSO org has no "Permission sets"
300
+ /** Does `ssoProfile` have scopes other than "sso:account:access"? */
301
+ const hasScopes = ! ! ssoProfile . scopes ?. some ( s => ! ssoAccountAccessScopes . includes ( s ) )
302
+ if ( ! hasScopes && ( accounts . size === 0 || found . size === 0 ) ) {
303
+ // SSO user has no OIDC scopes nor IAM roles. Possible causes:
305
304
// - user is not an "Assigned user" in any account in the SSO org
306
- // - user is an "Assigned user" but no "Permission sets"
305
+ // - SSO org has no "Permission sets"
306
+ const name = truncateStartUrl ( ssoProfile . startUrl )
307
307
if ( accounts . size === 0 ) {
308
308
getLogger ( ) . warn ( 'auth: SSO org (%s) returned no accounts' , name )
309
309
} else if ( found . size === 0 ) {
@@ -317,7 +317,12 @@ export async function* loadLinkedProfilesIntoStore(
317
317
318
318
// Clean-up stale references in case the user no longer has access
319
319
for ( const [ id , profile ] of store . listProfiles ( ) ) {
320
- if ( profile . type === 'iam' && profile . subtype === 'linked' && profile . ssoSession === source && ! found . has ( id ) ) {
320
+ if (
321
+ profile . type === 'iam' &&
322
+ profile . subtype === 'linked' &&
323
+ profile . ssoSession === sourceId &&
324
+ ! found . has ( id )
325
+ ) {
321
326
await store . deleteProfile ( id )
322
327
}
323
328
}
0 commit comments