Skip to content

Commit

Permalink
Revert "Fix case where user can never login to Builder ID again"
Browse files Browse the repository at this point in the history
This reverts commit 2ac6c35
  • Loading branch information
rli committed Sep 26, 2024
1 parent 2ac6c35 commit b31f46b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ interface ToolkitStartupAuthFactory {
}

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

fun activeConnectionForFeature(feature: FeatureWithPinnedConnection): ToolkitConnection?
Expand Down Expand Up @@ -123,15 +122,14 @@ fun loginSso(
metadata: ConnectionMetadata? = null
): AwsBearerTokenConnection? {
val source = metadata
fun createAndAuthNewConnection(isReAuth: Boolean, profile: AuthProfile): AwsBearerTokenConnection? {
fun createAndAuthNewConnection(profile: AuthProfile): AwsBearerTokenConnection? {
val authManager = ToolkitAuthManager.getInstance()
val connection = try {
authManager.tryCreateTransientSsoConnection(profile) { transientConnection ->
reauthConnectionIfNeeded(
project = project,
connection = transientConnection,
onPendingToken = onPendingToken,
isReAuth = isReAuth
)
}
} catch (e: Exception) {
Expand All @@ -151,8 +149,7 @@ fun loginSso(

val manager = ToolkitAuthManager.getInstance()
val allScopes = requestedScopes.toMutableSet()
var isReAuth = false
val connection = manager.getConnection(connectionId)?.let { connection ->
return manager.getConnection(connectionId)?.let { connection ->
val logger = getLogger<ToolkitAuthManager>()

if (connection !is AwsBearerTokenConnection) {
Expand All @@ -170,28 +167,32 @@ fun loginSso(
""".trimIndent()
}
// can't reuse since requested scopes are not in current connection. forcing reauth
return@let null
return createAndAuthNewConnection(
ManagedSsoProfile(
region,
startUrl,
allScopes.toList()
)
)
}

// For the case when the existing connection is in invalid state, we need to re-auth
isReAuth = true
return@let null
}

// never true?
if (connection != null) {
reauthConnectionIfNeeded(
project = project,
connection = connection,
isReAuth = true
)
return connection
}

// No existing connection, start from scratch
return createAndAuthNewConnection(
isReAuth = isReAuth,
ManagedSsoProfile(
region,
startUrl,
allScopes.toList()
} ?: run {
// No existing connection, start from scratch
createAndAuthNewConnection(
ManagedSsoProfile(
region,
startUrl,
allScopes.toList()
)
)
)
}
}

@Suppress("UnusedParameter")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,6 @@ abstract class LoginBrowser(
Login
.BuilderId(scopes, onPendingToken, onError, onSuccess)
.login(project)

// 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
}
}

Expand Down

0 comments on commit b31f46b

Please sign in to comment.