---
schema_version: "1"
id: 52bed44ca16ed5e04835c4bb81a9f37ced9f067d3de25bd6c662d325f50edd6c
title: 设置 Amazon Athena IAM OAuth
collection: tableau
version: current
locale: zh-cn
portal_url: https://docs.salesforce.com/tableau/current/zh-cn/pro/desktop/amazon_athena_idp.md
canonical_url: https://help.tableau.com/current/pro/desktop/zh-cn/amazon_athena_idp.htm
source_site: help.tableau.com
content_type: documentation
content_hash: 1fd940a685d022823ca4ace5ccae34c1421fcb69b83161ee1a13aa45d5362d71
description: Set up OAuth 2.0/OIDC identity federation from an external IdP to Amazon Athena for Tableau.
---
[跳转到主要内容](#main-content)

# 设置 Amazon Athena IAM OAuth

从 Tableau 2023.2 开始，您可以使用 OAuth 2.0/OIDC 将外部身份提供程序 (IDP) 中的身份联合到 Amazon Athena。

根据身份提供程序的不同，配置集成需要执行不同的步骤。Tableau 仅提供有关如何配置 Tableau 产品的详细说明。有关如何配置身份提供程序（例如 Okta）的说明，请参阅该产品的帮助和教程。本文档概括介绍了配置过程。

**注意**：使用 Tableau Bridge 与 Tableau Cloud 的 OAuth 连接不支持一次性刷新令牌（有时称为滚动刷新令牌或刷新令牌轮换）。我们计划在未来的版本中支持这些令牌。

**注意：**Tableau 和 Salesforce 内容之外的步骤和链接可能不会更新或不准确。

## 配置身份提供程序 (IDP)

1. 在 IDP 上为 Tableau Desktop 和 Tableau Server 创建 OAuth 客户端。Desktop 客户端启用 [PKCE](https://auth0.com/docs/get-started/authentication-and-authorization-flow/authorization-code-flow-with-pkce) 并使用 [http://localhost](http://localhost/) 重定向。
2. 添加用于角色授权的任何必需的自定义声明。有关声明和范围的更多详细信息，请参见[范围与声明](https://curity.io/resources/learn/scopes-vs-claims/)。
3. 创建 Tableau OAuth 配置文件。有关如何执行此操作的详细信息，请参见 [github](https://tableau.github.io/connector-plugin-sdk/docs/oauth) 上的 [OAuth 配置和使用](https://tableau.github.io/connector-plugin-sdk/docs/oauth)，以及[此处](https://github.com/tableau/connector-plugin-sdk/tree/master/samples/components/oauth)的示例。请务必在 Tableau OAuth 配置 ID 前添加“custom\_”前缀。
4. 在 Tableau Desktop计算机、Tableau Server 和 Tableau Cloud 站点上安装 Tableau OAuth 配置文件，如上面链接的 OAuth 配置主题中所述。

## 在 AWS 上配置 IDP

1. 创建 IDP 实体。请参见 Amazon 文档 [Web 身份联合](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_providers_oidc.html)、[创建 OIDC 身份提供提供程序](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_providers_create_oidc.html)。
2. 必须将 IDP 配置为与 Athena 联合，以便与 Tableau 的驱动程序插件配合使用。以下提供程序信息用于 Tableau Server 和 Tableau Desktop 流程：
    
    AwsCredentialsProviderClass=com.simba.athena.iamsupport.plugin.JwtCredentialsProvider  
    role\_session\_name=AthenaJWT
3. 专门为 IDP 创建角色和策略。请参见 AWS 文档上的[为 OIDC 创建角色](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_create_for-idp_oidc.html)。

## 为 Athena 配置角色

附上 Athena 所需的策略。有很多方法可以实现这一点。一种方法是使用自定义声明。您可以使用 openID 令牌中的自定义声明来授权角色。这些角色被授予对其他资源的访问权限。有关详细信息，请参见：

- 教程：[使用 Lake Formation 和 JDBC 配置 Okta 用户对 Athena 的联合访问](https://docs.aws.amazon.com/athena/latest/ug/security-athena-lake-formation-jdbc-okta-tutorial.html)。
- [对 AWS Glue 数据目录中的数据库和表进行细粒度访问。](https://docs.aws.amazon.com/athena/latest/ug/fine-grained-access-to-glue-resources.html)

## 连接到 Athena

用户必须指定要代入的 AWS 角色 ARN（Amazon 资源名称），然后，在“OAuth 提供程序”下，选择之前安装的 OAuth 配置。请注意，仅当有多个配置可供选择时，才会出现选择配置的下拉菜单。

正确配置后，用户将被重定向到 IDP 以对 Tableau 的令牌进行身份验证和授权。Tableau 接收 openid 和刷新令牌。AWS 能够验证来自 IDP 的令牌和签名、从令牌中提取声明、查找声明到 IAM 角色的映射，以及允许或阻止 Tableau 代表用户承担角色。

[示例：AssumeRoleWithWebIdentity](https://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRoleWithWebIdentity.html)

![登录 athena 窗口](/tableau/current/zh-cn/pro/desktop/zh-cn/Img/athenaidp_signin.png)

## 令牌

默认情况下，Athena OAuth IAM 将 ID 令牌传递给驱动程序。对于本地客户（包括使用 Tableau Bridge 的客户），您可以改用 TDC 文件来传递访问令牌。

<connection-customization class='athena' enabled='true' version='10.0'>
    <vendor name='athena' />
    <driver name='athena' />
    <customizations>
        <customization name='CAP\_OAUTH\_FEDERATE\_ACCCESS\_TOKEN' value='yes'/>
    </customizations>
</connection-customization>

有关配置和安装 .tdc 文件的详细信息，请参见[自定义和调整连接](https://help.tableau.com/current/pro/desktop/zh-cn/connect_customize.htm)。

## Okta 配置

如果使用 Okta，最好使用“自定义授权服务器”而不是“组织授权服务器”。自定义授权服务器更加灵活。默认创建一个自定义授权服务器，称为“默认”。授权 URL 如以下示例所示：

`https://${yourOktaDomain}/oauth2/{authServerName}/v1/authorize`

![okta 仪表板](/tableau/current/zh-cn/pro/desktop/zh-cn/Img/athena_okta.png)