Skip to content

Commit 9d329a9

Browse files
authored
fix(auth): preserve old scopes if re-auth fails. show more helpful error message
Problem: If a connection fails due to not having valid scopes, the scopes are not reset. This soft-locks the user and new connections aren't possible until it is deleted in the quick pick. Solution: Restore scopes if that is the failure reason. Also, add a more helpful UI message to indicate why the sign on failed.
1 parent a5c7058 commit 9d329a9

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/auth/secondaryAuth.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { cast, Optional } from '../shared/utilities/typeConstructors'
1111
import { Auth } from './auth'
1212
import { once } from '../shared/utilities/functionUtils'
1313
import { isNonNullable } from '../shared/utilities/tsUtils'
14-
import { CancellationError } from '../shared/utilities/timeoutUtils'
1514
import { Connection, SsoConnection, StatefulConnection } from './connection'
1615

1716
let currentConn: Auth['activeConnection']
@@ -221,11 +220,11 @@ export class SecondaryAuth<T extends Connection = Connection> {
221220
try {
222221
return await this.auth.reauthenticate(updatedConn)
223222
} catch (e) {
224-
if (CancellationError.isUserCancelled(e)) {
225-
// We updated the connection scopes, but the user cancelled reauth.
226-
// Revert to old connection scopes, otherwise the new scopes persist.
227-
await updateConnectionScopes(oldScopes)
228-
}
223+
// We updated the connection scopes pre-emptively, but if there is some issue (e.g. user cancels,
224+
// InvalidGrantException, etc), then we need to revert to the old connection scopes. Otherwise,
225+
// this could soft-lock users into a broken connection that cannot be re-authenticated without
226+
// first deleting the connection.
227+
await updateConnectionScopes(oldScopes)
229228
throw e
230229
}
231230
}

src/auth/ui/vue/show.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import { Commands, VsCodeCommandArg, placeholder, vscodeComponent } from '../../
5252
import { ClassToInterfaceType } from '../../../shared/utilities/tsUtils'
5353
import { debounce } from 'lodash'
5454
import { submitFeedback } from '../../../feedback/vue/submitFeedback'
55+
import { InvalidGrantException } from '@aws-sdk/client-sso-oidc'
5556

5657
export class AuthWebview extends VueWebview {
5758
public override id: string = 'authWebview'
@@ -234,6 +235,13 @@ export class AuthWebview extends VueWebview {
234235
return { id: userCancelled, text: 'Setup cancelled.' }
235236
}
236237

238+
if (e instanceof ToolkitError && e.cause instanceof InvalidGrantException) {
239+
return {
240+
id: 'invalidGrantException',
241+
text: 'Permissions for this service may not be enabled by your SSO Admin, or the selected region may not be supported.',
242+
}
243+
}
244+
237245
if (
238246
e instanceof ToolkitError &&
239247
(e.code === trustedDomainCancellation || e.cause?.name === trustedDomainCancellation)

0 commit comments

Comments
 (0)