gpt4 book ai didi

go - 无法从 IDP 创建 SAML 响应

转载 作者:行者123 更新时间:2023-12-02 02:52:38 25 4
gpt4 key购买 nike

我必须为 Salesforce 创建单点登录 (SSO)。为了进行授权,我将使用用户的手机号码和 OTP。我只需在验证 OTP 后使用 Go 创建 SAML 响应。

我可以看到有几个库可以实现 go-saml , gosaml , go-oauthgoauth Go 编程语言,但即使经过几个小时的搜索,我也无法决定哪一种适合我。我不必实现完整的 IDP,我只需动态创建 SAML 响应。

我找到了需要从 https://www.samltool.com/generic_sso_res.php 创建的 XML 响应模板。所以我必须创建如下所示的 SAML 响应:-

<?xml version="1.0" encoding="UTF-8"?>
<saml1p:Response xmlns:saml1p="urn:oasis:names:tc:SAML:1.0:protocol" IssueInstant="2020-02-26T17:32:05.200Z" MajorVersion="1" MinorVersion="1" Recipient="https://im--partial.my.salesforce.com" ResponseID="_34ae7ce8-5f7fbd4d">
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<ds:SignedInfo>
<ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
<ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#dsa-sha1"/>
<ds:Reference URI="#_34ae7ce8-5f7fbd4d">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
<ds:DigestValue>fxk4drd6yhVQrJCtdfvYOyYYGAM=</ds:DigestValue>
</ds:Reference>
</ds:SignedInfo>
<ds:SignatureValue>EsjQYhFsL+Xvcgg59AkZja....8INZrTwyfLmo4+NMyYViDX6Q==</ds:SignatureValue>
<ds:KeyInfo>
<ds:X509Data>
<ds:X509Certificate>MIID0zCCA5GgAwIBAgIEF...XWlGzJ3SdBlgRsdFgKyFtcxE=</ds:X509Certificate>
</ds:X509Data>
</ds:KeyInfo>
</ds:Signature>
<saml1p:Status>
<saml1p:StatusCode Value="saml1p:Success"/>
</saml1p:Status>
<saml1:Assertion xmlns:saml1="urn:oasis:names:tc:SAML:1.0:assertion" AssertionID="_7f959448-5dbf311f" IssueInstant="2020-02-26T17:32:05.200Z" Issuer="AXIOM" MajorVersion="1" MinorVersion="1">
<saml1:Conditions NotBefore="2020-02-26T17:32:05.199Z" NotOnOrAfter="2020-02-26T17:33:05.199Z">
<saml1:AudienceRestrictionCondition>
<saml1:Audience>https://saml.salesforce.com</saml1:Audience>
</saml1:AudienceRestrictionCondition>
</saml1:Conditions>
<saml1:AuthenticationStatement AuthenticationInstant="2020-02-26T17:32:05.199Z" AuthenticationMethod="urn:oasis:names:tc:SAML:1.0:am:unspecified">
<saml1:Subject>
<saml1:NameIdentifier>rahul.satal@xyz.com</saml1:NameIdentifier>
<saml1:SubjectConfirmation>
<saml1:ConfirmationMethod>urn:oasis:names:tc:SAML:1.0:cm:bearer</saml1:ConfirmationMethod>
</saml1:SubjectConfirmation>
</saml1:Subject>
</saml1:AuthenticationStatement>
</saml1:Assertion>
</saml1p:Response>

其中我只需要更新几个参数,例如 Assertion_Id、Issertion_Id、Issuer、Audience、Recipient、Subject、Not before/After date、Attribute statements 等。我不确定是否需要任何库或可以获得一个单个脚本。

最佳答案

This library似乎是一个简单的 Go 的 SAML 库,负责生成 SAML Response 以及对该 Response 进行签名.

我还看到过使用"template"完成此操作,但实际上并未完成任何 SAML 处理。打开准备好的带有占位符的文本 block ,将占位符替换为所需的文本并发送响应。

saml1p:Response

可以是在运行时创建的带有 IssueInstantResponseID 的模板。例如伪代码将是:

String samlTemplate = loadSAMLTemplate()
.gsub("__IssueInstant__", "2020-02-26T17:32:05.200Z")
.gsub("__ResponseID__", "9421878f98")
.gsub( ... and so on ...)

即使不理想,也可以这样做,并且只有在只有一个断言时才有效。

您可以使用上面的模板并用占位符替换可替换的部分,例如

<saml1p:Response
xmlns:saml1p="urn:oasis:names:tc:SAML:1.0:protocol"
IssueInstant="__IssueInstant__"
MajorVersion="1"
MinorVersion="1"
Recipient="https://im--partial.my.salesforce.com"
ResponseID="__ResponseID__">

构建XML SAML 响应。您将拥有用于 AssertionID 等的占位符。任何需要每个 SAML 唯一的内容 Response 都需要一个占位符,其内容在运行时替换.

然后您需要签署该响应。你不能通过更换东西来做到这一点。您只能通过使用 XML 签名进行数字签名来完成此操作。您可以使用 this library要做到这一点。它仍在对响应进行编码,但您只需使用签名,而不是整个SAML流程。

所以工作流程是:

  • 创建可重复使用的 SAML Response 作为文本模板,并为每个可替换文本添加 PlaceHolders
  • 加载模板,替换所有需要替换的位。这是您的 SAML 响应
  • 使用 XML 签名库对 SAML 响应 进行签名。这是您发送给 SP 的内容。

关于go - 无法从 IDP 创建 SAML 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60430587/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com