DataConnector | ComponentOne
ADO.NET provider for Snowflake / Authentication
In This Topic
    Authentication
    In This Topic

    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 !!!");
    }

    Supported Authentication methods for Snowflake provider

    Snowflake supports two main authentication methods: OAuth2 authentication and Key Pair authentication.

    Connection properties used on each type of authentication

    OAuth2 Authentication

    1. Url: Specifies the URL of the Snowflake server.
    2. Account: Specifies the Snowflake account URL.
    3. Warehouse: Specifies the Snowflake warehouse name.
    4. Role: Specifies the Snowflake role.
    5. Database: Specifies the Snowflake database name.
    6. Schema: Specifies the Snowflake schema name.
    7. OAuthTokenEndpoint: Specifies the OAuth token endpoint URL for authentication.
    8. OAuthClientId: Specifies the OAuth client ID for authentication.
    9. OAuthClientSecret: Specifies the OAuth client secret for authentication.
    10. OAuthAccessToken: Specifies the OAuth access token for authentication.
    11. OAuthRefreshToken: Specifies the OAuth refresh token for authentication.

    Key Pair Authentication

    1. Private key: is the generated file together with a public key that contains the private key, in this property should be specified the path of the file.
    2. Fingerprint: the fingerprint can be retrieved in the Snowflake console using the query ‘DESC USER username’.
    3. Username: the username used to log in to the Snowflake console.