Skip to content

Commit b31f46b

Browse files
committed
Revert "Fix case where user can never login to Builder ID again"
This reverts commit 2ac6c35
1 parent 2ac6c35 commit b31f46b

File tree

2 files changed

+23
-24
lines changed

2 files changed

+23
-24
lines changed

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

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ 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)"))
9392
fun activeConnection(): ToolkitConnection?
9493

9594
fun activeConnectionForFeature(feature: FeatureWithPinnedConnection): ToolkitConnection?
@@ -123,15 +122,14 @@ fun loginSso(
123122
metadata: ConnectionMetadata? = null
124123
): AwsBearerTokenConnection? {
125124
val source = metadata
126-
fun createAndAuthNewConnection(isReAuth: Boolean, profile: AuthProfile): AwsBearerTokenConnection? {
125+
fun createAndAuthNewConnection(profile: AuthProfile): AwsBearerTokenConnection? {
127126
val authManager = ToolkitAuthManager.getInstance()
128127
val connection = try {
129128
authManager.tryCreateTransientSsoConnection(profile) { transientConnection ->
130129
reauthConnectionIfNeeded(
131130
project = project,
132131
connection = transientConnection,
133132
onPendingToken = onPendingToken,
134-
isReAuth = isReAuth
135133
)
136134
}
137135
} catch (e: Exception) {
@@ -151,8 +149,7 @@ fun loginSso(
151149

152150
val manager = ToolkitAuthManager.getInstance()
153151
val allScopes = requestedScopes.toMutableSet()
154-
var isReAuth = false
155-
val connection = manager.getConnection(connectionId)?.let { connection ->
152+
return manager.getConnection(connectionId)?.let { connection ->
156153
val logger = getLogger<ToolkitAuthManager>()
157154

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

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

197198
@Suppress("UnusedParameter")

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,6 @@ 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
225223
}
226224
}
227225

0 commit comments

Comments
 (0)