跳转至

User-attributed SAP writeback with OAuth 2.0(使用 OAuth 2.0 的用户属性 SAP 回写)

This page contains instructions for setting up the OAuth 2.0 server in SAP and setting up the OAuth 2.0 client in Foundry.

Setting up the OAuth 2.0 server in SAP

Prerequisites

  • SP21 or above of the Palantir Foundry Connector 2.0 for SAP Applications ("Connector")
  • The Foundry technical user in SAP should be a SYSTEM user
  • /PALANTIR/OAUTH_CLIENT should be assigned to the Foundry technical user and any end users wishing to write back to SAP from Foundry
  • /PALANTIR/CONTENT_FUNCTION_ALL should be assigned to end user
  • All services under the /sap/public/bc node to be activated (for OAuth 2.0 configuration)
  • /sap/bc/sec/oauth2*
  • /default_host/sap/bc/webdynpro/sap/oauth2_authority
  • SAP Gateway is active
  • SAP_BASIS (the technical component version, applicable to both SAP NetWeaver and SAP S/4HANA systems) 7.4 SP09 or above (support for OAuth 2.0 and OData)

Reference

OAuth 2.0 configuration

  1. Run the SOAUTH2 transaction.
  2. Select Create....
  3. Enter the username of the Foundry technical user as the OAuth 2.0 Client ID.
  4. Select Next >.
  5. Enter the username of the Foundry technical user as the User ID.
  6. Ensure Client User ID and Password and SSL Client Certificate are both checked.
  7. Select Next >.
  8. Set the Redirect URI as https://<FOUNDRY_DOMAIN>/workspace/oauth2-clients/callback.
  9. Select Next >.
  10. Add a Scope Assignment with an OAuth 2.0 Scope ID of /PALANTIR/SRV_0001 and a description such as Palantir Foundry writeback using SAP functions.
  11. Select Next > and then Finish.

OData configuration

  1. In the Maintain service page within SAP, follow the hierarchy of services to find opu > odata > palantir.
  2. Right-click on palantir and select Activate Service.
  3. Select Yes when prompted.
  4. On the Create/Change a Service tab, select GUI Configuration under Interactive Options.
  5. Add parameter with name ~CHECK_CSRF_TOKEN and value 0 (zero).
  6. Disable CSRF_TOKEN validation as outlined here: https://help.sap.com/doc/saphelp_hba/1.0/de-DE/e6/cae27d5e8d4996add4067280c8714e/content.htm
  7. Run the /IWFND/MAINT_SERVICE transaction.
  8. Select Add System Alias under System Aliases.
  9. Add a system alias with the following values:
  10. Service Doc. Identifier: /PALANTIR/SRV_0001
  11. User Role: blank
  12. Host Name: blank
  13. SAP System Alias: LOCAL
  14. Metadata Default: unchecked
  15. Default System: checked
  16. Tech. Svc. Name: /PALANTIR/SRV
  17. Ext. Service Name: ODATA_SRV
  18. Version: 1
  19. User Name: blank

Setting up the OAuth 2.0 client in Foundry

This follows the general approach outlined in Configure outbound applications but has been tailored specifically to SAP systems.

Outbound application setup

  1. Navigate to Control Panel and select Outbound applications under Organization settings.
  2. Select New application.
  3. Provide an Application name, for example, the name of your SAP system.
  4. Set the Approval prompt to describe the authorization action, for example, Allow Foundry to act on your behalf in SAP?.
  5. Under OAuth 2.0 server connection, select the Foundry Worker option.
  6. Set the Authorization page URL to the SAP OAuth 2.0 authorization endpoint:
https://<SAP_DOMAIN>/sap/bc/sec/oauth2/authorize
  1. Set the Token endpoint URL to the SAP OAuth 2.0 token endpoint:
https://<SAP_DOMAIN>/sap/bc/sec/oauth2/token
  1. Under Egress policy, select an agent proxy egress policy that routes traffic through a Data Connection agent installed in your network with access to the SAP system.

An outbound application configured with the Foundry Worker option, SAP authorization and token endpoint URLs, and an agent proxy egress policy.

  1. Under OAuth 2.0 settings, set the Client ID to the client ID from the SAP OAuth 2.0 server configuration. Under Scopes, add /PALANTIR/SRV_0001.
  2. Save the outbound application.
  3. This outbound application can now be used when creating an SAP webhook.

For more details on outbound application configuration options, see Configure outbound applications.

(Legacy) Webhook-based OAuth 2.0 configuration

:::callout{theme="warning" title="Legacy"} The webhook-based OAuth 2.0 configuration described below is in the legacy phase of development and no additional development is expected. Use the standard outbound application setup above instead. For more information on the legacy approach, see (Legacy) Custom webhook-based OAuth 2.0 handshakes. :::

