Skip to content

Commit 2ac6c35

Browse files
committed
Fix case where user can never login to Builder ID again
1 parent 3d77141 commit 2ac6c35

File tree

2 files changed

+24
-23
lines changed

2 files changed

+24
-23
lines changed

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/credentials/ToolkitAuthManager.kt

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ interface ToolkitStartupAuthFactory {
8989
}
9090

9191
interface ToolkitConnectionManager : Disposable {
92+
@Deprecated("Fragile API. Probably leads to unexpected behavior. Use only for toolkit explorer dropdown state.", ReplaceWith("activeConnectionForFeature(feature)"))
9293
fun activeConnection(): ToolkitConnection?
9394

9495
fun activeConnectionForFeature(feature: FeatureWithPinnedConnection): ToolkitConnection?
@@ -122,14 +123,15 @@ fun loginSso(
122123
metadata: ConnectionMetadata? = null
123124
): AwsBearerTokenConnection? {
124125
val source = metadata
125-
fun createAndAuthNewConnection(profile: AuthProfile): AwsBearerTokenConnection? {
126+
fun createAndAuthNewConnection(isReAuth: Boolean, profile: AuthProfile): AwsBearerTokenConnection? {
126127
val authManager = ToolkitAuthManager.getInstance()
127128
val connection = try {
128129
authManager.tryCreateTransientSsoConnection(profile) { transientConnection ->
129130
reauthConnectionIfNeeded(
130131
project = project,
131132
connection = transientConnection,
132133
onPendingToken = onPendingToken,
134+
isReAuth = isReAuth
133135
)
134136
}
135137
} catch (e: Exception) {
@@ -149,7 +151,8 @@ fun loginSso(
149151

150152
val manager = ToolkitAuthManager.getInstance()
151153
val allScopes = requestedScopes.toMutableSet()
152-
return manager.getConnection(connectionId)?.let { connection ->
154+
var isReAuth = false
155+
val connection = manager.getConnection(connectionId)?.let { connection ->
153156
val logger = getLogger<ToolkitAuthManager>()
154157

155158
if (connection !is AwsBearerTokenConnection) {
@@ -167,32 +170,28 @@ fun loginSso(
167170
""".trimIndent()
168171
}
169172
// can't reuse since requested scopes are not in current connection. forcing reauth
170-
return createAndAuthNewConnection(
171-
ManagedSsoProfile(
172-
region,
173-
startUrl,
174-
allScopes.toList()
175-
)
176-
)
173+
return@let null
177174
}
178175

179176
// For the case when the existing connection is in invalid state, we need to re-auth
180-
reauthConnectionIfNeeded(
181-
project = project,
182-
connection = connection,
183-
isReAuth = true
184-
)
177+
isReAuth = true
178+
return@let null
179+
}
180+
181+
// never true?
182+
if (connection != null) {
185183
return connection
186-
} ?: run {
187-
// No existing connection, start from scratch
188-
createAndAuthNewConnection(
189-
ManagedSsoProfile(
190-
region,
191-
startUrl,
192-
allScopes.toList()
193-
)
194-
)
195184
}
185+
186+
// No existing connection, start from scratch
187+
return createAndAuthNewConnection(
188+
isReAuth = isReAuth,
189+
ManagedSsoProfile(
190+
region,
191+
startUrl,
192+
allScopes.toList()
193+
)
194+
)
196195
}
197196

198197
@Suppress("UnusedParameter")

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/webview/LoginBrowser.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ abstract class LoginBrowser(
220220
Login
221221
.BuilderId(scopes, onPendingToken, onError, onSuccess)
222222
.login(project)
223+
224+
// TODO refresh the pane here for case when provider is no-op (i.e. provider exists and has a valid token), to fix issue where user is stuck waiting for browser
223225
}
224226
}
225227

0 commit comments

Comments
 (0)