Skip to content

Commit 258fa67

Browse files
committed
fix: Update OAuth implementation 6
1 parent 4c89089 commit 258fa67

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,17 @@ public CompletableFuture<OAuthTokens> exchangeCodeForToken(String code) {
179179
*/
180180
private void _saveTokens(OAuthTokens tokens) {
181181
this.tokens = tokens;
182+
// Update the client's auth state
183+
if (tokens != null && tokens.hasAccessToken()) {
184+
this.httpClient = this.httpClient.newBuilder()
185+
.addInterceptor(chain -> {
186+
Request request = chain.request().newBuilder()
187+
.header("Authorization", "Bearer " + tokens.getAccessToken())
188+
.build();
189+
return chain.proceed(request);
190+
})
191+
.build();
192+
}
182193
}
183194

184195
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public Response intercept(Chain chain) throws IOException {
5757
Request.Builder requestBuilder = originalRequest.newBuilder()
5858
.header("X-User-Agent", Util.defaultUserAgent())
5959
.header("User-Agent", Util.defaultUserAgent())
60-
.header("Content-Type", "application/json")
60+
.header("Content-Type", originalRequest.url().toString().contains("/token") ? "application/x-www-form-urlencoded" : "application/json")
6161
.header("X-Header-EA", earlyAccess != null ? String.join(",", earlyAccess) : "true");
6262

6363
// Get current tokens

0 commit comments

Comments
 (0)