@@ -740,14 +740,6 @@ public Builder setOAuthConfig(OAuthConfig config) {
740740 return this ;
741741 }
742742
743- /**
744- * Configures OAuth with client credentials (traditional flow)
745- * @param appId Application ID
746- * @param clientId Client ID
747- * @param clientSecret Client secret
748- * @param redirectUri Redirect URI
749- * @return Builder instance
750- */
751743 private TokenCallback tokenCallback ;
752744
753745 /**
@@ -760,64 +752,51 @@ public Builder setTokenCallback(TokenCallback callback) {
760752 return this ;
761753 }
762754
763- 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)
765- return setOAuth (appId , clientId , clientSecret , redirectUri , this .hostname );
766- }
767-
768755 /**
769- * Configures OAuth with client credentials and specific host
756+ * Configures OAuth authentication with PKCE flow (no client secret)
770757 * @param appId Application ID
771758 * @param clientId Client ID
772- * @param clientSecret Client secret
773759 * @param redirectUri Redirect URI
774- * @param host API host (e.g. "api.contentstack.io", "eu-api.contentstack.com")
775760 * @return Builder instance
776761 */
777- public Builder setOAuth (String appId , String clientId , String clientSecret , String redirectUri , String host ) {
778- OAuthConfig .OAuthConfigBuilder builder = OAuthConfig .builder ()
779- .appId (appId )
780- .clientId (clientId )
781- .clientSecret (clientSecret )
782- .redirectUri (redirectUri )
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 ();
791- return this ;
762+ public Builder setOAuth (String appId , String clientId , String redirectUri ) {
763+ // Use the builder's hostname (which defaults to Util.HOST if not set)
764+ return setOAuth (appId , clientId , redirectUri , this .hostname );
792765 }
793766
794767 /**
795- * Configures OAuth with PKCE (no client secret)
768+ * Configures OAuth authentication with PKCE flow (no client secret) and specific host
796769 * @param appId Application ID
797770 * @param clientId Client ID
798771 * @param redirectUri Redirect URI
772+ * @param host API host (e.g. "api.contentstack.io", "eu-api.contentstack.com")
799773 * @return Builder instance
800774 */
801- public Builder setOAuthWithPKCE (String appId , String clientId , String redirectUri ) {
802- // Use the builder's hostname (which defaults to Util.HOST if not set)
803- return setOAuthWithPKCE (appId , clientId , redirectUri , this .hostname );
775+ public Builder setOAuth (String appId , String clientId , String redirectUri , String host ) {
776+ return setOAuth (appId , clientId , redirectUri , host , null );
804777 }
805778
806779 /**
807- * Configures OAuth with PKCE (no client secret) and specific host
780+ * Configures OAuth authentication with optional client secret. PKCE flow is used when clientSecret is not provided.
808781 * @param appId Application ID
809782 * @param clientId Client ID
810783 * @param redirectUri Redirect URI
811784 * @param host API host (e.g. "api.contentstack.io", "eu-api.contentstack.com")
785+ * @param clientSecret Optional client secret. If not provided, PKCE flow will be used
812786 * @return Builder instance
813787 */
814- public Builder setOAuthWithPKCE (String appId , String clientId , String redirectUri , String host ) {
788+ public Builder setOAuth (String appId , String clientId , String redirectUri , String host , String clientSecret ) {
815789 OAuthConfig .OAuthConfigBuilder builder = OAuthConfig .builder ()
816790 .appId (appId )
817791 .clientId (clientId )
818792 .redirectUri (redirectUri )
819793 .host (host );
820794
795+ // Only set clientSecret if provided (otherwise PKCE flow will be used)
796+ if (clientSecret != null && !clientSecret .trim ().isEmpty ()) {
797+ builder .clientSecret (clientSecret );
798+ }
799+
821800 // Add token callback if set
822801 if (this .tokenCallback != null ) {
823802 builder .tokenCallback (this .tokenCallback );
0 commit comments