@@ -444,15 +444,21 @@ private void SetUserDetails(K8SConfiguration k8SConfig, Context activeContext)
444444 throw new KubeConfigException ( "External command execution missing ApiVersion key" ) ;
445445 }
446446
447- var ( accessToken , clientCertificateData , clientCertificateKeyData ) = ExecuteExternalCommand ( userDetails . UserCredentials . ExternalExecution ) ;
448- AccessToken = accessToken ;
447+ var response = ExecuteExternalCommand ( userDetails . UserCredentials . ExternalExecution ) ;
448+ AccessToken = response . Status . Token ;
449449 // When reading ClientCertificateData from a config file it will be base64 encoded, and code later in the system (see CertUtils.GeneratePfx)
450450 // expects ClientCertificateData and ClientCertificateKeyData to be base64 encoded because of this. However the string returned by external
451451 // auth providers is the raw certificate and key PEM text, so we need to take that and base64 encoded it here so it can be decoded later.
452- ClientCertificateData = clientCertificateData == null ? null : Convert . ToBase64String ( System . Text . Encoding . ASCII . GetBytes ( clientCertificateData ) ) ;
453- ClientCertificateKeyData = clientCertificateKeyData == null ? null : Convert . ToBase64String ( System . Text . Encoding . ASCII . GetBytes ( clientCertificateKeyData ) ) ;
452+ ClientCertificateData = response . Status . ClientCertificateData == null ? null : Convert . ToBase64String ( System . Text . Encoding . ASCII . GetBytes ( response . Status . ClientCertificateData ) ) ;
453+ ClientCertificateKeyData = response . Status . ClientKeyData == null ? null : Convert . ToBase64String ( System . Text . Encoding . ASCII . GetBytes ( response . Status . ClientKeyData ) ) ;
454454
455455 userCredentialsFound = true ;
456+
457+ // TODO: support client certificates here too.
458+ if ( AccessToken != null )
459+ {
460+ TokenProvider = new ExecTokenProvider ( userDetails . UserCredentials . ExternalExecution ) ;
461+ }
456462 }
457463
458464 if ( ! userCredentialsFound )
@@ -525,7 +531,7 @@ public static Process CreateRunnableExternalProcess(ExternalExecution config)
525531 /// <returns>
526532 /// The token, client certificate data, and the client key data received from the external command execution
527533 /// </returns>
528- public static ( string , string , string ) ExecuteExternalCommand ( ExternalExecution config )
534+ public static ExecCredentialResponse ExecuteExternalCommand ( ExternalExecution config )
529535 {
530536 if ( config == null )
531537 {
@@ -562,18 +568,9 @@ public static (string, string, string) ExecuteExternalCommand(ExternalExecution
562568 $ "external exec failed because api version { responseObject . ApiVersion } does not match { config . ApiVersion } ") ;
563569 }
564570
565- if ( responseObject . Status . ContainsKey ( "token" ) )
566- {
567- return ( responseObject . Status [ "token" ] , null , null ) ;
568- }
569- else if ( responseObject . Status . ContainsKey ( "clientCertificateData" ) )
571+ if ( responseObject . Status . IsValid ( ) )
570572 {
571- if ( ! responseObject . Status . ContainsKey ( "clientKeyData" ) )
572- {
573- throw new KubeConfigException ( $ "external exec failed missing clientKeyData field in plugin output") ;
574- }
575-
576- return ( null , responseObject . Status [ "clientCertificateData" ] , responseObject . Status [ "clientKeyData" ] ) ;
573+ return responseObject ;
577574 }
578575 else
579576 {
0 commit comments