2121from abc import ABC , abstractmethod
2222from typing import Any , Callable , List , Literal , Optional , Union
2323
24- from pydantic import BaseModel , model_validator , field_validator
24+ from pydantic import BaseModel , field_validator
2525
2626from veadk .integrations .ve_identity .models import OAuth2AuthPoller
2727from veadk .integrations .ve_identity .identity_client import IdentityClient
@@ -35,6 +35,7 @@ def _get_default_region() -> str:
3535 """
3636 try :
3737 from veadk .config import settings
38+
3839 return settings .veidentity .region
3940 except Exception :
4041 # Fallback to default if config loading fails
@@ -52,8 +53,8 @@ class AuthConfig(BaseModel, ABC):
5253
5354 def __init__ (self , ** data ):
5455 """Initialize AuthConfig with default region from VeADK config if not provided."""
55- if ' region' not in data or data [' region' ] is None :
56- data [' region' ] = _get_default_region ()
56+ if " region" not in data or data [" region" ] is None :
57+ data [" region" ] = _get_default_region ()
5758 super ().__init__ (** data )
5859
5960 @field_validator ("provider_name" )
@@ -82,10 +83,10 @@ def auth_type(self) -> str:
8283class OAuth2AuthConfig (AuthConfig ):
8384 """OAuth2 authentication configuration."""
8485
85- # Required fields
86- scopes : List [str ]
87- auth_flow : Literal ["M2M" , "USER_FEDERATION" ]
88- # Optional fields
86+ # Optional fields - control plane will use defaults if not provided
87+ scopes : Optional [ List [str ]] = None
88+ auth_flow : Optional [ Literal ["M2M" , "USER_FEDERATION" ]] = None
89+ # Additional optional fields
8990 callback_url : Optional [str ] = None
9091 force_authentication : bool = False
9192 response_for_auth_required : Optional [Union [dict , str ]] = None
@@ -94,10 +95,18 @@ class OAuth2AuthConfig(AuthConfig):
9495
9596 @field_validator ("scopes" )
9697 @classmethod
97- def validate_scopes_not_empty (cls , v : List [str ]) -> List [str ]:
98- """Validate that scopes list is not empty and contains valid scope strings."""
98+ def validate_scopes_not_empty (cls , v : Optional [List [str ]]) -> Optional [List [str ]]:
99+ """Validate that scopes list is not empty and contains valid scope strings.
100+
101+ If scopes is None, the control plane will use default scopes.
102+ """
103+ if v is None :
104+ return None
105+
99106 if not v :
100- raise ValueError ("scopes cannot be empty" )
107+ raise ValueError (
108+ "scopes cannot be an empty list; use None to use control plane defaults"
109+ )
101110
102111 # Validate each scope is not empty
103112 for scope in v :
@@ -128,15 +137,6 @@ def validate_callback_url(cls, v: Optional[str]) -> Optional[str]:
128137 raise ValueError ("callback_url must be a valid HTTP/HTTPS URL" )
129138 return v
130139
131- @model_validator (mode = "after" )
132- def _validate_required_fields (self ):
133- """Validate required fields."""
134- if not self .scopes :
135- raise ValueError ("scopes is required for OAuth2AuthConfig" )
136- if not self .auth_flow :
137- raise ValueError ("auth_flow is required for OAuth2AuthConfig" )
138- return self
139-
140140 @property
141141 def auth_type (self ) -> str :
142142 return "oauth2"
@@ -201,8 +201,8 @@ def workload_auth(
201201
202202def oauth2_auth (
203203 provider_name : str ,
204- scopes : List [str ],
205- auth_flow : Literal ["M2M" , "USER_FEDERATION" ],
204+ scopes : Optional [ List [str ]] = None ,
205+ auth_flow : Optional [ Literal ["M2M" , "USER_FEDERATION" ]] = None ,
206206 callback_url : Optional [str ] = None ,
207207 force_authentication : bool = False ,
208208 response_for_auth_required : Optional [Union [dict , str ]] = None ,
@@ -215,8 +215,10 @@ def oauth2_auth(
215215
216216 Args:
217217 provider_name: Name of the credential provider.
218- scopes: List of OAuth2 scopes.
219- auth_flow: Authentication flow type ("M2M" or "USER_FEDERATION").
218+ scopes: Optional list of OAuth2 scopes. If not provided, the control plane
219+ will use the default configured scopes for the provider.
220+ auth_flow: Optional authentication flow type ("M2M" or "USER_FEDERATION").
221+ If not provided, the control plane will use the default configured flow.
220222 callback_url: Optional callback URL for OAuth2.
221223 force_authentication: Whether to force authentication.
222224 response_for_auth_required: Response to return when auth is required.
0 commit comments