如何使用webex的XML-API与SSO (SAML)

本文关键字:SSO SAML XML-API 何使用 webex | 更新日期: 2023-09-27 17:49:45

我正在编写一个小工具,使用支持票证信息与我们的支持客户打开WebEx。当站点使用用户名/密码时,我可以使其工作,现在我们使用SSO。WebEx服务器已经设置为接受SSO(由我们的IT经理-不是我)。

WebEx参考资料(链接如下)没有详细说明,官方网站的WebEx开发论坛非常休眠,没有关于这个主题的答案,所以我决定在这里试试运气。
在官方论坛上发布了同样的问题

谁知道如何使下面的代码实际工作?<samlResponse>标签中的内容,并将代码中的下面一行替换为可以使其工作的内容:

    <samlResponse>samlResponse message will go here</samlResponse>

文档中的SAML断言是什么意思?

到目前为止我发现了什么

WebEx的XML-API文档(第68页)描述如下:

3.1 AuthenticateUser

AuthenticateUser API将接受SAML断言来代替用户密码。的返回的可用于后续XML API请求,而无需使用在Super Admin中定义的会话持续时间。这可以取代当前对a和身份验证的需求。…

以下模式图显示了AuthenticateUser请求的元素结构消息。

然后提供了XML模式图,以及一个示例。

