我正在开发一个在 iframe 中嵌入外部网站 (Tableau) 的 Web 应用程序。我想知道如何通过背后的代码安全地无缝登录?目前我只是通过在 URL 中设置参数来发布用户名和密码。这是我的代码:
var getAuthUrl = WebServerUrl + "/auth.xml";
WebClient.Headers["Content-type"] = "application/x-www-form-urlencoded";
var authResponse = WebClient.UploadString(new Uri(getAuthUrl), "GET");
var authXml = new XmlDocument();
authXml.LoadXml(authResponse);
var modulusNode = authXml.SelectSingleNode("//modulus/text()");
var exponentNode = authXml.SelectSingleNode("//exponent/text()");
var authTokenNode = authXml.SelectSingleNode("//authenticity_token/text()");
if (modulusNode != null && exponentNode != null && authTokenNode != null)
{
var authenticityToken = authTokenNode.Value;
var postLoginUrl = WebServerUrl + "/auth/login";
return postLoginUrl + "?" + "username=" + Username + "&password=" + Password + "&authenticity_token=" + authenticityToken;
}
后面的代码:
tableauIframe.Attributes["src"] = postLoginUrl;
谢谢。