在 Salesforce 中的何处存储授权不记名令牌?
Where to store a Authorization Bearer Token in Salesforce?
我们有一个外部供应商要求我们在与 API 通信时在 http 请求 header 中包含不记名令牌。此令牌不应未加密地留在代码中,那么存储它的最佳位置在哪里? Named Credential 类型似乎不支持存储简单令牌,而 Custom Setting 选项似乎过于复杂且不必要。这是一个单一的标记字符串,将用于每个 API 调用,无论哪个用户。我在 google 上进行了高低搜索,但没有找到明显有效的解决方案。
有一些选项,但它们仅限于您作为最终用户的代码。坚定的 developer/sysadmin 最终会学习到价值。
如果您要构建托管包,则可以使用受保护的自定义设置(托管包的代码可以看到它,但客户端代码甚至系统管理员都看不到)
检查其中一些:
- https://developer.salesforce.com/page/Secure_Coding_Storing_Secrets
- https://salesforce.stackexchange.com/questions/226110/what-is-the-best-way-of-storing-username-and-password-in-salesforce
- https://salesforce.stackexchange.com/questions/478/using-transient-keyword-to-store-password-in-hierarchy-custom-setting
- https://salesforce.stackexchange.com/questions/55008/is-encrypting-passwords-in-protected-custom-settings-a-security-requirement
您可以使用 2 个文本字段进行自定义设置,1 个带有加密密钥,1 个带有加密值。看看Cryptoclass.
Blob exampleIv = Blob.valueOf('Example of IV123');
Blob key = Crypto.generateAesKey(128);
Blob data = Blob.valueOf('Data to be encrypted');
Blob encrypted = Crypto.encrypt('AES128', key, exampleIv, data);
Blob decrypted = Crypto.decrypt('AES128', key, exampleIv, encrypted);
String decryptedString = decrypted.toString();
System.assertEquals('Data to be encrypted', decryptedString);
您的初始化向量可以是 org 的 id 或其他易于访问且不太可能更改的内容(我不知道您的供应商的 API 是否具有测试和生产端点,但这是在沙盒之后的额外好处刷新这将无法解密 OK,直到您更改自定义设置...您不想将测试消息发送到生产 API),您将生成一次密钥并将其存储在设置中。
我们有一个外部供应商要求我们在与 API 通信时在 http 请求 header 中包含不记名令牌。此令牌不应未加密地留在代码中,那么存储它的最佳位置在哪里? Named Credential 类型似乎不支持存储简单令牌,而 Custom Setting 选项似乎过于复杂且不必要。这是一个单一的标记字符串,将用于每个 API 调用,无论哪个用户。我在 google 上进行了高低搜索,但没有找到明显有效的解决方案。
有一些选项,但它们仅限于您作为最终用户的代码。坚定的 developer/sysadmin 最终会学习到价值。
如果您要构建托管包,则可以使用受保护的自定义设置(托管包的代码可以看到它,但客户端代码甚至系统管理员都看不到)
检查其中一些:
- https://developer.salesforce.com/page/Secure_Coding_Storing_Secrets
- https://salesforce.stackexchange.com/questions/226110/what-is-the-best-way-of-storing-username-and-password-in-salesforce
- https://salesforce.stackexchange.com/questions/478/using-transient-keyword-to-store-password-in-hierarchy-custom-setting
- https://salesforce.stackexchange.com/questions/55008/is-encrypting-passwords-in-protected-custom-settings-a-security-requirement
您可以使用 2 个文本字段进行自定义设置,1 个带有加密密钥,1 个带有加密值。看看Cryptoclass.
Blob exampleIv = Blob.valueOf('Example of IV123');
Blob key = Crypto.generateAesKey(128);
Blob data = Blob.valueOf('Data to be encrypted');
Blob encrypted = Crypto.encrypt('AES128', key, exampleIv, data);
Blob decrypted = Crypto.decrypt('AES128', key, exampleIv, encrypted);
String decryptedString = decrypted.toString();
System.assertEquals('Data to be encrypted', decryptedString);
您的初始化向量可以是 org 的 id 或其他易于访问且不太可能更改的内容(我不知道您的供应商的 API 是否具有测试和生产端点,但这是在沙盒之后的额外好处刷新这将无法解密 OK,直到您更改自定义设置...您不想将测试消息发送到生产 API),您将生成一次密钥并将其存储在设置中。