【问题标题】:How to get SAML2 Bearer Assertion profile for OAuth within WSO2 API Manager to work?如何在 WSO2 API Manager 中为 OAuth 获取 SAML2 Bearer Assertion 配置文件才能正常工作?
【发布时间】:2024-01-02 10:16:01
【问题描述】:

我在 WSO2 API 管理器中获取工作“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 的代码只有在配置的“受信任的身份提供者”中的“身份提供者受众”条目均不与 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 端点运行“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   

【问题讨论】:

    标签: oauth wso2 saml-2.0


    【解决方案1】:

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

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

    事实上,让 saml2-bearer 授权类型工作所需的唯一受众是令牌端点。 IE。您根本不需要在“受信任的身份提供者”配置中指定任何受众。如果您在此处指定了任何受众,那么您需要确保这些受众来自 SAML2 断言。这在除了令牌端点之外,其他依赖方将使用此 SAML2 断言的情况下很有用。在您的情况下,如果您没有此类要求,则可以从“受信任的身份提供者”配置和断言中删除名为“限制”的受众,或者如果您需要这样的受众,则必须在两个地方都有它。

    【讨论】:

      最近更新 更多