Previously, configuring OAuth 2.0 for SAP required creating a dedicated REST API source with webhooks to handle the token and refresh flows manually. If your existing SAP integration uses this approach, it will continue to work. However, for new configurations, use the standard outbound application setup above.

Source connection setup

:::callout{theme="warning" title="Warning"} Ensure that the SAP source URL is using HTTPS, or webhooks will fail when using an OAuth flow. :::

  1. Create a new REST API source.

Create REST API source

  1. Configure the source with the base domain URL and port used for the SAP source.
  2. Select Basic authentication and add the username and password used to connect to SAP.

Configure REST API source

  1. Save the source.

OAuth 2.0 authorization flow webhook setup

:::callout{theme="warning" title="Webhooks published as functions are incompatible"} Webhooks published as functions cannot be used in legacy custom webhook-based OAuth 2.0 outbound applications. When creating your token and refresh webhooks, ensure function publishing is disabled. :::

  1. On the overview page of the new REST API source, select Create webhook.

  2. Give the webhook a name (such as SAP OAuth2 authorization code flow webhook). Ensure that Function Configuration is toggled off.

  3. Advance to the Request configuration step.

  4. Under Calls, select POST as the request type and enter sap/bc/sec/oauth2/token as the path.

  5. Under Query Params, sap-client might have to be set if the client used is not the default client.

Webhook calls

  1. Scroll down to Input Parameters and add the following three parameters (all string type):

  2. redirect_uri

  3. client_id
  4. authorization_code

Webhook input parameters

  1. Scroll back up to Calls and select the Body tab.
  2. Choose Form URL Encoded and add the following four entries:

  3. grant_typeauthorization_code

  4. redirect_uri → Mapped to the redirect_uri input parameter (see below for how to do this)
  5. client_id → Mapped to the client_id input parameter
  6. code → Mapped to the authorization_code input parameter

  7. To map an input parameter, type @ into the field and then select Input Parameter. Find the relevant parameter, select it and then select Add beneath.

Input parameter mappings

  1. The finished Body configuration should look like this:

Webhook body

  1. Advance to the Responses step.
  2. Create the following five Output Parameters. All should be of type string and should be extracted by key from the response.

  3. access_token

  4. token_type
  5. expires_in
  6. refresh_token
  7. scope

This is an example for creating access_token. All output parameters should follow this pattern.

Webhook output parameter

  1. Save the webhook by selecting Create webhook and continue.

OAuth 2.0 refresh flow webhook setup

  1. Create a new webhook from the REST API source.
  2. Give the webhook a distinct name (such as SAP OAuth2 refresh flow webhook). Ensure that Function Configuration is toggled off.
  3. The request method should again be set to POST and the same path (sap/bc/sec/oauth2/token ) should be used.
  4. As with the previous webhook, set sap-client as a Query Param if needed.
  5. On the Headers tab, add the following header:

  6. Content-Typeapplication/x-www-form-urlencoded

Refresh webhook header

  1. Set up these two Input Parameters (both strings):

  2. client_id

  3. refresh_token

  4. Then under the Body tab, add these three entries:

  5. grant_typerefresh_token

  6. client_id → Mapped to the client_id input parameter
  7. refresh_token → Mapped to the refresh_token input parameter Refresh webhook body

  8. Create exactly the same five Output Parameters as for the authorization code flow webhook. All should be of type string and should be extracted by key from the response.

  9. access_token

  10. token_type
  11. expires_in
  12. refresh_token
  13. scope

  14. Save the webhook by selecting Create webhook and continue.

Legacy outbound application setup

  1. Navigate to the Foundry Control Panel and select Outbound applications.
  2. Give the application a name then follow the steps outlined under (Legacy) Custom webhook-based OAuth 2.0 handshakes.
  3. The two webhooks created earlier should be used as the Token webhook and Refresh token webhook respectively.
  4. The Authorization page URL should be of the form:
https://<SAP_DOMAIN>/sap/bc/sec/oauth2/authorize
  1. Under OAuth 2.0 settings, the Client ID should be set to the client ID from the SAP OAuth 2.0 server configuration. Under Scopes, add /PALANTIR/SRV_0001.
  2. Save the outbound application.
  3. This outbound application can now be used when creating an SAP webhook.

中文翻译


使用 OAuth 2.0 的用户属性 SAP 回写

本文包含在 SAP 中设置 OAuth 2.0 服务器和在 Foundry 中设置 OAuth 2.0 客户端的说明。

在 SAP 中设置 OAuth 2.0 服务器

