-
Notifications
You must be signed in to change notification settings - Fork 81
fix: Update OAuth authentication URL host to www domain & Bump version to 0.2.2 #30
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
Changes from 2 commits
8bc92ed
d87e548
9f8a0c8
8b4efe4
c8c1a1f
1274441
37c1ddc
4b113ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,11 @@ protected OAuthClient(OAuthBuilder<?> builder) { | |
this.clientSecret = builder.clientSecret; | ||
this.clientID = builder.clientID; | ||
this.baseURL = builder.baseURL; | ||
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); | ||
|
@@ -121,10 +128,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 = | ||
|
@@ -251,6 +257,7 @@ public abstract static class OAuthBuilder<T extends OAuthBuilder<T>> { | |
protected String clientID; | ||
protected String clientSecret; | ||
protected String baseURL; | ||
protected String wwwURL; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Add test coverage for wwwURL builder methods The codebase analysis confirms that wwwURL builder functionality lacks test coverage. Existing OAuth client tests demonstrate thorough testing patterns for other builder properties, but wwwURL-specific tests are missing. Please add test cases to verify:
🔗 Analysis chainAdd test coverage for wwwURL builder methods. The new builder methods for
Also applies to: 285-289 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Check for existing test coverage of wwwURL functionality
# Search for test files that might contain wwwURL-related tests
echo "Searching for existing test files..."
fd -e java -e kt test
# Search for wwwURL usage in test files
echo -e "\nSearching for wwwURL test coverage..."
rg -l "wwwURL" $(fd -e java -e kt test)
Length of output: 4911 Script: #!/bin/bash
# Check for builder pattern usage in auth tests
echo "Checking builder usage in auth tests..."
rg -A 5 -B 5 "\.builder\(\)" api/src/test/java/com/coze/openapi/service/auth/
# Check for any indirect wwwURL testing through setters
echo -e "\nChecking for indirect wwwURL testing..."
rg -A 5 -B 5 "\.setWww" api/src/test/java/com/coze/openapi/service/auth/
Length of output: 338 Script: #!/bin/bash
# Check test structure and initialization patterns
echo "Analyzing OAuthClient test implementations..."
rg -l "OAuthClient" api/src/test/java/com/coze/openapi/service/auth/ | xargs cat
# Broader search for builder-related patterns
echo -e "\nChecking for builder patterns..."
rg "new\s+.*Builder|builder\s*\(\)" api/src/test/java/com/coze/openapi/service/auth/
Length of output: 30942 |
||
protected int readTimeout; | ||
protected int connectTimeout; | ||
protected OkHttpClient client; | ||
|
@@ -276,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(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Validate wwwURL construction
While the URL domain separation is correct, the current implementation using simple string replacement could be fragile.
Consider adding validation and using URL parsing:
Also applies to: 59-59