Skip to content

Commit 762e43d

Browse files
committed
fix(amazonq): Add missing bearer token auth
1 parent 6afae55 commit 762e43d

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

packages/amazonq/src/lsp/auth.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import { RequestType, ResponseMessage } from '@aws/language-server-runtimes/protocol'
6+
import {
7+
ConnectionMetadata,
8+
NotificationType,
9+
RequestType,
10+
ResponseMessage,
11+
} from '@aws/language-server-runtimes/protocol'
712
import * as jose from 'jose'
813
import * as crypto from 'crypto'
914
import { LanguageClient } from 'vscode-languageclient'
@@ -43,12 +48,19 @@ export interface UpdateCredentialsRequest {
4348
encrypted: boolean
4449
}
4550

46-
const notificationTypes = {
51+
export const notificationTypes = {
4752
updateBearerToken: new RequestType<UpdateCredentialsRequest, ResponseMessage, Error>(
4853
'aws/credentials/token/update'
4954
),
55+
deleteBearerToken: new NotificationType('aws/credentials/token/delete'),
56+
getConnectionMetadata: new RequestType<undefined, ConnectionMetadata, Error>(
57+
'aws/credentials/getConnectionMetadata'
58+
),
5059
}
5160

61+
/**
62+
* Facade over our VSCode Auth that does crud operations on the language server auth
63+
*/
5264
export class AmazonQLSPAuth {
5365
constructor(private readonly client: LanguageClient) {}
5466

packages/amazonq/src/lsp/client.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ import * as cp from 'child_process'
99
import * as crypto from 'crypto'
1010
import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind } from 'vscode-languageclient'
1111
import { registerInlineCompletion } from '../inline/completion'
12-
import { AmazonQLSPAuth, writeEncryptionInit } from './auth'
12+
import { AmazonQLSPAuth, notificationTypes, writeEncryptionInit } from './auth'
1313
import { AuthUtil } from 'aws-core-vscode/codewhisperer'
14+
import { ConnectionMetadata } from '@aws/language-server-runtimes/protocol'
1415

1516
const localize = nls.loadMessageBundle()
1617

@@ -86,9 +87,21 @@ export function startLanguageServer(extensionContext: vscode.ExtensionContext, s
8687
await auth.init()
8788
registerInlineCompletion(client)
8889

90+
// Request handler for when the server wants to know about the clients auth connnection
91+
client.onRequest<ConnectionMetadata, Error>(notificationTypes.getConnectionMetadata.method, () => {
92+
return {
93+
sso: {
94+
startUrl: AuthUtil.instance.auth.startUrl,
95+
},
96+
}
97+
})
98+
8999
toDispose.push(
90100
AuthUtil.instance.auth.onDidChangeActiveConnection(async () => {
91101
await auth.init()
102+
}),
103+
AuthUtil.instance.auth.onDidDeleteConnection(async () => {
104+
client.sendNotification(notificationTypes.deleteBearerToken.method)
92105
})
93106
)
94107
})

0 commit comments

Comments
 (0)