- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我创建了一堆网络应用程序。其中一些使用旧式 Webforms 身份验证,而我们公司的其他一些站点则使用不同的身份验证模式。
我正在尝试使用 Azure Active Directory 在一种 SSO 模式下整合这一点。我一直在尝试遵循指南/教程,但它不适合我。
我的技术目前是 ASP 4/MVC 5,尽管如果 ASP 5/MVC 6 更容易,那么我也可以自由地走这条路。目前所有 Web 应用程序都托管在 Azure 中。
令我困惑的是,在查看文档时,似乎有很多方法可以对用户进行身份验证和授权(而且,身份验证与授权对我来说并不是绝对清楚)。
我转到了 Azure 管理门户(旧门户)的 Active Directory 区域。我添加了一个名为 TestApp
的新应用程序。我将应用程序 URL 设置为 https://localhost:44320/
,然后将登录 URL 设置为 https://localhost:44320/
,将租户名称设置为 >测试应用程序
。我的回复网址是 https://localhost:44320/
这使得我的应用程序 id uri https://localhost:44320/testapp
我想?我还有我的客户端 ID 指南。
本教程有一个 AccountController
和一个 SignIn
方法,如下所示:
public void SignIn()
{
// Send an OpenID Connect sign-in request.
if (!Request.IsAuthenticated)
{
HttpContext.GetOwinContext().Authentication.Challenge(new AuthenticationProperties { RedirectUri = "/" }, OpenIdConnectAuthenticationDefaults.AuthenticationType);
}
}
导航到此时,我在浏览器中收到以下内容:
[InvalidOperationException: IDX10803: Unable to create to obtain configuration from: 'https://localhost:44320/testapp/.well-known/openid-configuration'.]
我有一种感觉,这是因为 Azure 无法将这一切重定向回我的本地主机?我该如何设置才能在 Azure 上进行测试?更进一步,这个解决方案可以在多个网络应用程序中使用吗?我假设它们在我的 Active Directory 中都是不同的应用程序,但它们都需要使用 SSO 过程,用户可以使用一个身份登录多个应用程序。
抱歉造成任何困惑,这对我来说非常复杂,但我正在尽力学习它。
编辑:
在网络应用程序的启动中,我调用此:
private static string clientId = ConfigurationManager.AppSettings["ida:ClientId"];
private static string aadInstance = ConfigurationManager.AppSettings["ida:AADInstance"];
private static string tenant = ConfigurationManager.AppSettings["ida:Tenant"];
private static string postLogoutRedirectUri = ConfigurationManager.AppSettings["ida:PostLogoutRedirectUri"];
string authority = String.Format(CultureInfo.InvariantCulture, aadInstance, tenant);
public void ConfigureAuth(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
ClientId = clientId,
Authority = authority,
PostLogoutRedirectUri = postLogoutRedirectUri,
Notifications = new OpenIdConnectAuthenticationNotifications
{
AuthenticationFailed = context =>
{
context.HandleResponse();
context.Response.Redirect("/Error?message=" + context.Exception.Message);
return Task.FromResult(0);
}
}
});
}
它利用这些 app.config 设置:
<add key="ida:ClientId" value="[my client id here]" />
<add key="ida:Tenant" value="testapp" />
<add key="ida:AADInstance" value="https://localhost:44320/{0}" />
<add key="ida:PostLogoutRedirectUri" value="https://localhost:44320/" />
最佳答案
Azure 能够重定向到本地主机,它只会弹出一个安全确认,询问是否可以导航到本地主机。
app.config 中的租户看起来不正确,请更改这些应用设置:
<add key="ida:Tenant" value="[YOUR TENANT].onmicrosoft.com" />
<add key="ida:AADInstance" value="https://login.microsoftonline.com/{0}" />
要了解有关您的租户的更多信息,请参阅这篇文章:How to get an Azure Active Directory tenant
您还可以尝试将此代码添加到启动中的通知中(就在 AuthenticationFailed 下),尝试在处理程序上放置断点以查看会发生什么:
AuthenticationFailed = context =>
{
context.HandleResponse();
context.Response.Redirect("/Error?message=" + context.Exception.Message);
return Task.FromResult(0);
},
SecurityTokenValidated = (context) =>
{
return Task.FromResult(0);
}
将 [Authorize] 属性放在您的一个 Controller 上,当您浏览到它时,它应该重定向到 AAD 身份验证。
据我所知,每个应用程序都需要在 Azure AD 中拥有一个单独的应用程序,并且您需要在每个单独的应用程序中实现此身份验证。当我通过 url 从一个应用程序链接到另一个应用程序时,我成功地获得了无缝登录体验。
这个答案很好地总结了身份验证与授权:Authentication versus Authorization
关于asp.net - 使用 Azure Active Directory 进行单点登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35487695/
这个问题在这里已经有了答案: Git for beginners: The definitive practical guide (37 个答案) 关闭 9 年前。 在使用句点(或句点,单点)将文件
我是一名优秀的程序员,十分优秀!