我一直在尋找解決方案,但無法找到它。如何在PHP中檢索SAML2令牌以從WSO2獲取OAuth令牌APIM
這個問題直接關係到:
- 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令牌。 (使用URL 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">[email protected]</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之間的鏈接缺少某些聲明。 (我用google搜索了這個,並提出了一個stackoverflow交換來檢查發佈者id在斷言,我做了,但我不能在那裏發現任何錯誤)
感謝您的幫助,我會回來如果我有什麼新東西。當然,如果我忽略了一些明顯的東西!
可能與http://stackoverflow.com/questions/19866021/how-to-get-saml2-bearer-assertion-profile-for-oauth-within-wso2-api-manager-to-w?rq = 1 – JRobinss
可能與http://stackoverflow.com/questions/34738716/wso2-saml2bearergranthandler-saml-token-issuer-verification-failed-or-issuer-not – JRobinss