Skip to content

Commit 99ca31f

Browse files
committed
fix: Update OAuth implementation 4
1 parent 9256fa0 commit 99ca31f

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/main/java/com/contentstack/cms/models/OAuthConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public String getTokenEndpoint() {
9494
.replaceAll("^dev\\d+", "dev") // Replace dev1, dev2, etc. with dev
9595
.replace("io", "com");
9696

97-
return "https://" + hostname;
97+
return "https://" + hostname + "/apps/oauth/token";
9898
}
9999

100100
/**

src/main/java/com/contentstack/cms/oauth/OAuthHandler.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ public String authorize() {
121121

122122
StringBuilder urlBuilder = new StringBuilder(baseUrl);
123123
urlBuilder.append("?response_type=").append(config.getResponseType())
124-
.append("&client_id=").append(URLEncoder.encode(config.getClientId(), "UTF-8"));
124+
.append("&client_id=").append(URLEncoder.encode(config.getClientId(), "UTF-8"))
125+
.append("&redirect_uri=").append(URLEncoder.encode(config.getRedirectUri(), "UTF-8"));
125126

126127
if (config.getClientSecret() != null && !config.getClientSecret().trim().isEmpty()) {
127128
return urlBuilder.toString();
@@ -216,18 +217,30 @@ public CompletableFuture<OAuthTokens> refreshAccessToken() {
216217
* Executes a token request and processes the response
217218
*/
218219
private OAuthTokens executeTokenRequest(Request request) throws IOException {
220+
System.out.println("\nToken Request Details:");
221+
System.out.println("URL: " + request.url());
222+
System.out.println("Method: " + request.method());
223+
System.out.println("Headers: " + request.headers());
224+
219225
Response response = null;
220226
ResponseBody responseBody = null;
221227
try {
222228
response = httpClient.newCall(request).execute();
223229
responseBody = response.body();
224230

231+
System.out.println("\nToken Response Details:");
232+
System.out.println("Status Code: " + response.code());
233+
System.out.println("Headers: " + response.headers());
234+
225235
if (!response.isSuccessful()) {
226236
String error = responseBody != null ? responseBody.string() : "Unknown error";
227-
throw new RuntimeException("Token request failed: " + error);
237+
System.err.println("Error Response Body: " + error);
238+
throw new RuntimeException("Token request failed with status " + response.code() + ": " + error);
228239
}
229240

230241
String body = responseBody != null ? responseBody.string() : "{}";
242+
System.out.println("Success Response Body: " + body);
243+
231244
OAuthTokens newTokens = gson.fromJson(body, OAuthTokens.class);
232245

233246
// Keep old refresh token if new one not provided

0 commit comments

Comments
 (0)