OAuth is an open-standard authorization protocol that allows unlinked servers and services to provide authenticated access to data sources without sharing private credentials. It is widely used in various applications for user authentication. If you want to learn more about OAuth and the different types of credentials, refer to OAuth Authorization topic.
Snowflake authorization is slightly different compared to other providers provided by C1DataConnector. In Snowflake, the DataConnector APIs do not automatically generate OAuthAccessToken and OAuthRefreshToken. After fetching OAuthAccessToken and OAuthRefreshToken from OAuth 2.0 Playground using the OAuthClientId and OAuthClientSecret, you can complete the authentication to provide secured access to fetch data from the resource server. To connect to a Snowflake, provide the following properties:
C# |
Copy Code |
---|---|
static string OAuthClientId = @"**********"; static string OAuthClientSecret = @"*******"; static string OAuthAccessToken = @"*******"; static string OAuthRefreshToken = @"*********"; static string OAuthTokenEndpoint = "https://****.snowflakecomputing.com/oauth/token-request"; |
Using the OAuthClientId OAuthClientSecret OAuthRefreshToken Snowflake provider will automatically refresh the access token:
C# |
Copy Code |
---|---|
//Create connection string using C1SnowflakeConnectionStringBuilder C1SnowflakeConnectionStringBuilder builder = new C1SnowflakeConnectionStringBuilder(); builder.Account = "****.eu-west-2.aws"; builder.Url = "https://****.eu-west-2.aws.snowflakecomputing.com"; builder.Warehouse = "****"; builder.Database = "****"; builder.Schema = "****"; builder.Role = "****"; builder.OAuthTokenEndpoint = "****.snowflakecomputing.com/oauth/token-request"; builder.OAuthClientId = "****"; builder.OAuthClientSecret = "****"; builder.OAuthRefreshToken = "****"; builder.OAuthAccessToken = "****"; //Setup Connection using (C1SnowflakeConnectionconn = new C1SnowflakeConnection(builder)) { //Tried fetching data from two different tables C1SnowflakeCommand comm = new C1SnowflakeCommand(conn, "Select * from CALL_CENTER"); C1SnowflakeDataAdapter adapter = new C1SnowflakeDataAdapter(comm); DataTable dataTable = new DataTable(); adapter.Fill(dataTable); //Display fetched data foreach (DataRow row in dataTable.Rows) { Console.WriteLine("{0}\t{1}\t{2}", row[0], row[1], row[2]); } Console.WriteLine("Connection created and read operation completed !!!"); } |
Snowflake supports two main authentication methods: OAuth2 authentication and Key Pair authentication.