【发布时间】:2017-05-01 20:43:52
【问题描述】:
我已经能够使用 Boomerang 客户端发布一个肥皂请求以返回一个过期的 GUID(用于 SSO)。
我现在正尝试在 C# ASP.NET 中实现相同的功能。我得到了一个可以正常工作的经典 ASP 示例:
<%
Option Explicit
Dim objHttp
Dim xmlData
Dim GUIDUrl
Dim SSOUrl
Dim redirectURL
Dim guidType
Dim orgId
Dim installCode
Dim TTL
Dim key
Dim user
' ====================================
' CONFIGURE THIS SECTION
' ====================================
GUIDUrl = "https://{URL}/d2l/guids/D2L.Guid.2.asmx"
SSOUrl = "https://{URL}/d2l/lp/auth/login/ssoLogin.d2l"
guidType = "SSO"
orgId = "12947"
installCode = "{Please Set this Value}"
TTL = "30"
key = "{Please Set this Value}"
user = "{Replace with an existing username or OegDefinedId}"
' ====================================
' END OF CONFIGURATION
' ====================================
Dim strResult, getusername
strResult = GUIDUrl & "/GenerateExpiringGuid" '?guidType=" & guidType & "&orgId=" & orgId & "&installCode=" & installCode & "&TTL=" & TTL & "&data=" & user & "&key=" & key
Set objHttp = Server.CreateObject("Microsoft.XMLHTTP")
objHTTP.open "POST", strResult,false
objHTTP.setRequestHeader "Content-Type","application/x-www-form-urlencoded"
objHttp.Send "guidType=" & guidType & "&orgId=" & orgId & "&installCode=" & installCode & "&TTL=" & TTL & "&data=" & user & "&key=" & key
strResult=objHTTP.responseText
If objHttp.Status = 200 Then
Set xmlData = objHttp.ResponseXML
RedirectURL = SSOUrl & "?username=" & user & "&guid=" & xmlData.childNodes(1).text
Response.Redirect (RedirectURL)
End If
Set objHttp = Nothing
%>
Boomerang 客户端和经典 ASP 示例代码都返回一个 385 个字符的字符串“GenerateExpiringGuidResult”。在这两种情况下,我都可以在 SSO URL 查询字符串中包含这个 GUID 以及一个用户 ID,然后我就可以成功地通过 D2L Brightspace 实例的身份验证。
我尝试在 C#/ASP.NET 中编写等效的代码,但是我的示例返回的是 429 个字符的字符串。
string guidType = "SSO";
string orgId = "1234";
string installCode = "{Please Set this Value}";
string TTL = "30";
string key = "{Please Set this Value}";
string user = "{Replace with an existing username or OegDefinedId}";
var GUIDUrl = "https://{URL}/d2l/guids/D2L.Guid.2.asmx";
var AuthURL = "https://{URL}/d2l/lp/auth/login/ssoLogin.d2l";
string postData = "guidType=" + guidType + "&orgId=" + orgId + "&installCode=" + installCode + "&TTL=" + TTL + "&data=" + user + "&key=" + key;
byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(postData);
HttpWebRequest request = HttpWebRequest.Create(GUIDUrl + "/GenerateExpiringGuid") as HttpWebRequest;
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;
StreamWriter requestWriter = new StreamWriter(request.GetRequestStream());
requestWriter.Write(postData);
requestWriter.Close();
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(response.GetResponseStream());
string strGUID = xmlDoc.DocumentElement.LastChild.InnerText;
string strRedirect = AuthURL + "?guid=" + strGUID + "&userid=" + user;
lblResult.Text = strRedirect;
尝试使用此 GUID(如上所述)会导致“未授权”页面:“错误:未授权。您无权查看您尝试访问的页面”。
【问题讨论】:
标签: c# asp.net desire2learn valence