我正在研究Klipfolio的SSO。我正在使用restsharp进行SSO。一切都很完美,我得到了成功的回应。我还收到了cookie作为回应,但无法重定向到他们的仪表板。 这是我的代码
var client = new RestClient("https://app.klipfolio.com/users/sso_auth");
var request = new RestRequest(Method.POST);
request.AddHeader("cache-control", "no-cache");
request.AddHeader("content-type", "application/json");
request.AddParameter("KF-SSO", AuthData["KF-SSO"]);
request.AddParameter("KF-Company", AuthData["KF-Company"]);
response = client.Execute(request);
CookieContainer CookiesContainer = new CookieContainer();
if (response.StatusCode == HttpStatusCode.OK) {
foreach (var Cookie in response.Cookies)
{
CookiesContainer.Add(new Cookie(Cookie.Name, Cookie.Value, Cookie.Path, Cookie.Domain));
}
client.CookieContainer = CookiesContainer;
KlipfolioDataModel objKlipfolioDataModel = JsonConvert.DeserializeObject<KlipfolioDataModel>(response.Content);
return objKlipfolioDataModel;
}
else
return new KlipfolioDataModel();
如果我从AJAX做同样的事情,我可以重定向到Klipoflio仪表板
function ssoAuth() {
$.ajax({
url: "https://app.klipfolio.com/users/sso_auth",
type: "post",
async: false,
xhrFields: {
withCredentials: true
},
headers: {
"KF-SSO": ssoToken,
"KF-Company": ssoCompany
},
dataType: "json",
success: function (data) {
console.log(data);
},
error: function (err) {
console.log("sso auth failed", err)
var errMsg = JSON.parse(err.responseText);
console.log(errMsg)
$('#result').html("<h2 class='fail'>SSO Failed<h2><p>Error: (#" + errMsg.error_code + ") "
+ errMsg.error_message + "</p>");
}
})
}
我不知道我哪里错了?帮我理清这件事。