link to open auth page

This commit is contained in:
Nate 2025-04-22 18:13:56 -07:00
parent b398305ac4
commit 51736306e0
2 changed files with 41 additions and 10 deletions

View file

@ -3,12 +3,17 @@ package com.github.continuedev.continueintellijextension.auth
import com.intellij.openapi.ui.DialogWrapper
import com.intellij.ui.components.JBLabel
import com.intellij.ui.components.JBTextField
import com.intellij.ui.HyperlinkLabel
import javax.swing.JComponent
import javax.swing.JPanel
import java.awt.BorderLayout
import javax.swing.BoxLayout
class ContinueAuthDialog(private val useOnboarding: Boolean, private val onTokenEntered: (String) -> Unit) :
DialogWrapper(true) {
class ContinueAuthDialog(
private val useOnboarding: Boolean,
private val authUrl: String? = null,
private val onTokenEntered: (String) -> Unit,
) : DialogWrapper(true) {
private val tokenField = JBTextField()
init {
@ -18,9 +23,22 @@ class ContinueAuthDialog(private val useOnboarding: Boolean, private val onToken
override fun createCenterPanel(): JComponent {
val panel = JPanel(BorderLayout())
val topPanel = JPanel()
topPanel.layout = BoxLayout(topPanel, BoxLayout.Y_AXIS)
val message =
if (useOnboarding) "After onboarding you will be shown an authentication token. Please enter it here:" else "Please enter your Continue authentication token:"
panel.add(JBLabel(message), BorderLayout.NORTH)
topPanel.add(JBLabel(message))
topPanel.add(javax.swing.Box.createVerticalStrut(10))
if (authUrl != null) {
val linkLabel = HyperlinkLabel("Open authentication page")
linkLabel.setHyperlinkTarget(authUrl)
topPanel.add(linkLabel)
topPanel.add(javax.swing.Box.createVerticalStrut(10))
}
panel.add(topPanel, BorderLayout.NORTH)
panel.add(tokenField, BorderLayout.CENTER)
return panel
}

View file

@ -53,11 +53,11 @@ class ContinueAuthService {
fun startAuthFlow(project: Project, useOnboarding: Boolean) {
// Open login page
openSignInPage(project, useOnboarding)
val url = openSignInPage(project, useOnboarding)
// Open a dialog where the user should paste their sign-in token
ApplicationManager.getApplication().invokeLater {
val dialog = ContinueAuthDialog(useOnboarding) { token ->
val dialog = ContinueAuthDialog(useOnboarding, url) { token ->
// Store the token
updateRefreshToken(token)
}
@ -144,18 +144,31 @@ class ContinueAuthService {
}
private fun openSignInPage(project: Project, useOnboarding: Boolean) {
private fun openSignInPage(project: Project, useOnboarding: Boolean): String? {
var authUrl: String? = null
val coreMessenger = project.service<ContinuePluginService>().coreMessenger
// Use a blocking approach to get the URL
val latch = java.util.concurrent.CountDownLatch(1)
coreMessenger?.request(
"auth/getAuthUrl", mapOf(
"useOnboarding" to useOnboarding
), null
) { response ->
val authUrl = ((response as? Map<*, *>)?.get("content") as? Map<*, *>)?.get("url") as? String
if (authUrl != null) {
Desktop.browse(java.net.URI(authUrl))
}
authUrl = ((response as? Map<*, *>)?.get("content") as? Map<*, *>)?.get("url") as? String
latch.countDown()
}
// Wait for the response with a reasonable timeout
latch.await(5, java.util.concurrent.TimeUnit.SECONDS)
// Still open the URL in the browser (keeping existing behavior)
if (authUrl != null) {
Desktop.browse(java.net.URI(authUrl))
}
return authUrl
}
private fun retrieveSecret(key: String): String? {