SAML 2.0 SSO 登录配置
SAML 2.0工作流程
提供SP Metadata给IDP
SP指的是程序方,IDP是指SAML server方
The SP Metadata build on sp_metadata
一般情况下只需要输入EntityId 和ACS url就行了
<?xml version="1.0"?>
<md:EntityDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata"
validUntil="2023-09-13T09:33:35Z"
cacheDuration="PT604800S"
entityID="UAT">
<md:SPSSODescriptor AuthnRequestsSigned="false" WantAssertionsSigned="false" protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol">
<md:NameIDFormat>urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified</md:NameIDFormat>
<md:AssertionConsumerService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"
Location="http://uat:8088/api/v1/SSO/AuthBack"
index="1" />
</md:SPSSODescriptor>
</md:EntityDescriptor>
需要客户提供SAML 2.0的登录URL : https://client.com/openam/saml2/jsp/idpSSOInit.jsp?metaAlias=/qa/username&spEntityID=UAT
SAMLResponse
ACS url(一个sso回调URL)接收到samlresponse,需要对response进行解析
<samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" ID="s27d01aa107fdb40dfa34dab********" Version="2.0" IssueInstant="2022-07-13T15:49:34Z" Destination="http://uat:8088/api/v1/SSO/AuthBack">
<saml:Issuer xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">qa_elc_am</saml:Issuer>
<samlp:Status xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol">
<samlp:StatusCode xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" Value="urn:oasis:names:tc:SAML:2.0:status:Success"></samlp:StatusCode>
</samlp:Status>
<saml:Assertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" ID="#s2b83995a1e811***********" IssueInstant="2022-07-13T15:49:34Z" Version="2.0">
<saml:Issuer>username</saml: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:CanonicalizationMethod>
<ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"></ds:SignatureMethod>
<ds:Reference URI="#s2b83995a1e811***********">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"></ds:Transform>
<ds:Transform Algorithm="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:DigestMethod>
<ds:DigestValue>KgQ9OoB3a+meUL0BUHCLk7f*********QcgdI=</ds:DigestValue>
</ds:Reference>
</ds:SignedInfo>
<ds:SignatureValue>bEyN7IAzChrcZys7p2M7UEuw000BIrxESpIezAtRwmo4I9AeW3Xg6*********************UKJAodORojah4iCutMqR9MX3c891v8Oy5aNeIl3p0Vobk8Z3jQyByK++d271nTEYik6tUEygflzrU8ePpi6gp6bsvDAt7AA2apqlnxc4TpRMoqTygnOrXjHct1HwBY/lZSqpfw+LK6Cp0TDReE1rUdfACjbTpntnkOABFWPTWrtcMu5zs3gG9BSeSqLE98E40yGKbXmId6pWLQ==</ds:SignatureValue>
<ds:KeyInfo>
<ds:X509Data>
<ds:X509Certificate>MIIHvTCCBaWgAwIBAgITWgADj/nUWNXtKxLBugAAAAOP+TANBgkqhkiG9********************ElMCMGA1UEAxMcRVNURUUtRU5URVJQUklTRS1JU1NVSU5HLUNBMTAeFw0yMjA2MDE***********aMIGlMQswCQYDVQQGEwJVUzEQMA4GA1UECBMHTmV3WW9yazEQMA4GA1UEBxMHTmV3WW9yazEUMBIGA1UEChMLRUxDb21wYW5pZXMxLjAsBgNVBAMTJWlhbS1xYS1lbGNzYW1sanVuMjRxYS5lbGNvbXBhbmllcy5jb20xLDAqBgkqhkiG9w0BCQEWHUVMQy1XaXByby1Gb3JnZVJvY2tAZXN0ZWUuY29tMIIBIjANBgkqhkiG9w0B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gsCuZ6L+rWBJBFfg3G5yWM=</ds:X509Certificate>
</ds:X509Data>
</ds:KeyInfo>
</ds:Signature>
<saml:Subject>
<saml:NameID Format="urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified" NameQualifier="qa_elc_am" SPNameQualifier="HBS_UAT">akolanup@estee.com</saml:NameID>
<saml:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer">
<saml:SubjectConfirmationData NotOnOrAfter="2022-07-13T15:59:34Z" Recipient="http://uat:8088/api/v1/SSO/AuthBack"></saml:SubjectConfirmationData>
</saml:SubjectConfirmation>
</saml:Subject>
<saml:Conditions NotBefore="2022-07-13T15:39:34Z" NotOnOrAfter="2022-07-13T15:59:34Z">
<saml:AudienceRestriction>
<saml:Audience>UAT</saml:Audience>
</saml:AudienceRestriction>
</saml:Conditions>
<saml:AuthnStatement AuthnInstant="2023-09-13T09:33:35Z" SessionIndex="s2175cf5b9655927157**********">
<saml:AuthnContext>
<saml:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport</saml:AuthnContextClassRef>
</saml:AuthnContext>
</saml:AuthnStatement>
</saml:Assertion>
</samlp:Response>
samlp:StatusCode :只有是status:Success才表示sso登录成功
saml:Audience:这个要和你SP metadata里面的EntityId对应才可以,避免环境错乱
saml:NameID:这个就是登录的用户ID,需要和HBS系统管理里面的user对应起来
以上三点都验证通过才能进入系统,然后去组织token等信息返回给前端
SSO登录成功之后回传验证页面
/sso/result?code=0&token=xxx&userId=xxxx&tenantCode=xxx&userCode=xxxx&userName=xxx&tenantDescription=xxx&msg=xxx
code=0 sso登录成功,将token和user、tenant等信息存到localstrorage,并且进入首页
code=-1 sso登录不成功,需要在页面上显示错误信息(不是弹框)并且还要显示
【重新登录】再次重定向到ssourl
【密码方式登录】返回到登录首页