Dir*_*dly 5 c# asp.net authentication webforms azure
我有一个WebForms站点,它已在内部服务器上运行,并根据我们的内部Active Directory对用户进行身份验证.由于我们正在实施一些新功能,因此需要将此站点移动到外部服务器,然后更改身份验证,以便根据我们的Office 365帐户对用户进行身份验证.为此,我有:
修改了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" });
Run Code Online (Sandbox Code Playgroud)当我转到默认页面并单击"登录"时,它会转到正确的"登录"页面,并显示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);
}
}
});
Run Code Online (Sandbox Code Playgroud)
cookie auth只是为了避免每次请求都去AAD.所有实际工作都发生在OpenIdConnectAuthentication中.
以下是WebForms,Azure AD和OpenID Connect的示例:
| 归档时间: |
|
| 查看次数: |
4663 次 |
| 最近记录: |