Verwenden von Snowflake OAuth für lokale Anwendungen¶
Unter diesem Thema wird die bevorzugte Authentifizierungsmethode für lokale Anwendungen beschrieben, einschließlich Desktop-Anwendungen und lokaler Skripte.
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.
Ein Verwaltender kann die Parameter der SNOWFLAKE$LOCAL_APPLICATION-Integration ändern, um das Verhalten anzupassen, z. B. wie lange OAuth-Zugriffstoken und Aktualisierungstoken gültig sind.
Snowflake OAuth für lokale Anwendungen bietet folgende zusätzliche Vorteile:
Unlike user-created Snowflake OAuth integrations, in-role session switching is supported.
Es ist ein einfacher Ersatz für Anwendungen, die derzeit Kennwörter nur zur Authentifizierung von Benutzenden verwenden. Snowflake unterstützt nicht länger Ein-Faktor-Kennwörter. Snowflake OAuth für lokale Anwendungen bietet einen Weg, eine sicherere Form der Authentifizierung zu verwenden, ohne dass umfangreiche Einrichtungsschritte erforderlich sind.
Bemerkung
Die SNOWFLAKE$LOCAL_APPLICATION-Sicherheitsintegration wird langsam auf alle Konten eingeführt. Um festzustellen, ob diese automatische Integration in Ihrem Konto vorhanden ist, führen Sie den folgenden Befehl aus:
SHOW SECURITY INTEGRATIONS LIKE 'SNOWFLAKE$LOCAL_APPLICATION';
Konfigurieren der Snowflake OAuth-Integration¶
Die automatische SNOWFLAKE$LOCAL_APPLICATION-Sicherheitsintegration ist Eigentum des Systems, kann aber von Sicherheitsadministratoren (d. h. Benutzenden, denen die Systemrolle SECURITYADMIN zugewiesen wurde) konfiguriert werden.
Sicherheitsadministratoren können die folgenden Parameter der Sicherheitsintegration konfigurieren:
Parameter |
Beschreibung |
|---|---|
|
Steuert, ob die Integration aktiviert ist. Wenn die Integration deaktiviert ist, müssen lokale Anwendungen eine andere Authentifizierungsmethode verwenden. |
|
Controls whether the authorization server issues refresh tokens. |
|
Legt die Gültigkeitsdauer von Aktualisierungstoken fest. |
|
Controls whether the authorization server issues single-use refresh tokens. |
|
Legt die Gültigkeitsdauer von Zugriffstoken fest. |
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;
Weitere Informationen zum Einstellen dieser Parameter finden Sie unter ALTER SECURITY INTEGRATION.
Überwachen der Anmeldefrequenz¶
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.
Einrichten einer lokalen Anwendung für die Verwendung von 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:
Eine lokale Anwendung, die einen Snowflake-Client wie den Python-Treiber oder Snowflake CLI verwendet. Siehe Anwendungen, die einen Snowflake-Client verwenden.
Eine lokale Anwendung, die REST-Anforderungen an den OAuth-Autorisierungsendpunkt und Token-Endpunkt direkt ohne die Verwendung eines Snowflake-Clients ausführt. Siehe Anwendungen, die OAuth-Endpunkte direkt aufrufen.
Anwendungen, die einen Snowflake-Client verwenden¶
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.
Voraussetzung¶
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.
Unterstützte Clients¶
Ihre lokale Anwendung kann die folgenden Snowflake-Clients verwenden, um sich bei Snowflake OAuth für lokale Anwendungen zu authentifizieren:
Client |
Erforderliche Mindestversion |
Erforderliche Konfiguration |
|---|---|---|
.NET |
v4.8.0 |
Legen Sie |
Go |
v1.14.1 |
Legen Sie |
JDBC |
v3.24.1 |
Legen Sie |
Node.js |
v2.1.0 |
Legen Sie |
ODBC |
v3.9.0 |
|
Python |
v3.16.0 |
Übergeben Sie |
Snowflake CLI |
v3.8.1 |
Fügen Sie die Option |
SnowSQL |
v1.4.0 |
Fügen Sie den Parameter |
Anwendungen, die OAuth-Endpunkte direkt aufrufen¶
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.
Weitere Informationen zum Erstellen von REST-Anforderungen an die Autorisierungs- und Token-Endpunkte von Snowflake finden Sie unter OAuth-Endpunkte aufrufen.
Anfrageanforderungen¶
Die REST-Anforderungen Ihrer Anwendung an die Autorisierungs- und Token-Endpunkte müssen den folgenden Anforderungen entsprechen:
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.Anforderungen an die Autorisierungs- und Token-Endpunkte müssen Proof Key for Code Exchange (PKCE) implementieren. Weitere Informationen dazu finden Sie unter Proof Key for Code Exchange (PKCE).
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:
Wenn Sie Anmeldeinformationen des Clients im Anforderungs-Header senden, muss die Client-ID
LOCAL_APPLICATIONsein, und das Clientgeheimnis mussLOCAL_APPLICATIONsein.Wenn Sie Anmeldeinformationen des Clients im POST-Textkörper senden, muss die Client-ID
LOCAL_APPLICATIONsein. Die automatische Integration konfiguriert die lokale Anwendung als öffentlichen Client, sodass das Clientgeheimnis nicht erforderlich ist, wenn Sie die Client-ID alsclient_id=LOCAL_APPLICATIONim POST-Textkörper bereitstellen.
Nutzungshinweise¶
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.