Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PowerBuilder) eHealth.gov.be RequestSecurityTokenRequest a security token for use with the eHealth.gov.be SOAP web services. For more information, see https://www.ehealth.fgov.be/ehealthplatform/fr/data/file/view/bf25682e28c6ccd0d06768c73a467176f63791dd?name=STS%20-%20WS%20Trust%20-%20Cookbook%20v1.0%20dd%2020012023.pdf
integer li_rc integer li_Success oleobject loo_Cert oleobject loo_XmlToSign oleobject loo_BdCert oleobject loo_Dt oleobject loo_Gen oleobject loo_XmlCustomKeyInfo oleobject loo_SbXml oleobject loo_Http string ls_Url oleobject loo_Resp integer li_ResponseStatus oleobject loo_BdSecToken // This requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. li_Success = 1 // Provide a certificate + private key. // Note: If your certificate + private key is located on a hardware token or smartcard, you can call a different function to load from smartcard.. loo_Cert = create oleobject // Use "Chilkat_9_5_0.Cert" for versions of Chilkat < 10.0.0 li_rc = loo_Cert.ConnectToNewObject("Chilkat.Cert") if li_rc < 0 then destroy loo_Cert MessageBox("Error","Connecting to COM object failed") return end if li_Success = loo_Cert.LoadPfxFile("SSIN=12345678.acc.p12","p12_password") if li_Success <> 1 then Write-Debug loo_Cert.LastErrorText destroy loo_Cert return end if // Create the following XML to be signed.. // <?xml version="1.0" encoding="UTF-8"?> // <soapenv:Envelope xmlns:ns="http://docs.oasis-open.org/ws-sx/ws-trust/200512" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> // <soapenv:Header> // <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" // xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> // <wsse:BinarySecurityToken EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" // ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" // wsu:Id="X509-4A13D668E59AAC4F3816750824965588">{organization certificate}</wsse:BinarySecurityToken> // <wsu:Timestamp wsu:Id="TS-4A13D668E59AAC4F3816750824965567"> // <wsu:Created>2023-02-01T12:42:11.156Z</wsu:Created> // <wsu:Expires>2023-02-01T12:58:51.156Z</wsu:Expires> // </wsu:Timestamp> // </wsse:Security> // </soapenv:Header> // <soapenv:Body wsu:Id="id-4A13D668E59AAC4F38167508249655911" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> // <wst:RequestSecurityToken Context="RC-302613de-a809-46b5-931a-0a55bfca5937" // xmlns:auth="http://docs.oasis-open.org/wsfed/authorization/200706" // xmlns:ds="http://www.w3.org/2000/09/xmldsig#" // xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" // xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" // xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" // xmlns:wst="http://docs.oasis-open.org/ws-sx/ws-trust/200512"> // <wst:TokenType>http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1</wst:TokenType> // <wst:RequestType>http://docs.oasis-open.org/ws-sx/ws-trust/200512/Issue</wst:RequestType> // <wst:Claims Dialect="http://docs.oasis-open.org/wsfed/authorization/200706/authclaims"> // <auth:ClaimType Uri="urn:be:fgov:kbo-bce:organization:cbe-number"> // <auth:Value>{cbenumber}</auth:Value> // </auth:ClaimType> // <auth:ClaimType Uri="urn:be:fgov:ehealth:1.0:certificateholder:enterprise:cbe-number"> // <auth:Value>{cbenumber}</auth:Value> // </auth:ClaimType> // </wst:Claims> // <wst:Lifetime> // <wsu:Created>2023-02-01T08:30:10+02:00</wsu:Created> // <wsu:Expires>2023-02-01T09:30:10+02:00</wsu:Expires> // </wst:Lifetime> // <wst:KeyType>http://docs.oasis-open.org/ws-sx/wstrust/200512/PublicKey</wst:KeyType> // </wst:RequestSecurityToken> // </soapenv:Body> // </soapenv:Envelope> loo_XmlToSign = create oleobject // Use "Chilkat_9_5_0.Xml" for versions of Chilkat < 10.0.0 li_rc = loo_XmlToSign.ConnectToNewObject("Chilkat.Xml") loo_XmlToSign.Tag = "soapenv:Envelope" loo_XmlToSign.AddAttribute("xmlns:ns","http://docs.oasis-open.org/ws-sx/ws-trust/200512") loo_XmlToSign.AddAttribute("xmlns:soapenv","http://schemas.xmlsoap.org/soap/envelope/") loo_XmlToSign.UpdateAttrAt("soapenv:Header|wsse:Security",1,"xmlns:wsse","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd") loo_XmlToSign.UpdateAttrAt("soapenv:Header|wsse:Security",1,"xmlns:wsu","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd") loo_XmlToSign.UpdateAttrAt("soapenv:Header|wsse:Security|wsse:BinarySecurityToken",1,"EncodingType","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary") loo_XmlToSign.UpdateAttrAt("soapenv:Header|wsse:Security|wsse:BinarySecurityToken",1,"ValueType","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3") loo_XmlToSign.UpdateAttrAt("soapenv:Header|wsse:Security|wsse:BinarySecurityToken",1,"wsu:Id","X509-4A13D668E59AAC4F3816750824965588") loo_BdCert = create oleobject // Use "Chilkat_9_5_0.BinData" for versions of Chilkat < 10.0.0 li_rc = loo_BdCert.ConnectToNewObject("Chilkat.BinData") loo_Cert.ExportCertDerBd(loo_BdCert) loo_XmlToSign.UpdateChildContent("soapenv:Header|wsse:Security|wsse:BinarySecurityToken",loo_BdCert.GetEncoded("base64")) loo_XmlToSign.UpdateAttrAt("soapenv:Header|wsse:Security|wsu:Timestamp",1,"wsu:Id","TS-4A13D668E59AAC4F3816750824965567") loo_Dt = create oleobject // Use "Chilkat_9_5_0.CkDateTime" for versions of Chilkat < 10.0.0 li_rc = loo_Dt.ConnectToNewObject("Chilkat.CkDateTime") loo_Dt.SetFromCurrentSystemTime() loo_XmlToSign.UpdateChildContent("soapenv:Header|wsse:Security|wsu:Timestamp|wsu:Created",loo_Dt.GetAsTimestamp(0)) loo_Dt.AddSeconds(300) loo_XmlToSign.UpdateChildContent("soapenv:Header|wsse:Security|wsu:Timestamp|wsu:Expires",loo_Dt.GetAsTimestamp(0)) loo_Dt.AddSeconds(-300) loo_XmlToSign.UpdateAttrAt("soapenv:Body",1,"wsu:Id","id-4A13D668E59AAC4F38167508249655911") loo_XmlToSign.UpdateAttrAt("soapenv:Body",1,"xmlns:wsu","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd") loo_XmlToSign.UpdateAttrAt("soapenv:Body|wst:RequestSecurityToken",1,"Context","RC-302613de-a809-46b5-931a-0a55bfca5937") loo_XmlToSign.UpdateAttrAt("soapenv:Body|wst:RequestSecurityToken",1,"xmlns:auth","http://docs.oasis-open.org/wsfed/authorization/200706") loo_XmlToSign.UpdateAttrAt("soapenv:Body|wst:RequestSecurityToken",1,"xmlns:ds","http://www.w3.org/2000/09/xmldsig#") loo_XmlToSign.UpdateAttrAt("soapenv:Body|wst:RequestSecurityToken",1,"xmlns:wsa","http://schemas.xmlsoap.org/ws/2004/08/addressing") loo_XmlToSign.UpdateAttrAt("soapenv:Body|wst:RequestSecurityToken",1,"xmlns:wsp","http://schemas.xmlsoap.org/ws/2004/09/policy") loo_XmlToSign.UpdateAttrAt("soapenv:Body|wst:RequestSecurityToken",1,"xmlns:wsse","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd") loo_XmlToSign.UpdateAttrAt("soapenv:Body|wst:RequestSecurityToken",1,"xmlns:wst","http://docs.oasis-open.org/ws-sx/ws-trust/200512") loo_XmlToSign.UpdateChildContent("soapenv:Body|wst:RequestSecurityToken|wst:TokenType","http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1") loo_XmlToSign.UpdateChildContent("soapenv:Body|wst:RequestSecurityToken|wst:RequestType","http://docs.oasis-open.org/ws-sx/ws-trust/200512/Issue") li_Success = loo_XmlToSign.UpdateAttrAt("soapenv:Body|wst:RequestSecurityToken|wst:Claims",1,"Dialect","http://docs.oasis-open.org/wsfed/authorization/200706/authclaims") li_Success = loo_XmlToSign.UpdateAttrAt("soapenv:Body|wst:RequestSecurityToken|wst:Claims|auth:ClaimType[1]",1,"Uri","urn:be:fgov:ehealth:1.0:certificateholder:person:ssin") loo_XmlToSign.UpdateChildContent("soapenv:Body|wst:RequestSecurityToken|wst:KeyType","http://docs.oasis-open.org/ws-sx/wstrust/200512/PublicKey") loo_Gen = create oleobject // Use "Chilkat_9_5_0.XmlDSigGen" for versions of Chilkat < 10.0.0 li_rc = loo_Gen.ConnectToNewObject("Chilkat.XmlDSigGen") loo_Gen.SigLocation = "soapenv:Envelope|soapenv:Header|wsse:Security|wsse:BinarySecurityToken" loo_Gen.SigLocationMod = 1 loo_Gen.SigId = "SIG-4A13D668E59AAC4F38167508249656212" loo_Gen.SigNamespacePrefix = "ds" loo_Gen.SigNamespaceUri = "http://www.w3.org/2000/09/xmldsig#" loo_Gen.SignedInfoPrefixList = "soapenv urn urn1" loo_Gen.IncNamespacePrefix = "ec" loo_Gen.IncNamespaceUri = "http://www.w3.org/2001/10/xml-exc-c14n#" loo_Gen.SignedInfoCanonAlg = "EXCL_C14N" loo_Gen.SignedInfoDigestMethod = "sha256" // Set the KeyInfoId before adding references.. loo_Gen.KeyInfoId = "KI-4A13D668E59AAC4F3816750824965589" // -------- Reference 1 -------- loo_Gen.AddSameDocRef("TS-4A13D668E59AAC4F3816750824965567","sha256","EXCL_C14N","wsse soapenv urn urn1","") // -------- Reference 2 -------- loo_Gen.AddSameDocRef("id-4A13D668E59AAC4F38167508249655911","sha256","EXCL_C14N","urn urn1","") // -------- Reference 3 -------- loo_Gen.AddSameDocRef("X509-4A13D668E59AAC4F3816750824965588","sha256","EXCL_C14N","_EMPTY_","") loo_Gen.SetX509Cert(loo_Cert,1) loo_Gen.KeyInfoType = "Custom" // Create the custom KeyInfo XML.. loo_XmlCustomKeyInfo = create oleobject // Use "Chilkat_9_5_0.Xml" for versions of Chilkat < 10.0.0 li_rc = loo_XmlCustomKeyInfo.ConnectToNewObject("Chilkat.Xml") loo_XmlCustomKeyInfo.Tag = "wsse:SecurityTokenReference" loo_XmlCustomKeyInfo.AddAttribute("wsu:Id","STR-4A13D668E59AAC4F38167508249655810") loo_XmlCustomKeyInfo.UpdateAttrAt("wsse:Reference",1,"URI","#X509-4A13D668E59AAC4F3816750824965588") loo_XmlCustomKeyInfo.UpdateAttrAt("wsse:Reference",1,"ValueType","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3") loo_XmlCustomKeyInfo.EmitXmlDecl = 0 loo_Gen.CustomKeyInfoXml = loo_XmlCustomKeyInfo.GetXml() // Load XML to be signed... loo_SbXml = create oleobject // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 li_rc = loo_SbXml.ConnectToNewObject("Chilkat.StringBuilder") loo_XmlToSign.GetXmlSb(loo_SbXml) loo_Gen.Behaviors = "IndentedSignature" // Sign the XML... li_Success = loo_Gen.CreateXmlDSigSb(loo_SbXml) if li_Success <> 1 then Write-Debug loo_Gen.LastErrorText destroy loo_Cert destroy loo_XmlToSign destroy loo_BdCert destroy loo_Dt destroy loo_Gen destroy loo_XmlCustomKeyInfo destroy loo_SbXml return end if // The sbXml is sent as the HTTP request body below.. Write-Debug loo_SbXml.GetAsString() // ----------------------------------------------------------------------------------------------------------- // Send the SOAP requet to ask the server to issue a security token, which can then be used to access other SOAP services.. loo_Http = create oleobject // Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0 li_rc = loo_Http.ConnectToNewObject("Chilkat.Http") li_Success = loo_Http.SetSslClientCert(loo_Cert) if li_Success = 0 then Write-Debug loo_Http.LastErrorText destroy loo_Cert destroy loo_XmlToSign destroy loo_BdCert destroy loo_Dt destroy loo_Gen destroy loo_XmlCustomKeyInfo destroy loo_SbXml destroy loo_Http return end if loo_Http.SetRequestHeader("Content-Type","text/xml") ls_Url = "https://services-acpt.ehealth.fgov.be/IAM/SecurityTokenService/v1/RequestSecurityToken" loo_Resp = loo_Http.PostXml(ls_Url,loo_SbXml.GetAsString(),"utf-8") if loo_Http.LastMethodSuccess = 0 then Write-Debug loo_Http.LastErrorText destroy loo_Cert destroy loo_XmlToSign destroy loo_BdCert destroy loo_Dt destroy loo_Gen destroy loo_XmlCustomKeyInfo destroy loo_SbXml destroy loo_Http return end if li_ResponseStatus = loo_Resp.StatusCode Write-Debug "Response Status Code = " + string(li_ResponseStatus) // You'll want to check to see if the response status code = 200. // If not, then the response body contains error information instead of a security token. // This example will assume we received 200 status code. Write-Debug loo_Resp.BodyStr // The response body contains XML like this: // <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> // <SOAP-ENV:Header/> // <SOAP-ENV:Body> // <wst:RequestSecurityTokenResponse xmlns:wst="http://docs.oasis-open.org/ws-sx/ws-trust/200512" Context="RC-302613de-a809-46b5-931a-0a55bfca5937"> // <wst:RequestedSecurityToken> // <Assertion xmlns="urn:oasis:names:tc:SAML:1.0:assertion" AssertionID="_3e8ea5c951b2167c274974750ace9b5d" // ... // </Assertion> // </wst:RequestedSecurityToken> // </wst:RequestSecurityTokenResponse> // </SOAP-ENV:Body> // </SOAP-ENV:Envelope> // The portion of the response from <Assertion ..> ... </Assertion> is the SAML security token to be included // in a subsesquent SOAP request. It is extremely important to not modify the contents of the security token in any way, including not changing // whitespace or any formatting. Therefore, we get the response body exactly as-is, to be used in a SOAP request. // Copy the response body to a Chilkat BinData object. loo_BdSecToken = create oleobject // Use "Chilkat_9_5_0.BinData" for versions of Chilkat < 10.0.0 li_rc = loo_BdSecToken.ConnectToNewObject("Chilkat.BinData") loo_Resp.GetBodyBd(loo_BdSecToken) destroy loo_Resp // Let's save the bdSecToken to a file, and pick it up in the next example where it is used // in a SOAP request, such as in this example: AddressBook Search for Professionals loo_BdSecToken.WriteFile("qa_data/tokens/ehealth-fgov-be-sectoken.xml") Write-Debug "OK" destroy loo_Cert destroy loo_XmlToSign destroy loo_BdCert destroy loo_Dt destroy loo_Gen destroy loo_XmlCustomKeyInfo destroy loo_SbXml destroy loo_Http destroy loo_BdSecToken |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.