@@ -737,15 +737,6 @@ public Builder setOAuthConfig(OAuthConfig config) {
737737 return this;
738738 }
739739
740- /**
741- * Configures OAuth with client credentials (traditional flow)
742- *
743- * @param appId Application ID
744- * @param clientId Client ID
745- * @param clientSecret Client secret
746- * @param redirectUri Redirect URI
747- * @return Builder instance
748- */
749740 private TokenCallback tokenCallback;
750741
751742 /**
@@ -758,70 +749,52 @@ public Builder setTokenCallback(TokenCallback callback) {
758749 this.tokenCallback = callback;
759750 return this;
760751 }
761-
762- public Builder setOAuth(String appId, String clientId, String clientSecret, String redirectUri) {
763- // Use the builder's hostname (which defaults to Util.HOST if not set)
764- return setOAuth(appId, clientId, clientSecret, redirectUri, this.hostname);
765- }
766-
752+
767753 /**
768- * Configures OAuth with client credentials and specific host
769- *
754+ * Configures OAuth authentication with PKCE flow (no client secret)
770755 * @param appId Application ID
771756 * @param clientId Client ID
772- * @param clientSecret Client secret
773757 * @param redirectUri Redirect URI
774- * @param host API host (e.g. "api.contentstack.io",
775- * "eu-api.contentstack.com")
776758 * @return Builder instance
777759 */
778- public Builder setOAuth(String appId, String clientId, String clientSecret, String redirectUri, String host) {
779- OAuthConfig.OAuthConfigBuilder builder = OAuthConfig.builder()
780- .appId(appId)
781- .clientId(clientId)
782- .clientSecret(clientSecret)
783- .redirectUri(redirectUri)
784- .host(host);
785-
786- // Add token callback if set
787- if (this.tokenCallback != null) {
788- builder.tokenCallback(this.tokenCallback);
789- }
790-
791- this.oauthConfig = builder.build();
792- return this;
760+ public Builder setOAuth(String appId, String clientId, String redirectUri) {
761+ // Use the builder's hostname (which defaults to Util.HOST if not set)
762+ return setOAuth(appId, clientId, redirectUri, this.hostname);
793763 }
794764
795765 /**
796- * Configures OAuth with PKCE (no client secret)
797- *
766+ * Configures OAuth authentication with PKCE flow (no client secret) and specific host
798767 * @param appId Application ID
799768 * @param clientId Client ID
800769 * @param redirectUri Redirect URI
770+ * @param host API host (e.g. "api.contentstack.io", "eu-api.contentstack.com")
801771 * @return Builder instance
802772 */
803- public Builder setOAuthWithPKCE(String appId, String clientId, String redirectUri) {
804- // Use the builder's hostname (which defaults to Util.HOST if not set)
805- return setOAuthWithPKCE(appId, clientId, redirectUri, this.hostname);
773+ public Builder setOAuth(String appId, String clientId, String redirectUri, String host) {
774+ return setOAuth(appId, clientId, redirectUri, host, null);
806775 }
807776
808777 /**
809- * Configures OAuth with PKCE (no client secret) and specific host
810- *
778+ * Configures OAuth authentication with optional client secret. PKCE flow is used when clientSecret is not provided.
811779 * @param appId Application ID
812780 * @param clientId Client ID
813781 * @param redirectUri Redirect URI
814- * @param host API host (e.g. "api.contentstack.io",
815- * "eu-api.contentstack.com")
782+ * @param host API host (e.g. "api.contentstack.io", "eu-api.contentstack.com")
783+ * @param clientSecret Optional client secret. If not provided, PKCE flow will be used
816784 * @return Builder instance
817785 */
818- public Builder setOAuthWithPKCE (String appId, String clientId, String redirectUri, String host) {
786+ public Builder setOAuth (String appId, String clientId, String redirectUri, String host, String clientSecret ) {
819787 OAuthConfig.OAuthConfigBuilder builder = OAuthConfig.builder()
820788 .appId(appId)
821789 .clientId(clientId)
822790 .redirectUri(redirectUri)
823791 .host(host);
824792
793+ // Only set clientSecret if provided (otherwise PKCE flow will be used)
794+ if (clientSecret != null && !clientSecret.trim().isEmpty()) {
795+ builder.clientSecret(clientSecret);
796+ }
797+
825798 // Add token callback if set
826799 if (this.tokenCallback != null) {
827800 builder.tokenCallback(this.tokenCallback);
0 commit comments