前提条件

  • Palantir Foundry Connector 2.0 for SAP Applications("连接器")需为 SP21 或更高版本
  • SAP 中的 Foundry 技术用户应为 SYSTEM 用户
  • /PALANTIR/OAUTH_CLIENT 应分配给 Foundry 技术用户以及任何希望从 Foundry 回写到 SAP 的最终用户
  • /PALANTIR/CONTENT_FUNCTION_ALL 应分配给最终用户
  • 需激活 /sap/public/bc 节点下的所有服务(用于 OAuth 2.0 配置)
  • /sap/bc/sec/oauth2*
  • /default_host/sap/bc/webdynpro/sap/oauth2_authority
  • SAP Gateway 处于活动状态
  • SAP_BASIS(技术组件版本,适用于 SAP NetWeaver 和 SAP S/4HANA 系统)需为 7.4 SP09 或更高版本(支持 OAuth 2.0 和 OData)

参考

OAuth 2.0 配置

  1. 运行 SOAUTH2 事务。
  2. 选择 创建...
  3. 将 Foundry 技术用户的用户名输入为 OAuth 2.0 客户端 ID
  4. 选择 下一步 >
  5. 将 Foundry 技术用户的用户名输入为 用户 ID
  6. 确保 客户端用户 ID 和密码SSL 客户端证书 均已勾选。
  7. 选择 下一步 >
  8. 重定向 URI 设置为 https://<FOUNDRY_DOMAIN>/workspace/oauth2-clients/callback
  9. 选择 下一步 >
  10. 添加一个 范围分配,其 OAuth 2.0 范围 ID/PALANTIR/SRV_0001,描述为 使用 SAP 功能的 Palantir Foundry 回写
  11. 选择 下一步 >,然后选择 完成

OData 配置

  1. 在 SAP 的 维护服务 页面中,按照服务层级找到 opu > odata > palantir
  2. 右键单击 palantir,然后选择 激活服务
  3. 出现提示时选择
  4. 创建/更改服务 选项卡中,选择 交互选项 下的 GUI 配置
  5. 添加参数,名称为 ~CHECK_CSRF_TOKEN,值为 0(零)。
  6. 按照此处概述禁用 CSRF_TOKEN 验证:https://help.sap.com/doc/saphelp_hba/1.0/de-DE/e6/cae27d5e8d4996add4067280c8714e/content.htm
  7. 运行 /IWFND/MAINT_SERVICE 事务。
  8. 系统别名 下选择 添加系统别名
  9. 添加一个具有以下值的系统别名:
  10. 服务文档标识符: /PALANTIR/SRV_0001
  11. 用户角色: 留空
  12. 主机名: 留空
  13. SAP 系统别名: LOCAL
  14. 元数据默认: 未勾选
  15. 默认系统: 已勾选
  16. 技术服务名称: /PALANTIR/SRV
  17. 外部服务名称: ODATA_SRV
  18. 版本: 1
  19. 用户名: 留空

在 Foundry 中设置 OAuth 2.0 客户端

这遵循 配置出站应用程序 中概述的通用方法,但专门针对 SAP 系统进行了定制。

出站应用程序设置

  1. 导航到控制面板,在 组织设置 下选择 出站应用程序
  2. 选择 新建应用程序
  3. 提供一个 应用程序名称,例如您的 SAP 系统名称。
  4. 设置 批准提示 以描述授权操作,例如 允许 Foundry 代表您在 SAP 中执行操作?
  5. OAuth 2.0 服务器连接 下,选择 Foundry Worker 选项。
  6. 授权页面 URL 设置为 SAP OAuth 2.0 授权端点:
https://<SAP_DOMAIN>/sap/bc/sec/oauth2/authorize
  1. 令牌端点 URL 设置为 SAP OAuth 2.0 令牌端点:
https://<SAP_DOMAIN>/sap/bc/sec/oauth2/token
  1. 出口策略 下,选择一个 代理出口策略,该策略通过安装在您网络中并可访问 SAP 系统的 数据连接代理 路由流量。

一个配置了 Foundry Worker 选项、SAP 授权和令牌端点 URL 以及代理出口策略的出站应用程序。

  1. OAuth 2.0 设置 下,将 客户端 ID 设置为来自 SAP OAuth 2.0 服务器配置的客户端 ID。在 范围 下,添加 /PALANTIR/SRV_0001
  2. 保存出站应用程序。
  3. 现在可以在创建 SAP webhook 时使用此出站应用程序。

有关出站应用程序配置选项的更多详细信息,请参阅 配置出站应用程序

(旧版)基于 Webhook 的 OAuth 2.0 配置

:::callout{theme="warning" title="旧版"} 下面描述的基于 Webhook 的 OAuth 2.0 配置处于开发的 旧版 阶段,预计不会再有额外开发。请改用上述的 标准出站应用程序设置。有关旧版方法的更多信息,请参阅 (旧版)自定义基于 Webhook 的 OAuth 2.0 握手。 :::

