Skip to content

Commit c9eb334

Browse files
authored
fix(amazonq): send sso startUrl on token update (aws#7148)
## Problem race conditions can occur with getConnectionMetadata ## Solution instead send the start url through the token update. When it's done this way you don't need to [set getConnectionMetadata](https://github.com/aws/language-server-runtimes/blob/5ba754af403a6f35cd771f27efb987c1580ae6b5/runtimes/runtimes/auth/auth.ts#L158) --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent e39a32b commit c9eb334

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

packages/amazonq/src/lsp/auth.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
*/
55

66
import {
7+
bearerCredentialsUpdateRequestType,
78
ConnectionMetadata,
89
NotificationType,
910
RequestType,
1011
ResponseMessage,
12+
UpdateCredentialsParams,
1113
} from '@aws/language-server-runtimes/protocol'
1214
import * as jose from 'jose'
1315
import * as crypto from 'crypto'
@@ -81,7 +83,7 @@ export class AmazonQLspAuth {
8183
token,
8284
})
8385

84-
await this.client.sendRequest(notificationTypes.updateBearerToken.method, request)
86+
await this.client.sendRequest(bearerCredentialsUpdateRequestType.method, request)
8587

8688
this.client.info(`UpdateBearerToken: ${JSON.stringify(request)}`)
8789
}
@@ -96,7 +98,7 @@ export class AmazonQLspAuth {
9698
return interval
9799
}
98100

99-
private async createUpdateCredentialsRequest(data: any) {
101+
private async createUpdateCredentialsRequest(data: any): Promise<UpdateCredentialsParams> {
100102
const payload = new TextEncoder().encode(JSON.stringify({ data }))
101103

102104
const jwt = await new jose.CompactEncrypt(payload)
@@ -105,6 +107,11 @@ export class AmazonQLspAuth {
105107

106108
return {
107109
data: jwt,
110+
metadata: {
111+
sso: {
112+
startUrl: AuthUtil.instance.auth.startUrl,
113+
},
114+
},
108115
encrypted: true,
109116
}
110117
}

packages/amazonq/src/lsp/client.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { LanguageClient, LanguageClientOptions, RequestType } from 'vscode-langu
1010
import { InlineCompletionManager } from '../app/inline/completion'
1111
import { AmazonQLspAuth, encryptionKey, notificationTypes } from './auth'
1212
import {
13-
ConnectionMetadata,
1413
CreateFilesParams,
1514
DeleteFilesParams,
1615
DidChangeWorkspaceFoldersParams,
@@ -164,14 +163,6 @@ export async function startLanguageServer(
164163
const auth = new AmazonQLspAuth(client)
165164

166165
return client.onReady().then(async () => {
167-
// Request handler for when the server wants to know about the clients auth connnection. Must be registered before the initial auth init call
168-
client.onRequest<ConnectionMetadata, Error>(notificationTypes.getConnectionMetadata.method, () => {
169-
return {
170-
sso: {
171-
startUrl: AuthUtil.instance.auth.startUrl,
172-
},
173-
}
174-
})
175166
await auth.refreshConnection()
176167

177168
if (Experiments.instance.get('amazonqLSPInline', false)) {

0 commit comments

Comments
 (0)