我有一个MVC应用,正在尝试使其将Salesforce用作sso idp。我能够将其重定向到Salesforce进行登录。但是,登录后,以下内容将无法正常运行: 1)User.Identity.IsAuthenticated仍然为false。因此,索引页面显示“您尚未登录”。即使我已经登录。 2)如果我单击“关于”链接,则如果我已经登录,它会将我重定向到索引页面。如果不是,则将我带到salesforce进行登录,然后将我带到索引页面,该页面将显示“您尚未登录”。
以下是有关我的MVC应用程序的一些信息,希望对您有所帮助。
Web.config:
<sustainsys.saml2 entityId="http://xxxx.xxxx.com/SAML2" returnUrl="http://localhost:51048/Home/Index" authenticateRequestSigningBehavior="Never">
<nameIdPolicy allowCreate="true" format="Persistent" />
<metadata cacheDuration="PT1H" validDuration="7.12:00:00" wantAssertionsSigned="true">
<organization name="xxxx Inc" displayName="xxxx" url="https://www.xxxx.com" language="en" />
<contactPerson type="Support" email="lim.hock-chai@xxxx.com" />
<requestedAttributes>
<add friendlyName="User Name" name="urn:Username" nameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri" isRequired="true" />
<add name="Minimal" />
</requestedAttributes>
</metadata>
<identityProviders>
<add entityId="https://xxxx.my.salesforce.com" signOnUrl="https://xxxx.xxx.my.salesforce.com/idp/login?app=xxxxxxxxxxx" allowUnsolicitedAuthnResponse="true" binding="HttpRedirect">
<signingCertificate fileName="~/App_Data/SelfSignedCert_10Oct2017.crt" />
</add>
</identityProviders>
</sustainsys.saml2>
家庭控制器:
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
[Authorize]
public ActionResult About()
{
ViewBag.Message = "Your application description page.";
return View();
}
public ActionResult Contact()
{
ViewBag.Message = "Your contact page.";
return View();
}
}
索引页:
@{
ViewBag.Title = "Home Page";
}
<div class="row">
@if (User.Identity.IsAuthenticated)
{
<div class="col-md-4">
<h2>Hello @User.Identity.Name</h2>
<p>
Welcome.
</p>
</div>
}
else
{
<div class="col-md-4">
<h2>Hello</h2>
<p>
You are not login yet. Click <a href="@Url.Content("~/Saml2/SignIn")">here</a> to login
</p>
</div>
}
</div>
关于页面:
@{
ViewBag.Title = "About";
}
<h2>@ViewBag.Title.</h2>
<h3>@ViewBag.Message</h3>
<p>Use this area to provide additional information.</p>
答案 0 :(得分:0)
我找到了问题的原因。这是由我在Salesforce中设置连接的应用程序时放置错误的ACC链接引起的。 acs链接必须为/ Saml2 / Acs才能正常工作(例如:http://mysite/Saml2/Acs)。这解决了我的“ User.Identity.IsAuthenticated仍然为假”的问题。但是在解决该问题之后,我遇到了另外两个问题。
一个与使用SHA1加密不可接受的SHA1加密的Salesforce有关。为此,我将minIncomingSigningAlgorithm =“ SHA1”属性添加到web.config中的sustainsys.saml2元素中,以解决问题:
<sustainsys.saml2 .... minIncomingSigningAlgorithm="SHA1">
另一个问题与Salesforce有关,在响应中不包含InResponseTo元素。为此,我添加了ignoreMissingInResponseTo属性以通过传递错误:
<sustainsys.saml2 ....>
....
<compatibility ignoreMissingInResponseTo="true">
</compatibility>
....
</sustainsys.saml2>