我有一个 WebForms 站点,它在内部服务器上运行,并根据我们的内部 Active Directory 对用户进行身份验证。由于我们正在实施一些新功能,该网站需要移动到外部服务器,然后更改身份验证,以便根据我们的 Office 365 帐户对用户进行身份验证。为此我有:
- 创建了一个新的 WebForms 站点(不使用 MVC)
- 在 Azure 中设置新应用程序。
-
修改Startup.Auth.cs如下:
public void ConfigureAuth(IAppBuilder app)
{
app.CreatePerOwinContext(ApplicationDbContext.Create);
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
}
});
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions { ClientId = "MyApplicationGUID", Authority = "https://login.windows.net/MyDomain.com" });
当我转到默认页面并单击登录时,它会将我带到正确的登录页面并显示 OpenID 按钮。如果单击该按钮,我将进入 Microsoft 登录页面,我可以在其中输入我的凭据。然而,此时,我被重定向回网站的登录页面,其中仍然要求输入用户名/密码。
我希望发生的是设置网站,以便如果用户未经过身份验证,他们将直接重定向到 Microsoft 登录页面,并在成功登录后重定向回他们最初请求的页面。如果失败,我会满意地让默认登录页面正常工作,这样当我单击 OpenID 时,我不会重定向回登录页面。
我现在没有时间学习 MVC 并将整个事情移植过来,所以此时走这条路不是一个选择。
我对这个过程了解不够,所以如果我的问题没有意义或者您需要更多信息,请告诉我,我很乐意尝试找到您需要的信息来帮助我。
也许我遗漏了一些东西,但我不明白为什么你需要自定义登录页面或外部登录 cookie。 OIDC/AAD 的典型 Startup.Auth 如下所示:
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
ClientId = "AppGUID",
Authority = "https://login.windows.net/MyDomain.com",
// After authentication return user to the page they were trying
// to access before being redirected to the Azure AD signin page.
Notifications = new OpenIdConnectAuthenticationNotifications()
{
RedirectToIdentityProvider = (context) =>
{
string currentUrl = context.Request.Scheme + "://" + context.Request.Host + context.Request.Path;
context.ProtocolMessage.RedirectUri = currentUrl;
return Task.FromResult(0);
}
}
});
cookie 身份验证只是为了防止每个请求都转到 AAD。所有实际工作都发生在 OpenIdConnectAuthentication 中。
以下是 WebForms、Azure AD 和 OpenID Connect 的示例:
http://www.cloudidentity.com/blog/2014/07/24/protecting-an-asp-net-webforms-app-with-openid-connect-and-azure-ad/ http://www.cloudidentity.com/blog/2014/07/24/protecting-an-asp-net-webforms-app-with-openid-connect-and-azure-ad/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)