Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid incorrect reauth #5068

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.intellij.ui.dsl.builder.Align
import com.intellij.ui.dsl.builder.panel
import com.intellij.ui.jcef.JBCefJSQuery
import org.cef.CefApp
import software.amazon.awssdk.services.ssooidc.model.SsoOidcException
import software.aws.toolkits.core.utils.error
import software.aws.toolkits.core.utils.getLogger
import software.aws.toolkits.core.utils.warn
Expand All @@ -27,6 +28,8 @@ import software.aws.toolkits.jetbrains.core.credentials.actions.SsoLogoutAction
import software.aws.toolkits.jetbrains.core.credentials.pinning.QConnection
import software.aws.toolkits.jetbrains.core.credentials.sono.Q_SCOPES
import software.aws.toolkits.jetbrains.core.credentials.sono.isSono
import software.aws.toolkits.jetbrains.core.credentials.sso.bearer.BearerTokenProvider
import software.aws.toolkits.jetbrains.core.credentials.sso.bearer.BearerTokenProviderListener
import software.aws.toolkits.jetbrains.core.region.AwsRegionProvider
import software.aws.toolkits.jetbrains.core.webview.BrowserMessage
import software.aws.toolkits.jetbrains.core.webview.BrowserState
Expand Down Expand Up @@ -243,12 +246,27 @@ class QWebviewBrowser(val project: Project, private val parentDisposable: Dispos
writeValueAsString(it)
}

// TODO: pass "REAUTH" if connection expires
val stage = if (isQExpired(project)) {
"REAUTH"
val stage = if(isQExpired(project)) {
try {
val conn = ToolkitConnectionManager.getInstance(project).activeConnectionForFeature(QConnection.getInstance()) as? AwsBearerTokenConnection
val provider = conn?.getConnectionSettings()?.tokenProvider
val p = provider?.delegate as? BearerTokenProvider
p?.resolveToken()
provider?.id?.let { BearerTokenProviderListener.notifyCredUpdate(it) }
return
} catch (e: SsoOidcException) {
"REAUTH"
}

} else {
"START"
}
// TODO: pass "REAUTH" if connection expires
// val stage = if (isQExpired(project)) {
// "REAUTH"
// } else {
// "START"
// }

val jsonData = """
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import kotlinx.coroutines.delay
import kotlinx.coroutines.withTimeoutOrNull
import org.slf4j.LoggerFactory
import software.amazon.awssdk.services.ssooidc.model.SsoOidcException

Check warning on line 10 in plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/utils/FunctionUtils.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import directive

Unused import directive

Check warning

Code scanning / QDJVMC

Unused import directive Warning

Unused import directive
import software.aws.toolkits.core.utils.debug
import software.aws.toolkits.jetbrains.core.credentials.AwsBearerTokenConnection
import software.aws.toolkits.jetbrains.core.credentials.ToolkitConnectionManager
Expand Down Expand Up @@ -56,6 +57,7 @@
LOG.debug {
"qConnectionState: $qState; cwConnectionState: $cwState"
}

return qState == BearerTokenAuthState.NEEDS_REFRESH || cwState == BearerTokenAuthState.NEEDS_REFRESH
}

Expand Down
Loading