From 8bc92ed56f61a122259dca6a1223a91305248133 Mon Sep 17 00:00:00 2001 From: hanzeINGH Date: Thu, 23 Jan 2025 21:00:31 +0800 Subject: [PATCH 1/8] fix: callback url Change-Id: I96cda3ea6a200b85184177851af8b1e4ce27f21d --- api/pom.xml | 2 +- .../java/com/coze/openapi/service/auth/OAuthClient.java | 8 +++++--- .../coze/openapi/service/utils/UserAgentInterceptor.java | 2 +- example/pom.xml | 2 +- example/src/main/java/example/auth/WebOAuthExample.java | 4 ++-- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/api/pom.xml b/api/pom.xml index 42e976e6..b21fb4f2 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -43,7 +43,7 @@ coze-api - 0.2.1 + 0.2.2 scm:git:git://github.com/coze-dev/coze-java.git diff --git a/api/src/main/java/com/coze/openapi/service/auth/OAuthClient.java b/api/src/main/java/com/coze/openapi/service/auth/OAuthClient.java index 568d4593..7bfc2418 100644 --- a/api/src/main/java/com/coze/openapi/service/auth/OAuthClient.java +++ b/api/src/main/java/com/coze/openapi/service/auth/OAuthClient.java @@ -28,6 +28,7 @@ import com.coze.openapi.service.utils.Utils; import com.fasterxml.jackson.databind.ObjectMapper; +import io.jsonwebtoken.lang.Strings; import io.reactivex.Single; import okhttp3.ConnectionPool; import okhttp3.OkHttpClient; @@ -45,6 +46,7 @@ public abstract class OAuthClient { protected final String clientSecret; protected final String clientID; protected final String baseURL; + protected final String wwwURL; protected final CozeAuthAPI api; protected final ExecutorService executorService; protected final String hostName; @@ -54,6 +56,7 @@ protected OAuthClient(OAuthBuilder builder) { this.clientSecret = builder.clientSecret; this.clientID = builder.clientID; this.baseURL = builder.baseURL; + this.wwwURL = Strings.replace(baseURL, "api.", "www."); if (this.baseURL != null && !this.baseURL.isEmpty()) { try { java.net.URL url = new java.net.URL(this.baseURL); @@ -121,10 +124,9 @@ private String _getOAuthURL( params.put("code_challenge_method", codeChallengeMethod); } - String uri = baseURL + "/api/permission/oauth2/authorize"; + String uri = wwwURL + "/api/permission/oauth2/authorize"; if (workspaceID != null) { - uri = - baseURL + String.format("/api/permission/oauth2/workspace_id/%s/authorize", workspaceID); + uri = wwwURL + String.format("/api/permission/oauth2/workspace_id/%s/authorize", workspaceID); } String queryString = diff --git a/api/src/main/java/com/coze/openapi/service/utils/UserAgentInterceptor.java b/api/src/main/java/com/coze/openapi/service/utils/UserAgentInterceptor.java index ee0f65c5..066208d4 100644 --- a/api/src/main/java/com/coze/openapi/service/utils/UserAgentInterceptor.java +++ b/api/src/main/java/com/coze/openapi/service/utils/UserAgentInterceptor.java @@ -24,7 +24,7 @@ public Response intercept(Chain chain) throws IOException { return chain.proceed(request); } - public static final String VERSION = "0.2.1"; + public static final String VERSION = "0.2.2"; private static final ObjectMapper objectMapper = new ObjectMapper(); /** 获取操作系统版本 */ diff --git a/example/pom.xml b/example/pom.xml index c2e94a8b..fcf715f8 100644 --- a/example/pom.xml +++ b/example/pom.xml @@ -16,7 +16,7 @@ com.coze coze-api - 0.2.1 + 0.2.2 \ No newline at end of file diff --git a/example/src/main/java/example/auth/WebOAuthExample.java b/example/src/main/java/example/auth/WebOAuthExample.java index d91197ad..b1afc5ef 100644 --- a/example/src/main/java/example/auth/WebOAuthExample.java +++ b/example/src/main/java/example/auth/WebOAuthExample.java @@ -47,13 +47,13 @@ public static void main(String[] args) { .build(); // Generate the authorization link and direct the user to open it. - String oauthURL = oauth.getOAuthURL(redirectURI, null); + String oauthURL = oauth.getOAuthURL(redirectURI, "state"); System.out.println(oauthURL); /* * The space permissions for which the Access Token is granted can be specified. As following codes: * */ - oauthURL = oauth.getOAuthURL(redirectURI, null, "workspaceID"); + oauthURL = oauth.getOAuthURL(redirectURI, "state", "workspaceID"); System.out.println(oauthURL); /* From d87e548da1c01b9ba2eb2effb6f104265df77d4a Mon Sep 17 00:00:00 2001 From: hanzeINGH Date: Thu, 23 Jan 2025 21:09:58 +0800 Subject: [PATCH 2/8] fix: callback url Change-Id: I5fdea142e7f80c43ea9e78047ff0d1e1e38ef65a --- .../com/coze/openapi/service/auth/OAuthClient.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/api/src/main/java/com/coze/openapi/service/auth/OAuthClient.java b/api/src/main/java/com/coze/openapi/service/auth/OAuthClient.java index 7bfc2418..b7ed72db 100644 --- a/api/src/main/java/com/coze/openapi/service/auth/OAuthClient.java +++ b/api/src/main/java/com/coze/openapi/service/auth/OAuthClient.java @@ -56,7 +56,11 @@ protected OAuthClient(OAuthBuilder builder) { this.clientSecret = builder.clientSecret; this.clientID = builder.clientID; this.baseURL = builder.baseURL; - this.wwwURL = Strings.replace(baseURL, "api.", "www."); + if (builder.wwwURL != null) { + this.wwwURL = builder.wwwURL; + }else { + this.wwwURL = Strings.replace(baseURL, "api.", "www."); + } if (this.baseURL != null && !this.baseURL.isEmpty()) { try { java.net.URL url = new java.net.URL(this.baseURL); @@ -253,6 +257,7 @@ public abstract static class OAuthBuilder> { protected String clientID; protected String clientSecret; protected String baseURL; + protected String wwwURL; protected int readTimeout; protected int connectTimeout; protected OkHttpClient client; @@ -278,6 +283,11 @@ public T baseURL(String baseURL) { return self(); } + public T wwwURL(String wwwURL) { + this.wwwURL = wwwURL; + return self(); + } + public T readTimeout(int readTimeout) { this.readTimeout = readTimeout; return self(); From 9f8a0c86765b7b2c014a940ad0f4c61984007562 Mon Sep 17 00:00:00 2001 From: hanzeINGH Date: Thu, 23 Jan 2025 21:12:55 +0800 Subject: [PATCH 3/8] Update OAuthClient.java fix code format Change-Id: I22bd59dcadd3777eb6ba3eb37ff8a739c469e751 --- .../main/java/com/coze/openapi/service/auth/OAuthClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/main/java/com/coze/openapi/service/auth/OAuthClient.java b/api/src/main/java/com/coze/openapi/service/auth/OAuthClient.java index b7ed72db..bedad627 100644 --- a/api/src/main/java/com/coze/openapi/service/auth/OAuthClient.java +++ b/api/src/main/java/com/coze/openapi/service/auth/OAuthClient.java @@ -58,7 +58,7 @@ protected OAuthClient(OAuthBuilder builder) { this.baseURL = builder.baseURL; if (builder.wwwURL != null) { this.wwwURL = builder.wwwURL; - }else { + } else { this.wwwURL = Strings.replace(baseURL, "api.", "www."); } if (this.baseURL != null && !this.baseURL.isEmpty()) { From 8b4efe4d261dec3e54b2a8f9c4444d3470483632 Mon Sep 17 00:00:00 2001 From: hanzeINGH Date: Thu, 23 Jan 2025 21:22:48 +0800 Subject: [PATCH 4/8] Update pom.xml update Change-Id: I7bcbf5ac5d04881da5ed121c34f6c908759d19d2 --- api/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/pom.xml b/api/pom.xml index b21fb4f2..a0bf705c 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -98,7 +98,7 @@ com.squareup.okhttp3 okhttp - 4.9.3 + 3.14.9 From c8c1a1f72c706876a2880e169ffa38b8d542b5ce Mon Sep 17 00:00:00 2001 From: hanzeINGH Date: Thu, 23 Jan 2025 21:27:35 +0800 Subject: [PATCH 5/8] fix: callback url Change-Id: I4c409c46bb5418912e1cb8ed5403a73e5b364b58 --- example/src/main/java/example/auth/PKCEOAuthExample.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/src/main/java/example/auth/PKCEOAuthExample.java b/example/src/main/java/example/auth/PKCEOAuthExample.java index 57dd862d..52918faa 100644 --- a/example/src/main/java/example/auth/PKCEOAuthExample.java +++ b/example/src/main/java/example/auth/PKCEOAuthExample.java @@ -45,7 +45,7 @@ public static void main(String[] args) { to select the code_challenge_method. * */ GetPKCEAuthURLResp oauthURL = - oauth.genOAuthURL(redirectURI, "state", PKCEOAuthClient.CodeChallengeMethod.S256); + oauth.genOAuthURL(redirectURI, "states", PKCEOAuthClient.CodeChallengeMethod.S256); System.out.println(oauthURL); /* From 1274441f092715f428615edcc37f98be9a6f5ab2 Mon Sep 17 00:00:00 2001 From: hanzeINGH Date: Thu, 23 Jan 2025 21:30:40 +0800 Subject: [PATCH 6/8] fix: callback url Change-Id: I34d5994b0e6d952139acd854dcb6f4f94a996075 --- api/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/pom.xml b/api/pom.xml index a0bf705c..b21fb4f2 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -98,7 +98,7 @@ com.squareup.okhttp3 okhttp - 3.14.9 + 4.9.3 From 37c1ddc4e88a4de1b097b7116ea6061f2c881a74 Mon Sep 17 00:00:00 2001 From: hanzeINGH Date: Thu, 23 Jan 2025 21:33:44 +0800 Subject: [PATCH 7/8] fix Change-Id: I3f8ffdc919f51f45ade99eca622460574905505f --- .../main/java/com/coze/openapi/service/auth/OAuthClient.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/api/src/main/java/com/coze/openapi/service/auth/OAuthClient.java b/api/src/main/java/com/coze/openapi/service/auth/OAuthClient.java index bedad627..5ab37922 100644 --- a/api/src/main/java/com/coze/openapi/service/auth/OAuthClient.java +++ b/api/src/main/java/com/coze/openapi/service/auth/OAuthClient.java @@ -28,7 +28,6 @@ import com.coze.openapi.service.utils.Utils; import com.fasterxml.jackson.databind.ObjectMapper; -import io.jsonwebtoken.lang.Strings; import io.reactivex.Single; import okhttp3.ConnectionPool; import okhttp3.OkHttpClient; @@ -59,7 +58,7 @@ protected OAuthClient(OAuthBuilder builder) { if (builder.wwwURL != null) { this.wwwURL = builder.wwwURL; } else { - this.wwwURL = Strings.replace(baseURL, "api.", "www."); + this.wwwURL = builder.baseURL.replace("api.", "www."); } if (this.baseURL != null && !this.baseURL.isEmpty()) { try { From 4b113eecbe039c713bf07aadf2e797a4f2eca47e Mon Sep 17 00:00:00 2001 From: hanzeINGH Date: Thu, 23 Jan 2025 21:55:11 +0800 Subject: [PATCH 8/8] fix Change-Id: Iba86b9bd15c662abfae7759abd2db4794bbba660 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 14043645..4fa643fd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,7 +27,7 @@ jobs: - name: Set up JDK ${{ matrix.java-version }} uses: actions/setup-java@v4 with: - distribution: 'temurin' + distribution: 'adopt' java-version: ${{ matrix.java-version }} cache: 'maven' - name: Code style check