【发布时间】:2016-11-21 15:43:41
【问题描述】:
我一直在寻找解决方案,但找不到。
这个问题直接相关:
- https://docs.wso2.com/display/AM200/Exchanging+SAML2+Bearer+Tokens+with+OAuth2+-+SAML+Extension+Grant+Type
- https://github.com/simplesamlphp/simplesamlphp/issues/220
这是我要执行的场景:
- 使用 SAML2 向 SP 进行身份验证。使用 SimpleSamlPhp 用 PHP 编码。
- 使用 SAML2 断言从 API mgr 端点获取 OAuth 令牌。 (使用网址http://api.gateway/token)
- 使用 OAuth 令牌通过 API 经理的网关调用 API。
我被困在指令上:获取 SAML2 断言令牌。 我在哪里可以找到这个令牌? 在 SimpleSamlPhp 中,我可以获取用户的属性或他们的 id,但我找不到任何断言。
我破解了 SSP 以获得最后一个断言,但不知道如何处理它。我期待一个单一的值(如令牌),但它是一个复杂的结构。上面的链接之一说我不应该访问它!
我要向令牌 URL 发送什么编码的内容?
编辑:添加一些示例。 我的断言 XML(已编辑):
<?xml version="1.0" encoding="UTF-8"?>
<saml2:Assertion xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion" xmlns:saml2p="urn:oasis:names:tc:SAML:2.0:protocol" ID="okdjgbm...jdbh" IssueInstant="2016-11-28T09:49:45.808Z" Version="2.0">
<saml2:Issuer Format="urn:oasis:names:tc:SAML:2.0:nameid-format:entity">https://g...p.com:9443/samlsso</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/2000/09/xmldsig#rsa-sha1" />
<ds:Reference URI="#okd...kejdbh">
<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>RrGcR...cktFuH0=</ds:DigestValue>
</ds:Reference>
</ds:SignedInfo>
<ds:SignatureValue>b91j/k...Z7d4=</ds:SignatureValue>
<ds:KeyInfo>
<ds:X509Data>
<ds:X509Certificate>MIICNT...Wq8uHSCo=</ds:X509Certificate>
</ds:X509Data>
</ds:KeyInfo>
</ds:Signature>
<saml2:Subject>
<saml2:NameID Format="urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress">toto@titi.com</saml2:NameID>
<saml2:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer">
<saml2:SubjectConfirmationData InResponseTo="_80258326a1...cd4bbd" NotOnOrAfter="2016-11-28T09:54:45.807Z" Recipient="http://1.2.3.4/simplesamlphp/www/module.php/saml/sp/saml2-acs.php/wso2-sp" />
</saml2:SubjectConfirmation>
<saml2:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer">
<saml2:SubjectConfirmationData InResponseTo="_8025832...d4bbd" NotOnOrAfter="2016-11-28T09:54:45.807Z" Recipient="https://my.wso2.apim:8243/token" />
</saml2:SubjectConfirmation>
</saml2:Subject>
<saml2:Conditions NotBefore="2016-11-28T09:49:45.808Z" NotOnOrAfter="2016-11-28T09:54:45.807Z">
<saml2:AudienceRestriction>
<saml2:Audience>mytestapp</saml2:Audience>
<saml2:Audience>https://my.wso2.apim:8243/token</saml2:Audience>
</saml2:AudienceRestriction>
</saml2:Conditions>
<saml2:AuthnStatement AuthnInstant="2016-11-28T09:49:45.815Z" SessionIndex="1f5192...b591">
<saml2:AuthnContext>
<saml2:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:Password</saml2:AuthnContextClassRef>
</saml2:AuthnContext>
</saml2:AuthnStatement>
<saml2:AttributeStatement />
</saml2:Assertion>
编码为 base64-URL 编码的 XML:
PHNhbWwyO...dGlvbj4,
使用从另一个 SO 帖子复制的方法
function base64_url_encode($input) {
return strtr(base64_encode($input), '+/=', '-_,');
}
大约有 20 行长(是的,末尾有一个逗号)。
不行,我得到JSON结果
{"error":"invalid_grant","error_description":"Provided Authorization Grant is invalid."}
在痕迹中:
TID: [0] [AM] [2016-11-29 11:04:50,297] DEBUG {org.wso2.carbon.identity.oauth2.token.handlers.grant.saml.SAML2BearerGrantHandler} - SAML Token Issuer verification failed or Issuer not registered {org.wso2.carbon.identity.oauth2.token.handlers.grant.saml.SAML2BearerGrantHandler}
TID: [0] [AM] [2016-11-29 11:04:50,298] DEBUG {org.wso2.carbon.identity.oauth2.token.AccessTokenIssuer} - Invalid Grant provided by the client, id=fkJa...Ohoa, user-name=null to application=myapp-subscriber_test_PRODUCTION {org.wso2.carbon.identity.oauth2.token.AccessTokenIssuer}
TID: [0] [AM] [2016-11-29 11:04:50,300] DEBUG {org.wso2.carbon.identity.oauth2.token.AccessTokenIssuer} - OAuth-Error-Code=invalid_grant client-id=fkJa...hoa grant-type=urn:ietf:params:oauth:grant-type:saml2-bearer scope=PRODUCTION {org.wso2.carbon.identity.oauth2.token.AccessTokenIssuer}
我正在询问系统的配置器。在我看来,IDS、APIM 和 OAuth 之间的链接中缺少一些东西,一些声明。 (我用谷歌搜索了这个,并提出了一个 stackoverflow 交换来检查断言中的颁发者 ID,我这样做了,但我无法确定那里有什么问题)
感谢您的帮助,如果我有什么新的东西,我会回来的。当然,如果我忽略了一些明显的事情!
【问题讨论】:
标签: php oauth wso2 saml-2.0 wso2-am