首页 文章

如何在WSO2 API Manager中获取OAuth的SAML2 Bearer Assertion配置文件?

提问于
浏览
1

我在WSO2 API Manager中遇到问题"SAML2 Bearer Assertion profile for Oauth" . 我正在尝试在API Manager(版本1.5)上应用"Johann's Wall" How-to,但运行时出现以下错误 .

[2013-11-08 17:44:35,930] DEBUG - SAML2BearerGrantTypeHandler SAML Assertion Audience Restriction validation failed
[2013-11-08 17:44:36,024] DEBUG - AccessTokenIssuer Invalid Grant provided by the client, id=enfKWsilmCxdIwhYiINcoA2JKwka, user-name=admin to application=MyFlowChart
[2013-11-08 17:44:36,025] DEBUG - AccessTokenIssuer OAuth-Error-Code=invalid_grant client-id=enfKWsilmCxdIwhYiINcoA2JKwka grant-type=urn:ietf:params:oauth:grant-type:saml2-bearer scope=

检查 org.wso2.carbon.identity.oauth2.token.handlers.grant.saml.SAML2BearerGrantTypeHandler 的代码只有在配置的"Trusted Identity Provider"中的"Identity Provider Audience"条目与SAML断言中的 <saml:Audience> 值都不匹配时才会出现此错误 . 但是比较配置和SAML断言(见下文)对我来说看起来很好 .

希望有人可以帮助我或者暗示我想要出错...

设置/配置

1.)在API Manager中设置"Trusted Identity Providers"(参见screenshot

2.)通过 SAML2AssertionCreator.jar 创建SAML2断言

<?xml version="1.0" encoding="UTF-8"?>
<saml:Assertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" ID="mkfeiofmkjmjpicmdllnaapcmjlimjmajdiejiip" IssueInstant="2013-11-08T16:43:41.877Z" Version="2.0">
    <saml:Issuer Format="urn:oasis:names:tc:SAML:2.0:nameid-format:entity">OAuthPlayground</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:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
            <ds:Reference URI="#mkfeiofmkjmjpicmdllnaapcmjlimjmajdiejiip">
                <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="ds saml xs xsi"/>
                    </ds:Transform>
                </ds:Transforms>
                <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
                <ds:DigestValue>bNaQFYpcakb07xbUpUdVuSidvuA=</ds:DigestValue>
            </ds:Reference>
        </ds:SignedInfo>
        <ds:SignatureValue>gUe0mXTRPD79HTz7[...]</ds:SignatureValue>
        <ds:KeyInfo>
            <ds:X509Data>
                <ds:X509Certificate>MIIFrDCCBJSgAwIBA[...]</ds:X509Certificate>
            </ds:X509Data>
        </ds:KeyInfo>
    </ds:Signature>
    <saml:Subject>
        <saml:NameID Format="urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress">admin</saml:NameID>
        <saml:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer">
            <saml:SubjectConfirmationData InResponseTo="0" NotOnOrAfter="2013-11-08T16:48:41.877Z" Recipient="https://sl02502.apps.eon.com:9443/oauth2endpoints/token"/>
        </saml:SubjectConfirmation>
    </saml:Subject>
    <saml:Conditions NotBefore="2013-11-08T16:43:41.877Z" NotOnOrAfter="2013-11-08T16:48:41.877Z">
        <saml:AudienceRestriction>
            <saml:Audience>restriction</saml:Audience>
        </saml:AudienceRestriction>
    </saml:Conditions>
    <saml:AuthnStatement AuthnInstant="2013-11-08T16:43:41.945Z">
        <saml:AuthnContext>
            <saml:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:Password</saml:AuthnContextClassRef>
        </saml:AuthnContext>
    </saml:AuthnStatement>
    <saml:AttributeStatement>
        <saml:Attribute>
            <saml:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">a</saml:AttributeValue>
        </saml:Attribute>
    </saml:AttributeStatement>
</saml:Assertion>

3.)使用base64编码的SAML断言对API Manager的OAuth endpoints 运行“curl”

curl -k -X POST -u "enfKWsilmCxdIwhYiINcoA2JKwka:eEfmtoFRFyl3JIhMH1jM0bbXbkMa" -H "Content-Type: application/x-www-form-urlencoded;charset=UTF-8" -d "grant_type=urn:ietf:params:oauth:grant-type:saml2-bearer&assertion=PD94bWwgdm[...]0aW9uPg%3D%3D" https://sl02502.apps.eon.com:9445/oauth2/token

1 回答

  • 2

    问题出在您的SAML2断言中 . 您找不到具有OAuth2令牌 endpoints 作为受众的Audience元素 . 你唯一的受众是“限制” . 要使saml2-bearer授权类型起作用,您需要将OAuth2令牌 endpoints 作为断言的受众 .

    您需要做的是使用"SAML2AssertionCreator.jar"生成SAML2断言时,您需要使用逗号分隔值指定多个受众 . 例如 . https://sl02502.apps.eon.com:9445/oauth2/token,restriction

    事实上,获得saml2-bearer授权类型工作所需的唯一受众是令牌 endpoints . 即您无需在“受信任的身份提供商”配置中指定任何受众 . 如果您在此处指定了任何受众,那么您需要确保这些受众进入SAML2断言 . 这在除了令牌 endpoints 之外其他依赖方将使用此SAML2断言的情况下非常有用 . 在您的情况下,如果您没有这样的要求,您可以从“受信任的身份提供商”配置和断言中删除称为“限制”的受众,或者如果您需要这样的受众,则必须在两个地方都拥有它 .

相关问题