Utilisation de Snowflake OAuth pour les applications locales¶
This topic describes the preferred authentication method for local applications, including desktop applications and local scripts.
Snowflake OAuth is implemented by creating a security integration that defines an interface between Snowflake as the OAuth authorization server and the application that is authenticating on behalf of a user by using the OAuth authorization code flow. Snowflake OAuth is a strong authentication option because the application doesn’t have to store or manage secrets, and you don’t have to configure a third-party identity provider like External OAuth.
To simplify how a local application uses Snowflake OAuth to authenticate, your account has a built-in
security integration called SNOWFLAKE$LOCAL_APPLICATION. Because the security integration already exists, if a local application
uses a Snowflake client like the Python driver or Snowflake CLI, the application can authenticate to Snowflake by setting a property or
parameter of the client. No further set up is required. The built-in integration also simplifies the setup for local applications that call
the OAuth endpoints directly rather than use a Snowflake client.
Un administrateur peut modifier les paramètres de l’intégration SNOWFLAKE$LOCAL_APPLICATION pour ajuster son comportement, par exemple en spécifiant la durée de validité des jetons d’accès OAuth et des jetons d’actualisation.
Snowflake OAuth pour les applications locales présente les avantages supplémentaires suivants :
Unlike user-created Snowflake OAuth integrations, in-role session switching is supported.
Il s’agit d’un remplacement simple pour les applications qui utilisent actuellement uniquement des mots de passe pour authentifier les utilisateurs. Snowflake abandonne l’utilisation des mots de passe à un seul facteur. Snowflake OAuth pour les applications locales offre donc un moyen d’utiliser une forme d’authentification plus sécurisée sans nécessiter beaucoup de configuration.
Note
L’intégration de sécurité SNOWFLAKE$LOCAL_APPLICATION est déployée au fur et à mesure sur tous les comptes. Pour déterminer si cette intégration existe dans votre compte, exécutez la commande suivante :
SHOW SECURITY INTEGRATIONS LIKE 'SNOWFLAKE$LOCAL_APPLICATION';
Configurer l’intégration OAuth Snowflake¶
L’intégration de sécurité SNOWFLAKE$LOCAL_APPLICATION appartient au système, mais peut être configurée par les administrateurs de sécurité (c’est-à-dire les utilisateurs disposant du rôle SECURITYADMIN dans le système).
Les administrateurs de sécurité peuvent configurer les paramètres suivants de l’intégration de sécurité :
Paramètre |
Description |
|---|---|
|
Contrôle si l’intégration est activée. Si l’intégration est désactivée, les applications locales doivent utiliser une méthode d’authentification différente. |
|
Controls whether the authorization server issues refresh tokens. |
|
Définit la durée de validité des jetons d’actualisation. |
|
Controls whether the authorization server issues single-use refresh tokens. |
|
Définit la durée de validité des jetons d’accès. |
For example, to modify the built-in security integration so that the authorization server starts issuing single-use refresh tokens, run the following commands:
USE ROLE SECURITYADMIN;
ALTER SECURITY INTEGRATION SNOWFLAKE$LOCAL_APPLICATION
SET OAUTH_SINGLE_USE_REFRESH_TOKENS_REQUIRED = TRUE;
Pour plus d’informations sur le réglage de ces paramètres, voir ALTER SECURITY INTEGRATION.
Contrôle de la fréquence de connexion¶
When OAUTH_ISSUE_REFRESH_TOKENS = TRUE, applications can use refresh tokens to obtain new access tokens without prompting users to log
in again. Users only need to re-authenticate when the refresh token expires after the duration that is specified by the
OAUTH_REFRESH_TOKEN_VALIDITY parameter.
Configuration d’une application locale pour utiliser Snowflake OAuth¶
This section provides the details a developer needs to configure a local application to authenticate with Snowflake OAuth. The following types of local applications can authenticate by using the built-in integration:
Une application locale qui utilise un client Snowflake comme le pilote Python ou la CLI Snowflake. Voir Applications qui utilisent un client Snowflake.
Une application locale qui envoie directement des requêtes REST au point de terminaison d’autorisation OAuth et au point de terminaison de jeton, sans utiliser de client Snowflake. Voir Applications qui appellent directement les points de terminaison OAuth.
Applications qui utilisent un client Snowflake¶
When a local application uses a Snowflake client like the Snowflake ODBC driver, it can authenticate with Snowflake OAuth by setting the
authenticator connection option to oauth_authorization_code. Additional development work isn’t required.
Conditions préalables¶
With Snowflake OAuth for local applications, the Snowflake client must be able to open the user’s web browser. For this reason, both the Snowflake client and the local application that uses it must be installed on the user’s computer. Snowflake OAuth for local applications doesn’t work if the Snowflake client is used by code that runs on a server.
Clients pris en charge¶
Votre application locale peut utiliser les clients Snowflake suivants pour s’authentifier auprès de Snowflake OAuth pour les applications locales :
Client |
Version minimale requise |
Configuration requise |
|---|---|---|
.NET |
v4.8.0 |
Définissez |
Go |
v1.14.1 |
Définissez |
JDBC |
v3.24.1 |
Définissez |
Node.js |
v2.1.0 |
Définissez |
ODBC |
v3.9.0 |
|
Python |
v3.16.0 |
Validez |
Snowflake CLI |
v3.8.1 |
Ajoutez l’option |
SnowSQL |
v1.4.0 |
Ajoutez le paramètre |
Applications qui appellent directement les points de terminaison OAuth¶
Your local application can use Snowflake OAuth by making requests to the authorization endpoint and token endpoint of Snowflake as the authorization server. You don’t need to use a Snowflake client. The application sends a request to Snowflake’s authorization endpoint to authenticate the user and receive an authorization code, and then sends a request to the token endpoint to exchange that code for an access token.
Pour plus d’informations sur la création de requêtes REST vers les points de terminaison d’autorisation et de jeton de Snowflake, voir Appel des points de terminaison OAuth.
Exigences relatives aux requêtes¶
Les requêtes REST de votre application vers les points de terminaison d’autorisation et de jeton doivent être conformes aux exigences suivantes :
The redirect URL in the request to the authorization endpoint must be
http://127.0.0.1[:port][/path]. That is, your local application must be listening on a loopback address for the authorization code that is returned by Snowflake as the authorization server.Les demandes vers les points de terminaison d’autorisation et de jeton doivent mettre en œuvre la clé de preuve pour l’échange de code (PKCE). Pour plus d’informations, voir Clé de preuve pour l’échange de code.
When calling the token endpoint to exchange an authorization code for an access token, the application must provide the proper client ID and client secret. This requirement varies slightly depending on how you choose to send these client credentials:
Si vous envoyez les identifiants de connexion client dans l’en-tête de la requête, l’ID du client doit être
LOCAL_APPLICATIONet le secret du client doit êtreLOCAL_APPLICATION.Si vous envoyez les identifiants de connexion client dans le corps du POST, l’ID client doit être
LOCAL_APPLICATION. L’intégration configure l’application locale comme client public, donc le secret du client n’est pas nécessaire si vous fournissez l’ID du client en tant queclient_id=LOCAL_APPLICATIONdans le corps du POST.
Notes sur l’utilisation¶
Every account has a SNOWFLAKE$LOCAL_APPLICATION integration, so this integration isn’t replicated. The
configuration of the built-in integration is unique to each account.