diff --git a/CHANGELOG.md b/CHANGELOG.md index c29e062..70d4ba8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ ## [Unreleased] +### Added +- Bring session token setting for official website back. [#7 (comment)](https://github.com/LiLittleCat/intellij-chatgpt/issues/7#issuecomment-1487889326) + ## [1.1.0] - 2023-03-21 ### Added diff --git a/DESCRIPTION.md b/DESCRIPTION.md index 44f4353..730f0bb 100644 --- a/DESCRIPTION.md +++ b/DESCRIPTION.md @@ -16,6 +16,12 @@ providing a seamless experience for developers to interact with the ChatGPT AI m This plugin uses JCEF(Java Chromium Embedded Framework) to render the content. It is a lightweight and cross-platform web browser engine that is built on top of Chromium and is used by IntelliJ IDEA to render the HTML content of the IDE. JCEF is supported in IntelliJ IDEA 2020.2 and later. See [JCEF](https://plugins.jetbrains.com/docs/intellij/jcef.html) for more information. +### 💡 Solution for `Cannot log in to the official ChatGPT by Google account or Microsoft account` + +See [Notice from README](https://github.com/LiLittleCat/intellij-chatgpt/blob/bring-back-session-token/README.md#-notice). + +### Support + Feel free to submit [issue](https://github.com/LiLittleCat/awesome-free-chatgpt/issues) and [PRs](https://github.com/LiLittleCat/awesome-free-chatgpt/pulls). If you find it useful, welcome to star ⭐, your support is my motivation to move forward. --- @@ -34,6 +40,12 @@ Feel free to submit [issue](https://github.com/LiLittleCat/awesome-free-chatgpt/ 此插件使用 JCEF(Java Chromium Embedded Framework)来渲染内容。它是一个轻量级且跨平台的基于 Chromium 的网络浏览器引擎,被 IntelliJ IDEA 用于渲染 IDE 的 HTML 内容。 JCEF 支持 IntelliJ IDEA 2020.2 及更高版本。有关更多信息,请参阅 [JCEF](https://plugins.jetbrains.com/docs/intellij/jcef.html)。 +### 💡 `无法用谷歌账户或微软账户登录官方 ChatGPT` 的解决方案 + +见 [README 中的注意](https://github.com/LiLittleCat/intellij-chatgpt/blob/bring-back-session-token/README_CN.md#-%E6%B3%A8%E6%84%8F)。 + +### 支持 + 欢迎随时提交 [issue](https://github.com/LiLittleCat/awesome-free-chatgpt/issues) 和 [PRs](https://github.com/LiLittleCat/awesome-free-chatgpt/pulls),如果您觉得有用,欢迎 star ⭐,您的支持是我前进的动力。 \ No newline at end of file diff --git a/README.md b/README.md index 2df0feb..4ad9842 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,26 @@ This Jetbrains IDEs plugin integrates [ChatGPT](https://chat.openai.com/) and [other third-party mirror websites](https://github.com/LiLittleCat/awesome-free-chatgpt) of ChatGPT into JetBrains IDEs, providing a seamless experience for developers to interact with the ChatGPT AI model directly within their development environment. +> ### 💡 Notice +> Cannot log in to the official ChatGPT by Google account or Microsoft account is not caused by this plugin, but by the +> official ChatGPT itself. +> +> See https://github.com/LiLittleCat/intellij-chatgpt/issues/7 and https://github.com/JetBrains/jcef/issues/14 for more +> information. +> +>
+> 💡 Click to expand the Solution for this +> +> 1. Go to [https://chat.openai.com/chat](https://chat.openai.com/chat) and log in or sign up. +> 2. Open dev tools. +> 3. Open `Application` > `Cookies`. + [![pSSKdmR.png](https://s1.ax1x.com/2022/12/28/pSSKdmR.png)](https://imgse.com/i/pSSKdmR) +> 4. Copy the value for `__Secure-next-auth.session-token` as settings value. + [![pSSK6pD.png](https://s1.ax1x.com/2022/12/28/pSSK6pD.png)](https://imgse.com/i/pSSK6pD) +> 5. After you enter the session token, you need to restart the IDE because ChatGPT Tool Windows needs a restart, and + you won't need to log in until the session token is expired. +>
+ ## Feature - 🚀 Easy to use, and interact with ChatGPT without leaving the IDE. @@ -58,11 +78,4 @@ JCEF is supported in IntelliJ IDEA 2020.2 and later. See [JCEF](https://plugins. 9. Delete the selected URL. 10. Fetch the URL list from [the author's other GitHub repository](https://github.com/LiLittleCat/awesome-free-chatgpt). 4. Utilize third-party mirror websites. - ![](/image/another.png) - - -> **Notice** -> -> Cannot log in to the official ChatGPT by Google account or Microsoft account is not caused by this plugin, but by the official ChatGPT itself. -> -> See https://github.com/LiLittleCat/intellij-chatgpt/issues/7 and https://github.com/JetBrains/jcef/issues/14 for more information. \ No newline at end of file + ![](/image/another.png) \ No newline at end of file diff --git a/README_CN.md b/README_CN.md index 5570aa3..c504f11 100644 --- a/README_CN.md +++ b/README_CN.md @@ -10,6 +10,23 @@ 一个将 [ChatGPT](https://chat.openai.com/) 和 [其他第三方镜像网站](https://github.com/LiLittleCat/awesome-free-chatgpt) 整合到 JetBrains IDEs 的插件。 +> ### 💡 注意 +> 无法使用 Google 账户或 Microsoft 账户登录官方 ChatGPT 不是由于此插件造成的,而是由官方 ChatGPT 本身造成的。 +> +> 有关更多信息,请参阅 https://github.com/LiLittleCat/intellij-chatgpt/issues/7 和 https://github.com/JetBrains/jcef/issues/14 。 +> +>
+> 💡 点击展开解决方案 +> +> 1. 进入 [https://chat.openai.com/chat](https://chat.openai.com/chat),登录或注册。 +> 2. 打开开发工具。 +> 3. 打开 `Application` > `Cookies`。 + [![pSSKdmR.png](https://s1.ax1x.com/2022/12/28/pSSKdmR.png)](https://imgse.com/i/pSSKdmR) +> 4. 复制 `__Secure-next-auth.session-token` 的值作为设置值。 + [![pSSK6pD.png](https://s1.ax1x.com/2022/12/28/pSSK6pD.png)](https://imgse.com/i/pSSK6pD) +> 5. 输入会话令牌后,你需要重启 IDE,因为 ChatGPT 工具 Windows 需要重启,在会话令牌过期之前,你不需要登录。 +>
+ ## 功能 - 🚀 易于使用,无需离开 IDE 即可与 ChatGPT 交互。 @@ -56,10 +73,4 @@ JCEF 支持 IntelliJ IDEA 2020.2 及更高版本。有关更多信息,请参 9. 删除选定的 URL。 10. 从 [作者的另一个 GitHub 仓库](https://github.com/LiLittleCat/awesome-free-chatgpt) 获取 URL 列表。 4. 使用第三方镜像网站。 - ![](/image/another.png) - -> **注意** -> -> 无法使用 Google 账户或 Microsoft 账户登录官方 ChatGPT 不是由于此插件造成的,而是由官方 ChatGPT 本身造成的。 -> -> 有关更多信息,请参阅 https://github.com/LiLittleCat/intellij-chatgpt/issues/7 和 https://github.com/JetBrains/jcef/issues/14 。 + ![](/image/another.png) \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 1f7b6fb..f1f83db 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ pluginGroup = com.lilittlecat.intellij-chatgpt pluginName = ChatGPT Tool pluginRepositoryUrl = https://github.com/LiLittleCat/intellij-chatgpt # SemVer format -> https://semver.org -pluginVersion = 1.1.0 +pluginVersion = 1.1.1 # Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html pluginSinceBuild = 202 diff --git a/src/main/java/com/lilittlecat/chatgpt/action/RefreshAction.java b/src/main/java/com/lilittlecat/chatgpt/action/RefreshAction.java index f6b343d..7606204 100644 --- a/src/main/java/com/lilittlecat/chatgpt/action/RefreshAction.java +++ b/src/main/java/com/lilittlecat/chatgpt/action/RefreshAction.java @@ -42,7 +42,7 @@ public void actionPerformed(@NotNull AnActionEvent e) { // Store the index of the selected content int selectedIndex = contentManager.getIndexOfContent(selectedContent); // Remove the selected content - contentManager.removeContent(selectedContent, false); + contentManager.removeContent(selectedContent, true); // Iterate through all contents in the content manager for (int i = 0; i < contentManager.getContentCount(); i++) { // Get the current content @@ -51,7 +51,7 @@ public void actionPerformed(@NotNull AnActionEvent e) { // Get the tab name of the current content String tabName = content.getTabName(); // Remove the current content - contentManager.removeContent(content, false); + contentManager.removeContent(content, true); // Create a new content with the same tab name Content browser = ContentFactory.SERVICE.getInstance().createContent( new ChatGPTToolWindow(tabName).getContent(), tabName, false); diff --git a/src/main/java/com/lilittlecat/chatgpt/setting/ChatGPTSettingsConfigurable.java b/src/main/java/com/lilittlecat/chatgpt/setting/ChatGPTSettingsConfigurable.java index e134c97..40efdff 100644 --- a/src/main/java/com/lilittlecat/chatgpt/setting/ChatGPTSettingsConfigurable.java +++ b/src/main/java/com/lilittlecat/chatgpt/setting/ChatGPTSettingsConfigurable.java @@ -11,13 +11,12 @@ import com.intellij.openapi.util.text.StringUtil; import com.intellij.ui.*; import com.intellij.ui.components.JBLabel; +import com.intellij.ui.components.JBScrollPane; +import com.intellij.ui.components.JBTextArea; import com.intellij.ui.components.fields.ExtendableTextField; import com.intellij.ui.table.JBTable; import com.intellij.util.messages.MessageBusConnection; -import com.intellij.util.ui.ColumnInfo; -import com.intellij.util.ui.FormBuilder; -import com.intellij.util.ui.JBInsets; -import com.intellij.util.ui.ListTableModel; +import com.intellij.util.ui.*; import com.lilittlecat.chatgpt.action.FetchURLAction; import com.lilittlecat.chatgpt.message.ChatGPTBundle; import org.jetbrains.annotations.Nls; @@ -84,6 +83,7 @@ public void addUrl(@NotNull String url) { private Disposable myDisposable = Disposer.newDisposable(); private JPanel myMainPanel; + private JBTextArea sessionToken = new JBTextArea(); private JComboBox defaultUrlComboBox; private ListTableModel myModel; @@ -140,7 +140,14 @@ public void editingCanceled(ChangeEvent e) { JComponent table = createTable(); table.setPreferredSize(new Dimension(500, 200)); createComboBox(); + + sessionToken.setFont(UIUtil.getLabelFont()); + sessionToken.setLineWrap(true); + JBScrollPane scrollPane = new JBScrollPane(sessionToken, + ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER, + ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); myMainPanel = FormBuilder.createFormBuilder() + .addLabeledComponent(new JBLabel(ChatGPTBundle.message("setting.session.token.label")), scrollPane, 1, true) .addLabeledComponent(new JBLabel(ChatGPTBundle.message("default.url.message")), defaultUrlComboBox, 1, false) .addLabeledComponent(new SeparatorComponent(), new JPanel(), 1, false) .addLabeledComponent(new JBLabel(ChatGPTBundle.message("url.list.message")), table, 3, true) @@ -261,6 +268,7 @@ public boolean isModified() { List items = myModel.getItems(); modified |= urlList.size() != items.size(); modified |= !urlList.equals(items); + modified |= !instance.sessionToken.equals(sessionToken.getText()); return modified; } @@ -270,6 +278,7 @@ public void apply() { ChatGPTSettingsState instance = ChatGPTSettingsState.getInstance(); instance.defaultUrl = Objects.requireNonNull(defaultUrlComboBox.getSelectedItem()).toString(); instance.urlList = myModel.getItems(); + instance.sessionToken = sessionToken.getText(); // Refresh the UI after updating the settings refreshUI(); // instance.urlList.addAll(myModel.getItems()); @@ -284,5 +293,6 @@ public void reset() { defaultUrlComboBox.addItem(s); } defaultUrlComboBox.setSelectedItem(instance.defaultUrl); + sessionToken.setText(instance.sessionToken); } } diff --git a/src/main/java/com/lilittlecat/chatgpt/setting/ChatGPTSettingsState.java b/src/main/java/com/lilittlecat/chatgpt/setting/ChatGPTSettingsState.java index 7acaca7..c017c74 100644 --- a/src/main/java/com/lilittlecat/chatgpt/setting/ChatGPTSettingsState.java +++ b/src/main/java/com/lilittlecat/chatgpt/setting/ChatGPTSettingsState.java @@ -24,7 +24,8 @@ storages = @Storage("ChatGPTSettingsState.xml") ) public class ChatGPTSettingsState implements PersistentStateComponent { -// public String sessionToken = ""; + + public String sessionToken = ""; public String defaultUrl = ChatGPTBundle.message("default.url"); @@ -68,6 +69,14 @@ public void setUrlList(List urlList) { this.urlList = urlList; } + public String getSessionToken() { + return sessionToken; + } + + public void setSessionToken(String sessionToken) { + this.sessionToken = sessionToken; + } + public static ChatGPTSettingsState getInstance() { return ApplicationManager.getApplication().getService(ChatGPTSettingsState.class); } diff --git a/src/main/java/com/lilittlecat/chatgpt/window/ChatGPTToolWindow.java b/src/main/java/com/lilittlecat/chatgpt/window/ChatGPTToolWindow.java index 9de92b2..83ff7ce 100644 --- a/src/main/java/com/lilittlecat/chatgpt/window/ChatGPTToolWindow.java +++ b/src/main/java/com/lilittlecat/chatgpt/window/ChatGPTToolWindow.java @@ -61,61 +61,66 @@ public ChatGPTToolWindow(String url) { } JBCefBrowser jbCefBrowser = new JBCefBrowser(); this.content.add(jbCefBrowser.getComponent(), BorderLayout.CENTER); -// JBCefCookieManager jbCefCookieManager = new JBCefCookieManager(); -// if (url.equals(ChatGPTBundle.message("default.url"))) { -// // find if there is session token in settings -// ChatGPTSettingsState state = ChatGPTSettingsState.getInstance().getState(); -// if (state != null) { -// String sessionToken = state.sessionToken; -// if (StringUtils.isNotBlank(sessionToken)) { -// // check the token is right or not -// -// // 2022.12.16 with Cloudflare, can not check token by http get -// -//// String cookie = sessionTokenName + "=" + sessionToken; -//// HttpGet httpGet = new HttpGet("https://chat.openai.com/chat"); -//// httpGet.setHeader("Connection", "keep-alive"); -//// httpGet.setHeader("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15"); -//// httpGet.setHeader("Cookie", cookie); -//// httpGet.setHeader("Origin", "https://auth0.openai.com"); -//// httpGet.setHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); -//// httpGet.setHeader("Accept-Language", "en-US,en;q=0.9"); -//// try (CloseableHttpClient httpClient = HttpClients.createDefault(); -//// CloseableHttpResponse httpResponse = httpClient.execute(httpGet)) { -//// HttpEntity httpEntity = httpResponse.getEntity(); -//// String bodyString = EntityUtils.toString(httpEntity); -//// if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK && !bodyString.contains("Welcome to ChatGPT")) { -// JBCefCookie jbCefCookie = new JBCefCookie(sessionTokenName, sessionToken, "chat.openai.com", "/", true, true); -// jbCefCookieManager.setCookie("https://chat.openai.com", jbCefCookie, 10000); -//// } -//// } catch (IOException e) { -//// LOG.error("Error when check session token: ", e); -//// } -// } -// } -// // get session token after login, fill it in settings -// // fill it every login, in case invalid session token cause can't login problem -// executor.execute(() -> { -// String currentSessionToken = null; -// while (currentSessionToken == null) { -// List cookies = jbCefCookieManager.getCookies(); -// if (!cookies.isEmpty()) { -// for (JBCefCookie cookie : cookies) { -// if (cookie.getName().equals(sessionTokenName)) { -// currentSessionToken = cookie.getValue(); -// ChatGPTSettingsState.getInstance().setSessionToken(currentSessionToken); -// } -// } -// } -// try { -// Thread.sleep(1000L); -// } catch (InterruptedException e) { -// throw new RuntimeException(e); + if (url.equals(ChatGPTBundle.message("default.url"))) { + setCookieForOfficalWebsite(url); + } + jbCefBrowser.loadURL(url); + } + + private void setCookieForOfficalWebsite(String url) { + JBCefCookieManager jbCefCookieManager = new JBCefCookieManager(); + // find if there is session token in settings + ChatGPTSettingsState state = ChatGPTSettingsState.getInstance().getState(); + if (state != null) { + String sessionToken = state.sessionToken; + if (StringUtils.isNotBlank(sessionToken)) { + // check the token is right or not + + // 2022.12.16 with Cloudflare, can not check token by http get + +// String cookie = sessionTokenName + "=" + sessionToken; +// HttpGet httpGet = new HttpGet("https://chat.openai.com/chat"); +// httpGet.setHeader("Connection", "keep-alive"); +// httpGet.setHeader("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15"); +// httpGet.setHeader("Cookie", cookie); +// httpGet.setHeader("Origin", "https://auth0.openai.com"); +// httpGet.setHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); +// httpGet.setHeader("Accept-Language", "en-US,en;q=0.9"); +// try (CloseableHttpClient httpClient = HttpClients.createDefault(); +// CloseableHttpResponse httpResponse = httpClient.execute(httpGet)) { +// HttpEntity httpEntity = httpResponse.getEntity(); +// String bodyString = EntityUtils.toString(httpEntity); +// if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK && !bodyString.contains("Welcome to ChatGPT")) { + JBCefCookie jbCefCookie = new JBCefCookie(sessionTokenName, sessionToken, "chat.openai.com", "/", true, true); + // use async set + jbCefCookieManager.setCookie(ChatGPTBundle.message("default.url"), jbCefCookie, false); // } +// } catch (IOException e) { +// LOG.error("Error when check session token: ", e); // } -// }); -// } - jbCefBrowser.loadURL(url); + } + } + // get session token after login, fill it in settings + // fill it every login, in case invalid session token cause can't login problem + executor.execute(() -> { + String currentSessionToken = null; + while (currentSessionToken == null) { + List cookies = jbCefCookieManager.getCookies(); + if (!cookies.isEmpty()) { + for (JBCefCookie cookie : cookies) { + if (cookie.getName().equals(sessionTokenName)) { + currentSessionToken = cookie.getValue(); + ChatGPTSettingsState.getInstance().setSessionToken(currentSessionToken); + } + } + } + try { + Thread.sleep(1000L); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + }); } public JPanel getContent() { diff --git a/src/main/resources/messages/ChatGPTBundle.properties b/src/main/resources/messages/ChatGPTBundle.properties index f67b2dd..263a6bd 100644 --- a/src/main/resources/messages/ChatGPTBundle.properties +++ b/src/main/resources/messages/ChatGPTBundle.properties @@ -1,5 +1,5 @@ name=ChatGPT Tool -setting.session.token.label=Session token: +setting.session.token.label=Session token(only for https://chat.openai.com): setting.menu.text=ChatGPT Tool default.url.message=Default URL: url.list.message=URL list: