Skip to content

Commit fe0f686

Browse files
authored
auth: emit user scopes in auth_userState (#5019)
1 parent 6583a32 commit fe0f686

File tree

5 files changed

+26
-4
lines changed

5 files changed

+26
-4
lines changed

packages/amazonq/src/auth/util.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import { AuthUtil } from 'aws-core-vscode/codewhisperer'
77
import { AuthStatus } from 'aws-core-vscode/telemetry'
8-
import { AwsConnection, Connection, AuthUtils } from 'aws-core-vscode/auth'
8+
import { AwsConnection, Connection, SsoConnection, AuthUtils } from 'aws-core-vscode/auth'
99
import { activateExtension, getLogger } from 'aws-core-vscode/shared'
1010
import { VSCODE_EXTENSION_ID } from 'aws-core-vscode/utils'
1111

@@ -15,6 +15,7 @@ export async function getAuthStatus() {
1515
const authState = (await AuthUtil.instance.getChatAuthState()).codewhispererChat
1616
let authEnabledConnections = AuthUtils.getAuthFormIdsFromConnection(AuthUtil.instance.conn)
1717
let authStatus: AuthStatus = authState === 'connected' || authState === 'expired' ? authState : 'notConnected'
18+
let authScopes: string[] = (AuthUtil.instance.conn as SsoConnection)?.scopes ?? []
1819

1920
// If the Q extension does not have its own connection, it will fallback and check
2021
// if the Toolkit extension can provide a connection that works with Q
@@ -33,10 +34,11 @@ export async function getAuthStatus() {
3334
// Though TS won't say it, AwsConnection sufficiently overlaps with Connection for the purposes
3435
// of `getAuthFormIdsFromConnection`
3536
authEnabledConnections = AuthUtils.getAuthFormIdsFromConnection(autoConnectConn as unknown as Connection)
37+
authScopes = autoConnectConn.scopes ?? []
3638
}
3739
}
3840

39-
return { authStatus, authEnabledConnections: authEnabledConnections.join(',') }
41+
return { authStatus, authEnabledConnections: authEnabledConnections.join(','), authScopes: authScopes.join(',') }
4042
}
4143

4244
/**

packages/amazonq/src/extensionShared.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,11 @@ export async function activateShared(context: vscode.ExtensionContext, isWeb: bo
156156
telemetry.record({ source: ExtStartUpSources.reload })
157157
}
158158

159-
const { authStatus, authEnabledConnections } = await getAuthStatus()
159+
const { authStatus, authEnabledConnections, authScopes } = await getAuthStatus()
160160
telemetry.record({
161161
authStatus,
162162
authEnabledConnections,
163+
authScopes,
163164
})
164165
})
165166
}

packages/core/src/auth/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*/
1111
export { initialize as initializeAuth } from './activation'
1212
export { initializeAwsCredentialsStatusBarItem } from './ui/statusBarItem'
13-
export { Connection, AwsConnection } from './connection'
13+
export { Connection, AwsConnection, SsoConnection } from './connection'
1414
export { Auth } from './auth'
1515
export { CredentialsStore } from './credentials/store'
1616
export { LoginManager } from './deprecated/loginManager'

packages/core/src/extensionShared.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import { ExtStartUpSources } from './shared/telemetry/util'
4646
import { ExtensionUse, getAuthFormIdsFromConnection } from './auth/utils'
4747
import { Auth } from './auth'
4848
import { AuthFormId } from './auth/ui/vue/authForms/types'
49+
import { isSsoConnection } from './auth/connection'
4950

5051
// In web mode everything must be in a single file, so things like the endpoints file will not be available.
5152
// The following imports the endpoints file, which causes webpack to bundle it in the final output file
@@ -256,6 +257,7 @@ export async function emitUserState() {
256257

257258
let authStatus: AuthStatus = 'notConnected'
258259
const enabledConnections: Set<AuthFormId> = new Set()
260+
const enabledScopes: Set<string> = new Set()
259261
if (Auth.instance.hasConnections) {
260262
authStatus = 'expired'
261263
;(await Auth.instance.listConnections()).forEach(conn => {
@@ -265,11 +267,15 @@ export async function emitUserState() {
265267
}
266268

267269
getAuthFormIdsFromConnection(conn).forEach(id => enabledConnections.add(id))
270+
if (isSsoConnection(conn)) {
271+
conn.scopes?.forEach(s => enabledScopes.add(s))
272+
}
268273
})
269274
}
270275
telemetry.record({
271276
authStatus,
272277
authEnabledConnections: [...enabledConnections].join(','),
278+
authScopes: [...enabledScopes].join(','),
273279
})
274280
})
275281
}

packages/core/src/shared/telemetry/vscodeTelemetry.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,11 @@
323323
"type": "string",
324324
"description": "Comma-delimited list of enabled auths."
325325
},
326+
{
327+
"name": "authScopes",
328+
"type": "string",
329+
"description": "Comma-delimited list of scopes that user has."
330+
},
326331
{
327332
"name": "region",
328333
"type": "string",
@@ -1116,6 +1121,10 @@
11161121
"type": "authStatus",
11171122
"required": true
11181123
},
1124+
{
1125+
"type": "authScopes",
1126+
"required": false
1127+
},
11191128
{
11201129
"type": "authEnabledConnections",
11211130
"required": true
@@ -1217,6 +1226,10 @@
12171226
"type": "authEnabledFeatures",
12181227
"required": false
12191228
},
1229+
{
1230+
"type": "authScopes",
1231+
"required": false
1232+
},
12201233
{
12211234
"type": "reason",
12221235
"required": false

0 commit comments

Comments
 (0)