Skip to content

Commit 0c04e34

Browse files
committed
fix: Ensure default host is properly used in OAuth config
1 parent 75a6b1e commit 0c04e34

File tree

1 file changed

+33
-6
lines changed

1 file changed

+33
-6
lines changed

src/main/java/com/contentstack/cms/Contentstack.java

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.contentstack.cms.models.LoginDetails;
2121
import com.contentstack.cms.models.OAuthConfig;
2222
import com.contentstack.cms.models.OAuthTokens;
23+
import com.contentstack.cms.oauth.TokenCallback;
2324
import com.contentstack.cms.oauth.OAuthHandler;
2425
import com.contentstack.cms.oauth.OAuthInterceptor;
2526
import com.contentstack.cms.organization.Organization;
@@ -747,7 +748,20 @@ public Builder setOAuthConfig(OAuthConfig config) {
747748
* @param redirectUri Redirect URI
748749
* @return Builder instance
749750
*/
751+
private TokenCallback tokenCallback;
752+
753+
/**
754+
* Sets the token callback for OAuth storage
755+
* @param callback The callback to handle token storage
756+
* @return Builder instance
757+
*/
758+
public Builder setTokenCallback(TokenCallback callback) {
759+
this.tokenCallback = callback;
760+
return this;
761+
}
762+
750763
public Builder setOAuth(String appId, String clientId, String clientSecret, String redirectUri) {
764+
// Use the builder's hostname (which defaults to Util.HOST if not set)
751765
return setOAuth(appId, clientId, clientSecret, redirectUri, this.hostname);
752766
}
753767

@@ -761,13 +775,19 @@ public Builder setOAuth(String appId, String clientId, String clientSecret, Stri
761775
* @return Builder instance
762776
*/
763777
public Builder setOAuth(String appId, String clientId, String clientSecret, String redirectUri, String host) {
764-
this.oauthConfig = OAuthConfig.builder()
778+
OAuthConfig.OAuthConfigBuilder builder = OAuthConfig.builder()
765779
.appId(appId)
766780
.clientId(clientId)
767781
.clientSecret(clientSecret)
768782
.redirectUri(redirectUri)
769-
.host(host)
770-
.build();
783+
.host(host);
784+
785+
// Add token callback if set
786+
if (this.tokenCallback != null) {
787+
builder.tokenCallback(this.tokenCallback);
788+
}
789+
790+
this.oauthConfig = builder.build();
771791
return this;
772792
}
773793

@@ -779,6 +799,7 @@ public Builder setOAuth(String appId, String clientId, String clientSecret, Stri
779799
* @return Builder instance
780800
*/
781801
public Builder setOAuthWithPKCE(String appId, String clientId, String redirectUri) {
802+
// Use the builder's hostname (which defaults to Util.HOST if not set)
782803
return setOAuthWithPKCE(appId, clientId, redirectUri, this.hostname);
783804
}
784805

@@ -791,12 +812,18 @@ public Builder setOAuthWithPKCE(String appId, String clientId, String redirectUr
791812
* @return Builder instance
792813
*/
793814
public Builder setOAuthWithPKCE(String appId, String clientId, String redirectUri, String host) {
794-
this.oauthConfig = OAuthConfig.builder()
815+
OAuthConfig.OAuthConfigBuilder builder = OAuthConfig.builder()
795816
.appId(appId)
796817
.clientId(clientId)
797818
.redirectUri(redirectUri)
798-
.host(host)
799-
.build();
819+
.host(host);
820+
821+
// Add token callback if set
822+
if (this.tokenCallback != null) {
823+
builder.tokenCallback(this.tokenCallback);
824+
}
825+
826+
this.oauthConfig = builder.build();
800827
return this;
801828
}
802829

0 commit comments

Comments
 (0)