Note: For OAuth 2.0 authentication, using a refresh token is more user-friendly and secure than using an access token. The access token expires every 10 minutes and may need to be generated multiple times a day, which can prolong the process of establishing a connection and cause a security risk.

The access token authentication flow passes the token directly from the client to the Snowflake instance for authentication. The token is obtained from sources external to the flow and specified using the AccessToken property. The following string includes the properties used to connect with the access token flow.

jdbc:datadirect:snowflake:AccountName=account_name;AuthenticationMethod=OAuth2;
AccessToken=access_token;DatabaseName=database_name;Schema=schema_name;
Warehouse=warehouse_name;[property=value[;...]];

where:

account_name

specifies the full name of your account with region and cloud platform.

access_token

specifies the access token required to authenticate to Snowflake. This property allows you to set the token manually.

Important:

  • The access token is a confidential value used to authenticate to the server. To prevent unauthorized access, this value must be securely maintained.
  • Access tokens expire ten minutes after generation. Once connected, the access token remains valid till the session is disconnected.
database_name

specifies the name of the database to which you are connecting.

schema_name

specifies the default schema to use for the specified database once connected. The specified schema should be an existing schema for which the specified default role has privileges.

warehouse_name

specifies the virtual warehouse to use once connected. The specified warehouse should be an existing warehouse for which the specified default role has privileges.

property=value
specifies connection property settings. Multiple properties are separated by a semi-colon.

The following example connection string includes the properties required for connecting with the OAuth 2.0 access token flow.

Connection conn = DriverManager.getConnection
("jdbc:datadirect:snowflake:AccountName=account_name.us-east-1;
  AuthenticationMethod=OAuth2;AccessToken=abc12cd34efg5678h9ij87klm6543no32pqr10;
  DatabaseName=payroll;Schema=xyz;Warehouse=accounting;");