3030#include < fstream>
3131
3232#include " snowflake/SF_CRTFunctionSafe.h"
33+ #include " snowflake/WifAttestation.hpp"
3334
3435#ifdef __APPLE__
3536#include < CoreFoundation/CFBundle.h>
@@ -75,6 +76,10 @@ extern "C" {
7576 {
7677 return AUTH_PAT;
7778 }
79+ if (strcasecmp (authenticator, SF_AUTHENTICATOR_WORKLOAD_IDENTITY) == 0 )
80+ {
81+ return AUTH_WIF;
82+ }
7883
7984 if (strcasecmp (authenticator, " test" ) == 0 )
8085 {
@@ -190,6 +195,46 @@ extern "C" {
190195 snowflake_cJSON_AddStringToObject (data, " TOKEN" , conn->oauth_token );
191196 }
192197 }
198+ if (AUTH_WIF == authenticator)
199+ {
200+ Snowflake::Client::AttestationConfig config;
201+
202+ // Populate config from SF_CONNECT fields
203+ if (conn->wif_provider ) {
204+ auto typeOpt = Snowflake::Client::attestationTypeFromString (conn->wif_provider );
205+ if (typeOpt) {
206+ config.type = typeOpt;
207+ log_debug (" Using explicit WIF provider: %s" , conn->wif_provider );
208+ } else {
209+ log_warn (" Invalid WIF provider specified: %s, falling back to auto-detection" , conn->wif_provider );
210+ }
211+ }
212+
213+ if (conn->wif_token ) {
214+ config.token = std::string (conn->wif_token );
215+ log_debug (" Using explicit WIF token" );
216+ }
217+
218+ if (conn->wif_azure_resource ) {
219+ config.snowflakeEntraResource = std::string (conn->wif_azure_resource );
220+ log_debug (" Using Azure resource: %s" , conn->wif_azure_resource );
221+ }
222+
223+ if (auto attestationOpt = Snowflake::Client::createAttestation (config))
224+ {
225+ const Snowflake::Client::Attestation &attestation = attestationOpt.value ();
226+
227+ snowflake_cJSON_DeleteItemFromObject (data, " AUTHENTICATOR" );
228+ snowflake_cJSON_DeleteItemFromObject (data, " TOKEN" );
229+
230+ snowflake_cJSON_AddStringToObject (data, " AUTHENTICATOR" , SF_AUTHENTICATOR_WORKLOAD_IDENTITY);
231+ snowflake_cJSON_AddStringToObject (data, " TOKEN" , attestation.credential .c_str ());
232+ snowflake_cJSON_AddStringToObject (data, " PROVIDER" ,
233+ Snowflake::Client::stringFromAttestationType (attestation.type ));
234+ } else {
235+ log_error (" Failed to create WIF attestation - not running in a supported cloud environment?" );
236+ }
237+ }
193238
194239 if (conn->sso_token )
195240 {
@@ -222,8 +267,6 @@ extern "C" {
222267 {
223268 ; // Do nothing
224269 }
225-
226- return ;
227270 }
228271
229272 void auth_renew_json_body (SF_CONNECT * conn, cJSON* body)
@@ -246,8 +289,6 @@ extern "C" {
246289 {
247290 ; // Do nothing
248291 }
249-
250- return ;
251292 }
252293
253294 void STDCALL auth_terminate (SF_CONNECT * conn)
0 commit comments