Fix connect button behavior for Oauth by making sure that scope is included in client metadata when client is registered.

- In auth.ts
    - in InspectorOAuthClientProvider constructor
      - add optional scope param
      - set instance var this.scope to scope param
    - in clientMetadata getter
      - add scope param set to this.scope or ""
  - in useConnection.ts
    - in handleAuthError handler
      - move instantiation of serverAuthProvider until after scope has been determined
      - pass scope to InspectorOAuthClientProvider constructor
This commit is contained in:
cliffhall 2025-08-15 18:40:21 -04:00
commit 5323d4d8f4

View file

@ -319,8 +319,6 @@ export function useConnection({
const handleAuthError = async (error: unknown) => {
if (is401Error(error)) {
const serverAuthProvider = new InspectorOAuthClientProvider(sseUrl);
let scope = oauthScope?.trim();
if (!scope) {
// Only discover resource metadata when we need to discover scopes
@ -334,6 +332,7 @@ export function useConnection({
}
scope = await discoverScopes(sseUrl, resourceMetadata);
}
const serverAuthProvider = new InspectorOAuthClientProvider(sseUrl, scope);
const result = await auth(serverAuthProvider, {
serverUrl: sseUrl,