SAML认证-Web UI方式
合作伙伴销售平台与华为云进行SAML认证的流程如图1所示:

1. 合作伙伴客户通过浏览器调用华为云登录链接,IAM发起samlRequest请求。
- a. 合作伙伴客户通过浏览器调用华为云登录链接(https://auth.huaweicloud.com/authui/saml/login?xAccountType=ZXT&isFirstLogin=false&service=https%3a%2f%2fconsole.huaweicloud.com%2fiam%2f)
参数 |
是否必填 |
说明 |
示例 |
xAccountType |
是 |
合作伙伴销售平台标识,全局唯一。该标识的具体值由华为分配。合作伙伴在合作伙伴中心完成接入配置后,即可生成该标识。获取方法请参见如何获取xaccountType的取值 。 |
ZXT |
isFirstLogin |
否 |
未绑定华为云账号,此参数必填且为true,其他可不填或为false。<br>成功调用“创建客户”接口后,华为云CBC已经将合作伙伴客户的合作伙伴销售平台账号和华为云账号进行了绑定。 |
false |
service |
是 |
登录后的跳转地址。<br>需要使用encodeURIComponent编码。 |
https%3a%2f%2fconsole.huaweicloud.com%2fiam%2f |
- b. IAM服务收到合作伙伴客户的登录请求, 根据xAccountType的取值, 查找对应IDP Metadata.xml配置, 找出SingleSignOnService配置项,向此路径发送samlRequest请求。
![samlRequest请求 图2: samlRequest请求]()
参数 |
描述 |
SAMLRequest |
返回消息体。<br>此消息为应答xml,IAM对此请求进行了“压缩 > base64加密 > url编码”。<br> 如果合作伙伴使用SAML库,可直接使用此参数值,不必完全解出xml。<br> 如果合作伙伴想解出xml,需要进行“解url > 解base64 > 解压缩(zip.inflate)”,可参考解出SAMLRequest的代码示例 。 |
RelayState |
SAML协议返回参数。 |
SigAlg |
签名使用的签名算法(华为默认使用SHA256算法进行签名)。<br>HTTP://WWW.W3.ORG/2001/04/XMLDSIG-MORE#RSA-SHA256 |
Signature |
签名值。通过签名机制来验证请求的发起方。<br>华为云发起请求时将请求https://www.test.com/saml/login?SAMLRequest={SAMLRequest }&RelayState={ RelayState} &SigAlg={ SigAlg}&Signature={ Signature }中的“SAMLRequest={ SAMLRequest }&RelayState={ RelayState } &SigAlg={ SigAlg }”使用私钥签名(签名算法为SigAlg字段指定的算法),之后再做一次Base64编码作为签名值。<br>接收方收到请求后通过华为云提供的公钥(SP Metadata.xml文件中<ds:X509Certificate></ds:X509Certificate>标签内的值)来验证签名。签名验证通过,则表明是华为云发送的请求可以进行后续操作,否则请求非法。 |
2. 合作伙伴销售平台生成samlResponse,并返回给华为云IAM。
Copied!
<?xml version="1.0" encoding="UTF-8"?>
<saml2p:Response Consent="urn:oasis:names:tc:SAML:2.0:consent:unspecified" ID="_d794dc393ae6724e236003bf0b917cf0" Destination=” https://auth.huaweicloud.com/authui/saml/SAMLAssertionConsumer”InResponseTo="_dck4mm08qmdhc8k4nuir07hghetdqqg8umg5" IssueInstant="2018-10-30T08:21:41.740Z" Version="2.0"
xmlns:saml2p="urn:oasis:names:tc:SAML:2.0:protocol">
<saml2:Issuer Format="urn:oasis:names:tc:SAML:2.0:nameid-format:entity"
xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion">https://www.test.com</saml2:Issuer>
<saml2p:Status>
<saml2p:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success" />
<saml2p:StatusMessage>urn:oasis:names:tc:SAML:2.0:status:Success</saml2p:StatusMessage>
</saml2p:Status>
<saml2:Assertion ID="_2320c40ac7b5e857b2d0d4ea0c8758c3" IssueInstant="2018-10-30T08:21:41.740Z" Version="2.0"
xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<saml2:Issuer>https://www.test.com</saml2:Issuer>
<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/2001/04/xmldsig-more#rsa-sha256" />
<ds:Reference URI="#_2320c40ac7b5e857b2d0d4ea0c8758c3">
<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#">
<ec:InclusiveNamespaces PrefixList="xsd"
xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" />
</ds:Transform>
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256" />
<ds:DigestValue>rFxrycznfGNYOnprZIFJJou4ro0Mz65+43MIR5F0+H4=</ds:DigestValue>
</ds:Reference>
</ds:SignedInfo>
<ds:SignatureValue>
YqTWQngAPfGqQmWa610PM7LeefqWdKuveUVINrqL67NoHJIDa2WxLwdVzoJIlJh64QiNPr6+ndmL DCMgIC5F/9ijuzhIICZcc6lHNIjy6EsPkKRjfo9oeoVAqLgG/kmVQYeHLBID0y11RNXXpAVY4nhJ 26KiIVGt7ywyKAmhichE+eW/UYAGiOI5vkfgD2gZUGV+yPkv64k7xK4yAH3mL2NaCPuw/90e4enm iUx0YuazDwM5FiRUSMpcJs0rcNmS6clWAUcCzbOx+y2vJGtTjHb7k3UsmpnTop5eYNp94+sDPEat 8FaV4SgafMEL5z54gpe8+//9yOWEvlBs1b0RYg==
</ds:SignatureValue>
<ds:KeyInfo>
<ds:X509Data>
<ds:X509Certificate>
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAhK3L160NjP9EhBGQOC2s4r+Wc62bkRkc nUxfhiZwCwJdQCykzuLOAoATnfoEamV5W25xtSS5kFs+4OC0mYVpKcI3SWoydX+UE5Qik5UfJ8Dt G1AvSEKhSluyO9axrV5Uv089jMxBnlm/R+xND73WcZM11yIbKJEZSTCEDfh+KnFbMw108umFMden RZCrNWUJoSp/90XeG0V2Nmj7Fkq72skSifwIASLRq9KqLbmh1QwUX+AoWpHK/jRUBustMBmG1n1i
AqpD4EBjjBOB27k1wXZ30+IoJt8IZmfSZRFoNn5VFWXNeEmZ1aQvGSvd3Tyyw2/Wr+w/8Mags69C mpeX6QIDAQAB
</ds:X509Certificate>
</ds:X509Data>
</ds:KeyInfo>
</ds:Signature>
<saml2:Subject>
<saml2:NameID Format="urn:oasis:names:tc:SAML:2.0:nameid-format:transient" NameQualifier="https://auth.huaweicloud.com/">Some NameID value</saml2:NameID>
<saml2:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer">
<saml2:SubjectConfirmationData InResponseTo="_dck4mm08qmdhc8k4nuir07hghetdqqg8umg5" NotBefore="2018-10-28T08:21:41.740Z" NotOnOrAfter="2018-11-01T08:21:41.740Z" Recipient="https://auth.huaweicloud.com/authui/saml/SAMLAssertionConsumer" />
</saml2:SubjectConfirmation>
</saml2:Subject>
<saml2:Conditions NotBefore="2018-10-28T08:21:41.740Z" NotOnOrAfter="2018-11-01T08:21:41.740Z">
<saml2:AudienceRestriction>
<saml2:Audience>https://auth.huaweicloud.com/</saml2:Audience>
</saml2:AudienceRestriction>
</saml2:Conditions>
<saml2:AttributeStatement>
<saml2:Attribute FriendlyName="xUserId" Name="xUserId" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri">
<saml2:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xsd:string">*******</saml2:AttributeValue>
</saml2:Attribute>
<saml2:Attribute FriendlyName="xAccountId" Name="xAccountId" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri">
<saml2:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xsd:string">********</saml2:AttributeValue>
</saml2:Attribute>
<saml2:Attribute FriendlyName="bpId" Name="bpId" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri">
<saml2:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xsd:string">******</saml2:AttributeValue>
</saml2:Attribute>
<saml2:Attribute FriendlyName="email" Name="email" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri">
<saml2:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xsd:string" />
</saml2:Attribute>
<saml2:Attribute FriendlyName="name" Name="name" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri">
<saml2:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xsd:string">******</saml2:AttributeValue>
</saml2:Attribute>
<saml2:Attribute FriendlyName="mobile" Name="mobile" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri">
<saml2:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xsd:string">*****</saml2:AttributeValue>
</saml2:Attribute>
</saml2:AttributeStatement>
<saml2:AuthnStatement AuthnInstant="2018-10-30T08:21:41.741Z">
<saml2:SubjectLocality Address="https://auth.huaweicloud.com/" />
<saml2:AuthnContext>
<saml2:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:unspecified</saml2:AuthnContextClassRef>
</saml2:AuthnContext>
</saml2:AuthnStatement>
</saml2:Assertion>
</saml2p:Response>
合作伙伴签名值使用标准的XML签名方式,签名类型为enveloped-signature。建议优先使用第三方提供的SAML库进行签名。
签名步骤如下:
- 获取签名对象 (Assertion)
Copied!
<saml2:Assertion ID="_2320c40ac7b5e857b2d0d4ea0c8758c3" IssueInstant="2018-10-30T08:21:41.740Z" Version="2.0"
xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
......
</saml2:Assertion>
```
2. 获取标签对象 (Signature)
<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#rsa-sha256" />
<ds:Reference URI="#_2320c40ac7b5e857b2d0d4ea0c8758c3">
<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#">
<ec:InclusiveNamespaces
xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#"
PrefixList="xs" />
</ds:Transform>
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
<ds:DigestValue>......</ds:DigestValue>
</ds:Reference>
</ds:SignedInfo>
<ds:SignatureValue>
......
</ds:SignatureValue>
<ds:KeyInfo>
<ds:X509Data>
<ds:X509Certificate>
......
</ds:X509Certificate>
</ds:X509Data>
</ds:KeyInfo>
</ds:Signature>
```
- 对签名对象Assertion生成“DigestValue”摘要值
- 对Assertion按照Signature的Transform子标签中的算法进行标准化转换;
- 将1)转换后的对象按照DigestMethod中的算法生成摘要;
- 将生成的摘要值放在DigestValue标签中。
4. 使用生成证书中步骤6的私钥对SignedInfo对象签名生成“SignatureValue”值
1. 对SignedInfo按照 CanonicalizationMethod 中的算法进行标准化转换;
2. 将1)转换后的对象按照SignatureMethod中的签名算法进行签名,签名值放在SignatureValue中
5. 将 “DigestValue”和“SignatureValue”值组成最终的Signature对象,将Signature放置于Assertion对象中,作为其子元素。
签名后的屏显如下:
Copied!
<saml2:Assertion ID="_2320c40ac7b5e857b2d0d4ea0c8758c3" IssueInstant="2018-10-30T08:21:41.740Z" Version="2.0"
xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
......
<ds:Signature
xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
......
<ds:SignatureValue>
......
</ds:SignatureValue>
<ds:KeyInfo>
<ds:X509Data>
<ds:X509Certificate>
......
</ds:X509Certificate>
</ds:X509Data>
</ds:KeyInfo>
</ds:Signature>
</saml2:Assertion>
- <saml2:AttributeValue></saml2:AttributeValue>之间的取值说明
参数 |
描述 |
xUserId |
合作伙伴客户在合作伙伴销售平台的用户ID,即xAccountId的取值。 |
xAccountId |
合作伙伴客户在合作伙伴销售平台的账号ID。 |
bpId |
如果客户需要关联至经销商伙伴或华为云伙伴能力中心(一级经销商),则此处需填写经销商伙伴或华为云伙伴能力中心的伙伴ID,获取方法请参见如何获取合作伙伴ID(partner_id)。如果客户需要关联至精英服务商(二级经销商),则此处需填写精英服务商的伙伴ID,获取方法请参见查询精英服务商列表。 |
email |
邮箱内容。<br>内容非必填。<br>校验规则:<br>客户间判重。<br>最大长度:64<br>使用正则表达式校验:"^[azA-Z0-9.!#$%&'+\\/=?^_`{/}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[azA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)$" |
name |
合作伙伴销售平台传递的客户名称。<br>内容非必填。<br>请与“创建客户 "接口请求参数中的“domain_name”取值保持一致。 |
mobile |
手机号码,格式为“国家码-手机号码”。<br>内容非必填。<br>手机号码请与“创建客户”接口请求参数中的“mobile_phone”保持一致。 |
说明 : |
|
-
表1中有账号ID和用户ID的定义是因为华为云IAM有账号和用户的概念。关于两个概念的具体介绍请参见身份管理 中的“账号”和“IAM用户”的描述。
-
c. 如果客户已在合作伙伴销售平台登录,则直接返回samlResponse消息。如果未登录,则登录后返回samlResponse消息。向2.a中华为云应答路径AssertionConsumerService发送POST请求,参数使用Form Data形式。
![samlResponse请求 图3: samlResponse请求]()
参数 |
描述 |
SAMLResponse |
2.b中samlResponse返回体经过base64加密后的字符串。 |
RelayState |
samlRequest中相同参数值。 |
3. IAM解析SAMLResponse。由于在调用“创建客户”接口时,华为云CBC将客户在合作伙伴销售平台上的账号与华为云账号进行了绑定,所以此时可直接登录到service重定向的页面,完成云服务的购买和管理。
版本说明
本示例不涉及SDK示例代码。
功能介绍
客户在伙伴销售平台登录后,可以直接跳转到华为云完成云服务购买、云服务资源管理等。伙伴销售平台需完成SAML认证,与华为云建立信任关系。
前提条件
SAML认证-Web UI方式
合作伙伴销售平台与华为云进行SAML认证的流程如图1所示:
1. 合作伙伴客户通过浏览器调用华为云登录链接,IAM发起samlRequest请求。
2. 合作伙伴销售平台生成samlResponse,并返回给华为云IAM。
a. 合作伙伴销售平台读取SP Metadata.xml文件获取华为云公钥及samlResponse返回路径。具体请参见获取SP Metadata.xml 中“示例及公钥、应答路径说明”的说明。
b. 合作伙伴销售平台构建samlResponse返回体。 此返回体为xml格式,正确返回体及参数说明请参见如下内容。
须知
:合作伙伴签名值使用标准的XML签名方式,签名类型为enveloped-signature。建议优先使用第三方提供的SAML库进行签名。
签名步骤如下:
签名后的屏显如下:
说明
:表1中有账号ID和用户ID的定义是因为华为云IAM有账号和用户的概念。关于两个概念的具体介绍请参见身份管理 中的“账号”和“IAM用户”的描述。
c. 如果客户已在合作伙伴销售平台登录,则直接返回samlResponse消息。如果未登录,则登录后返回samlResponse消息。向2.a中华为云应答路径AssertionConsumerService发送POST请求,参数使用Form Data形式。
3. IAM解析SAMLResponse。由于在调用“创建客户”接口时,华为云CBC将客户在合作伙伴销售平台上的账号与华为云账号进行了绑定,所以此时可直接登录到service重定向的页面,完成云服务的购买和管理。
参考
更多信息请参考合作伙伴中心
修订记录