参考示例。net代码(不使用SAML),我提出了以下代码:
string strXMLServer = "https://varonis.webex.com/WBXService/XMLService";
WebRequest request = WebRequest.Create(strXMLServer);
// Set the Method property of the request to POST.
request.Method = "POST";
// Set the ContentType property of the WebRequest.
request.ContentType = "application/x-www-form-urlencoded";
// Create POST data and convert it to a byte array.
Func<StringBuilder, StringBuilder> webExXML =
    bodySB => new StringBuilder(1024) // Currently 294 bytes in length
        .AppendLine("<?xml version='"1.0'" encoding='"ISO-8859-1'"?>")
        .Append("<serv:message xmlns:xsi='"http://www.w3.org/2001/XMLSchema-instance'"")
        .Append(" xmlns:serv='"http://www.webex.com/schemas/2002/06/service'"")
        .Append(" xsi:schemaLocation='"http://www.webex.com/schemas/2002/06/service")
        .Append(" http://www.webex.com/schemas/2002/06/service/service.xsd'">") 
        .AppendLine("<header>")
        .AppendLine("<securityContext>")
        .AppendLine("<siteName>siteName</siteName>")
        .AppendLine("<webExID>username</webExID>")
        .AppendLine("<password></password>")
        .AppendLine("<partnerID></partnerID>")
        .AppendLine("</securityContext>")
        .AppendLine("</header>")
        .AppendLine()
        .AppendLine("<body>")
        .Append(bodySB)
        .AppendLine()
        .AppendLine("</body>")
        .AppendLine("</serv:message>");
var xmlAuthBodyContent = new StringBuilder()
    .AppendLine("<bodyContent ")
    .AppendLine("xsi:type='"java:com.webex.service.binding.user.AuthenticateUser'">")
    .AppendLine("<samlResponse>samlResponse message will go here</samlResponse>")
    .AppendLine("</bodyContent>");
byte[] byteArray = Encoding.UTF8.GetBytes(webExXML(xmlAuthBodyContent).ToString());
// Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length;
// Get the request stream.
Stream dataStream = request.GetRequestStream();
// Write the data to the request stream.
dataStream.Write(byteArray, 0, byteArray.Length);
// Close the Stream object.
dataStream.Close();
// Get the response.
WebResponse response = request.GetResponse();
DataSet DSResponse = new DataSet();
DSResponse.ReadXml(response.GetResponseStream());
DSResponse.GetXml().Dump();
我得到的结果是:
<serv:message xmlns:serv="http://www.webex.com/schemas/2002/06/service">
<serv:header>
    <serv:response>
    <serv:result>FAILURE</serv:result>
    <serv:reason>Authentication Server can't generate a valid session ticket</serv:reason>
    <serv:gsbStatus>PRIMARY</serv:gsbStatus>
    <serv:exceptionID>030048</serv:exceptionID>
    <serv:subErrors>
        <serv:subError>
        <serv:exceptionID>AS0062</serv:exceptionID>
        <serv:reason>Validate assertion failed</serv:reason>
        <serv:value />
        </serv:subError>
    </serv:subErrors>
    </serv:response>
</serv:header>
<serv:body>
    <serv:bodyContent />
</serv:body>
</serv:message>

如何使用webex的XML-API与SSO (SAML)

我终于在WebEx论坛上得到了Nathan Morrow的回应,我在他的允许下复制了这里的内容,以防有人在这里发现这有用。

答案:

SAML断言是用于基于SAML的身份验证的XML样式文档。它包括使用先前配置的信任证书进行身份验证和数字签名所需的几个值。您将需要与IT合作,以获得从正在使用的Identity Management系统检索SAML断言的访问权限。一旦能够检索BASE64格式的SAML断言(它看起来不像这种格式的XML,只是一段字符),就可以将整个断言放入authenticateUser请求中的samlResponse元素中。

然后我问WebEx一键式工具是如何做到的,他回答:

WebEx生产力工具使用自定义的内部api和web浏览器功能来访问您公司的身份验证门户以确认身份验证。在幕后涉及到一个SAML断言。一旦您能够为您的工具检索断言,它也将在幕后显示给最终用户。

为线程巫术道歉,但这里的答案并不是真的那么有用,我想我应该包括一个完整的,在c#中工作的例子(针对ADFS 3.0服务器测试),从上面的代码加上一些额外的项目:

 var handler = new HttpClientHandler
        {
            UseDefaultCredentials = true,
            AllowAutoRedirect = true,
            CookieContainer = new System.Net.CookieContainer(),
            UseCookies = true
        };
        var client = new HttpClient(handler) {MaxResponseContentBufferSize = 256000};
        client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)");
        client.DefaultRequestHeaders.Add("Connection", "Keep-Alive");
        client.DefaultRequestHeaders.ExpectContinue = false;

        var samlResponseString = client
            .GetStringAsync(
                new Uri("https://AdfsServer/adfs/ls/IdpInitiatedSignOn.aspx?logintoRP=RPIdentifier")).Result;

        var parsedSamlResponse = "";
        Regex reg = new Regex("SAMLResponse''W+value''='''"([^'''"]+)'''"");
        MatchCollection matches = reg.Matches(samlResponseString);
        foreach (Match m in matches)
        {
            parsedSamlResponse =  m.Groups[1].Value;
        }        
        string strXMLServer = "https://mysite.webex.com/WBXService/XMLService";
        WebRequest request = WebRequest.Create(strXMLServer);
// Set the Method property of the request to POST.
        request.Method = "POST";
// Set the ContentType property of the WebRequest.
        request.ContentType = "application/x-www-form-urlencoded";
// Create POST data and convert it to a byte array.
        Func<StringBuilder, StringBuilder> webExXML =
            bodySB => new StringBuilder(1024) // Currently 294 bytes in length
                .AppendLine("<?xml version='"1.0'" encoding='"ISO-8859-1'"?>")
                .Append("<serv:message xmlns:xsi='"http://www.w3.org/2001/XMLSchema-instance'"")
                .Append(" xmlns:serv='"http://www.webex.com/schemas/2002/06/service'"")
                .Append(" xsi:schemaLocation='"http://www.webex.com/schemas/2002/06/service")
                .Append(" http://www.webex.com/schemas/2002/06/service/service.xsd'">")
                .AppendLine("<header>")
                .AppendLine("<securityContext>")
                .AppendLine("<siteName>siteName</siteName>")
                .AppendLine("<webExID>adminUsername</webExID>")                    
                .AppendLine("</securityContext>")
                .AppendLine("</header>")
                .AppendLine()
                .AppendLine("<body>")
                .Append(bodySB)
                .AppendLine()
                .AppendLine("</body>")
                .AppendLine("</serv:message>");
        var xmlAuthBodyContent = new StringBuilder()
            .AppendLine("<bodyContent ")
            .AppendLine("xsi:type='"java:com.webex.service.binding.user.AuthenticateUser'">")
            .AppendLine($"<samlResponse>{parsedSamlResponse}</samlResponse>")
            .AppendLine("<protocol>SAML2.0</protocol>")
            .AppendLine("</bodyContent>");
        byte[] byteArray = Encoding.UTF8.GetBytes(webExXML(xmlAuthBodyContent).ToString());
// Set the ContentLength property of the WebRequest.
        request.ContentLength = byteArray.Length;
// Get the request stream.
        Stream dataStream = request.GetRequestStream();
// Write the data to the request stream.
        dataStream.Write(byteArray, 0, byteArray.Length);
// Close the Stream object.
        dataStream.Close();
// Get the response.
        WebResponse response = request.GetResponse();
        DataSet DSResponse = new DataSet();
        DSResponse.ReadXml(response.GetResponseStream());
        string xmlResponse = DSResponse.GetXml();

更改代码以反映您的ADFS服务器,RP标识符,Webex站点名称和管理员用户名。

缺少的重要部分:

    从ADFS获取SAMLResponse的代码
  • bodyContent块中的protocol标签(设置为SAML2.0)