以前,为 SAP 配置 OAuth 2.0 需要创建一个专用的 REST API 源,并带有 webhook 来手动处理令牌和刷新流程。如果您现有的 SAP 集成使用此方法,它将继续有效。但是,对于新配置,请使用上述的 标准出站应用程序设置

源连接设置

:::callout{theme="warning" title="警告"} 确保 SAP 源 URL 使用 HTTPS,否则在使用 OAuth 流程时 webhook 将失败。 :::

  1. 创建一个新的 REST API 源。

创建 REST API 源

  1. 使用用于 SAP 源的基础域名 URL 和端口配置该源。
  2. 选择 基本 认证,并添加用于连接到 SAP 的用户名和密码。

配置 REST API 源

  1. 保存该源。

OAuth 2.0 授权流程 Webhook 设置

:::callout{theme="warning" title="作为函数发布的 Webhook 不兼容"} 作为函数发布的 Webhook 不能用于旧版自定义基于 Webhook 的 OAuth 2.0 出站应用程序。创建令牌和刷新 webhook 时,请确保禁用函数发布。 :::

  1. 在新的 REST API 源的概览页面上,选择 创建 webhook

  2. 为 webhook 命名(例如 SAP OAuth2 authorization code flow webhook)。确保 函数配置 已关闭。

  3. 进入 请求配置 步骤。

  4. 调用 下,选择 POST 作为请求类型,并输入 sap/bc/sec/oauth2/token 作为路径。

  5. 查询参数 下,如果使用的客户端不是默认客户端,则可能需要设置 sap-client

Webhook 调用

  1. 向下滚动到 输入参数,并添加以下三个参数(均为字符串类型):

  2. redirect_uri

  3. client_id
  4. authorization_code

Webhook 输入参数

  1. 向上滚动回 调用,然后选择 主体 选项卡。
  2. 选择 表单 URL 编码,并添加以下四个条目:

  3. grant_typeauthorization_code

  4. redirect_uri → 映射到 redirect_uri 输入参数(请参阅下文了解如何操作)
  5. client_id → 映射到 client_id 输入参数
  6. code → 映射到 authorization_code 输入参数

  7. 要映射输入参数,请在字段中输入 @,然后选择 输入参数。找到相关参数,选择它,然后选择下方的 添加

输入参数映射

  1. 完成的 主体 配置应如下所示:

Webhook 主体

  1. 进入 响应 步骤。
  2. 创建以下五个 输出参数。所有参数都应为字符串类型,并通过键从响应中提取。

  3. access_token

  4. token_type
  5. expires_in
  6. refresh_token
  7. scope

这是创建 access_token 的示例。所有输出参数都应遵循此模式。

Webhook 输出参数

  1. 选择 创建 webhook 并继续 以保存 webhook。

OAuth 2.0 刷新流程 Webhook 设置

  1. REST API 源创建一个新的 webhook。
  2. 为 webhook 指定一个不同的名称(例如 SAP OAuth2 refresh flow webhook)。确保 函数配置 已关闭。
  3. 请求方法应再次设置为 POST,并使用相同的路径(sap/bc/sec/oauth2/token)。
  4. 与之前的 webhook 一样,如果需要,将 sap-client 设置为 查询参数
  5. 标头 选项卡上,添加以下标头:

  6. Content-Typeapplication/x-www-form-urlencoded

刷新 webhook 标头

  1. 设置这两个 输入参数(均为字符串):

  2. client_id

  3. refresh_token

  4. 然后在 主体 选项卡下,添加这三个条目:

  5. grant_typerefresh_token

  6. client_id → 映射到 client_id 输入参数
  7. refresh_token → 映射到 refresh_token 输入参数 刷新 webhook 主体

  8. 创建与授权码流程 webhook 完全相同的五个 输出参数。所有参数都应为字符串类型,并通过键从响应中提取。

  9. access_token

  10. token_type
  11. expires_in
  12. refresh_token
  13. scope

  14. 选择 创建 webhook 并继续 以保存 webhook。

旧版出站应用程序设置

  1. 导航到 Foundry 控制面板,然后选择 出站应用程序
  2. 为应用程序命名,然后按照 (旧版)自定义基于 Webhook 的 OAuth 2.0 握手 中概述的步骤操作。
  3. 之前创建的两个 webhook 应分别用作 令牌 webhook刷新令牌 webhook
  4. 授权页面 URL 的格式应为:
https://<SAP_DOMAIN>/sap/bc/sec/oauth2/authorize
  1. OAuth 2.0 设置 下,客户端 ID 应设置为来自 SAP OAuth 2.0 服务器配置的客户端 ID。在 范围 下,添加 /PALANTIR/SRV_0001
  2. 保存出站应用程序。
  3. 现在可以在创建 SAP webhook 时使用此出站应用程序。