簡體   English   中英

針對Azure AD的WebForms身份驗證

[英]WebForms authentication against Azure AD

我有一個WebForms站點,它已在內部服務器上運行,並根據我們的內部Active Directory對用戶進行身份驗證。 由於我們正在實施一些新功能,因此需要將此站點移動到外部服務器,然后更改身份驗證,以便根據我們的Office 365帳戶對用戶進行身份驗證。 為此,我有:

  1. 創建了一個新的WebForms站點(不使用MVC)
  2. 在Azure中設置新應用程序。
  3. 修改了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 auth只是為了避免每次請求都去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/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM