Dataform 客户端库提供了以编程方式向 Dataform 进行身份验证的高级语言支持。
为了对 Google Cloud API 的调用进行身份验证,客户端库支持应用默认凭据 (ADC);这些库会在一组指定的位置查找凭据,并使用这些凭据对发送到 API 的请求进行身份验证。借助 ADC,您可以在各种环境(例如本地开发或生产环境)中为您的应用提供凭据,而无需修改应用代码。
在大多数情况下,您可以使用用户凭据从本地开发环境进行身份验证。如果这种方法不可行,或者您需要测试分配给服务账号的权限,则可以使用服务账号模拟。您必须拥有 iam.serviceAccounts.getAccessToken 权限,该权限包含在 Service Account Token Creator (roles/iam.serviceAccountTokenCreator) IAM 角色中。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-04。"],[[["\u003cp\u003eDataform offers programmatic access through client libraries and REST APIs, enabling automation and integration.\u003c/p\u003e\n"],["\u003cp\u003eApplication Default Credentials (ADC) are the recommended method for authentication, allowing consistent credential management across various environments.\u003c/p\u003e\n"],["\u003cp\u003eFor local development, you can set up authentication using user credentials, including ADC setup with the gcloud CLI, or through REST requests using the \u003ccode\u003egcloud auth print-access-token\u003c/code\u003e command.\u003c/p\u003e\n"],["\u003cp\u003eService account impersonation is available for testing service account permissions or when using user credentials isn't viable, requiring the \u003ccode\u003eiam.serviceAccounts.getAccessToken\u003c/code\u003e permission.\u003c/p\u003e\n"],["\u003cp\u003eOnce authenticated, Dataform uses Identity and Access Management (IAM) for authorization to control access to Google Cloud resources.\u003c/p\u003e\n"]]],[],null,["# Authenticate to Dataform\n\nThis document describes how to authenticate to Dataform programmatically. How\nyou authenticate to Dataform depends on the interface you use to access the API\nand the environment where your code is running.\n\n\nFor more information about Google Cloud authentication, see the\n[Authentication methods](/docs/authentication).\n\nAPI access\n----------\n\n\nDataform supports programmatic access. You can access the API in\nthe following ways:\n\n- [Client libraries](#client-libraries)\n- [REST](#rest)\n\n### Client libraries\n\n\nThe [Dataform client libraries](/dataform/docs/reference/libraries) provide\nhigh-level language support for authenticating to Dataform\nprogrammatically.\n\n\nTo authenticate calls to Google Cloud APIs, client libraries support\n[Application Default Credentials (ADC)](/docs/authentication/application-default-credentials);\nthe libraries look for credentials in a set of defined locations and use those credentials\nto authenticate requests to the API. With ADC, you can make\ncredentials available to your application in a variety of environments, such as local\ndevelopment or production, without needing to modify your application code.\n\n### REST\n\n\nYou can authenticate to\n[the Dataform API](/dataform/reference/rest)\nby using your gcloud CLI credentials or by using\n[Application Default Credentials](/docs/authentication/application-default-credentials).\nFor more information about authentication for REST requests, see\n[Authenticate for using REST](/docs/authentication/rest).\nFor information about the types of credentials, see\n[gcloud CLI credentials and ADC credentials](/docs/authentication/gcloud#gcloud-credentials).\n\nSet up authentication for Dataform\n----------------------------------\n\n\nHow you set up authentication depends on the environment where your code is running.\n\n\nThe following options for setting up authentication are the most commonly used. For more\noptions and information about authentication, see\n[Authentication methods](/docs/authentication).\n\n### For a local development environment\n\n\nYou can set up credentials for a local development environment in the following ways:\n\n- [User credentials for client libraries or third-party tools](#client-libs)\n- [User credentials for REST requests from the command line](#rest-requests)\n- [Service account impersonation](#sa-impersonation)\n\n#### Client libraries or third-party tools\n\n\nSet up\n[Application Default Credentials (ADC)](/docs/authentication/application-default-credentials)\nin your local environment:\n\n1.\n [Install](/sdk/docs/install) the Google Cloud CLI.\n\n After installation,\n [initialize](/sdk/docs/initializing) the Google Cloud CLI by running the following command:\n\n ```bash\n gcloud init\n ```\n\n\n If you're using an external identity provider (IdP), you must first\n [sign in to the gcloud CLI with your federated identity](/iam/docs/workforce-log-in-gcloud).\n2.\n\n If you're using a local shell, then create local authentication credentials for your user\n account:\n\n ```bash\n gcloud auth application-default login\n ```\n\n You don't need to do this if you're using Cloud Shell.\n\n\n If an authentication error is returned, and you are using an external identity provider\n (IdP), confirm that you have\n [signed in to the gcloud CLI with your federated identity](/iam/docs/workforce-log-in-gcloud).\n\n\n A sign-in screen appears. After you sign in, your credentials are stored in the\n [local credential file used by ADC](/docs/authentication/application-default-credentials#personal).\n\n\nFor more information about working with ADC in a local environment, see\n[Set up ADC for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n#### REST requests from the command line\n\n\nWhen you make a REST request from the command line,\nyou can use your gcloud CLI credentials by including\n[`gcloud auth print-access-token`](/sdk/gcloud/reference/auth/print-access-token)\nas part of the command that sends the request.\n\n\nThe following example lists service accounts for the specified project. You can use the\nsame pattern for any REST request.\n\n\nBefore using any of the request data,\nmake the following replacements:\n\n- \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: Your Google Cloud project ID.\n\nTo send your request, expand one of these options:\n\n#### curl (Linux, macOS, or Cloud Shell)\n\n\nExecute the following command:\n\n```\ncurl -X GET \\\n -H \"Authorization: Bearer $(gcloud auth print-access-token)\" \\\n \"https://iam.googleapis.com/v1/projects/PROJECT_ID/serviceAccounts\"\n```\n\n#### PowerShell (Windows)\n\n\nExecute the following command:\n\n```\n$cred = gcloud auth print-access-token\n$headers = @{ \"Authorization\" = \"Bearer $cred\" }\n\nInvoke-WebRequest `\n -Method GET `\n -Headers $headers `\n -Uri \"https://iam.googleapis.com/v1/projects/PROJECT_ID/serviceAccounts\" | Select-Object -Expand Content\n```\n\n\nFor more information about authenticating using REST and gRPC, see\n[Authenticate for using REST](/docs/authentication/rest).\nFor information about the difference between your local ADC credentials and your\ngcloud CLI credentials, see\n[gcloud CLI authentication configuration and ADC configuration](/docs/authentication/gcloud#gcloud-credentials).\n\n#### Service account impersonation\n\n\nIn most cases, you can use your user credentials to authenticate from a local development\nenvironment. If that is not feasible, or if you need to test the permissions assigned to\na service account, you can use service account impersonation. You must have the\n`iam.serviceAccounts.getAccessToken` permission, which is included in the\n[Service Account Token Creator](/iam/docs/understanding-roles#iam.serviceAccountTokenCreator)\n(`roles/iam.serviceAccountTokenCreator`) IAM role.\n\n\nYou can set up the gcloud CLI to use service account impersonation by using the\n[`gcloud config set` command](/sdk/gcloud/reference/config): \n\n```bash\ngcloud config set auth/impersonate_service_account SERVICE_ACCT_EMAIL\n```\n\n\nFor select languages, you can use service account impersonation to create a local ADC file\nfor use by client libraries. This approach is supported only for the Go, Java, Node.js, and\nPython client libraries---it is not supported for the other languages.\nTo set up a local ADC file with service account impersonation, use the\n[`--impersonate-service-account` flag](/sdk/gcloud/reference#--impersonate-service-account)\nwith the [`gcloud auth application-default login` command](/sdk/gcloud/reference/auth/application-default/login): \n\n```bash\ngcloud auth application-default login --impersonate-service-account=SERVICE_ACCT_EMAIL\n```\n\n\nFor more information about service account impersonation, see\n[Use service account impersonation](/docs/authentication/use-service-account-impersonation).\n\nAccess control for Dataform\n---------------------------\n\n\nAfter you authenticate to Dataform, you must be authorized to access\nGoogle Cloud resources. Dataform uses\nIdentity and Access Management (IAM) for authorization.\n\n\nFor more information about the roles for Dataform, see\n[Access control with IAM](/dataform/docs/access-control).\nFor more information about IAM and authorization, see\n[IAM overview](/iam/docs/overview).\n\nWhat's next\n-----------\n\n- Learn about [Google Cloud authentication methods](/docs/authentication#auth-decision-tree).\n- See a list of [authentication use cases](/docs/authentication/use-cases)."]]