![](/img/trans.png)
[英]ASP.net using OWIN for Azure Active Directory Federation Services Single Sign On
[英]Single Sign On with Azure Active Directory
我創建了許多Web應用程序。 其中一些使用舊式Web表單身份驗證,而我們公司的其他一些站點則使用不同的身份驗證模式。
我正在嘗試使用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/
,租戶名稱為testapp
。 我的回復URL是https://localhost:44320/
這使我的應用程序ID uri https://localhost:44320/testapp
我覺得呢? 我也有我的客戶ID guid。
本教程的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:無法創建以從以下位置獲取配置:' https:// localhost:44320 / testapp / .well-known / openid-configuration '。]
我感覺是因為Azure無法將所有這些重定向到我的本地主機? 我如何設置它以便可以在Azure本身上進行測試? 甚至更進一步,該解決方案是否可以在多個Web應用程序中使用? 我假設它們在Active Directory中都是不同的應用程序,但是它們都需要使用SSO過程,用戶可以在其中使用一個身份登錄多個應用程序。
抱歉讓您感到困惑,這一切對我來說都是非常令人費解的,但是我正在努力學習。
編輯:
在webapp的啟動中,我將其稱為:
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}" />
若要查找有關您的租戶的更多信息,請參見本文: 如何獲取Azure Active Directory租戶
您也可以嘗試將此代碼添加到“啟動”中的“通知”中(就在AuthenticationFailed下),嘗試在處理程序上放置斷點以查看會發生什么:
AuthenticationFailed = context =>
{
context.HandleResponse();
context.Response.Redirect("/Error?message=" + context.Exception.Message);
return Task.FromResult(0);
},
SecurityTokenValidated = (context) =>
{
return Task.FromResult(0);
}
在您的一個控制器上放置一個[Authorize]屬性,當您瀏覽到它時,它應該重定向到AAD身份驗證。
AFAIK每個應用程序在Azure AD中都需要一個單獨的應用程序,並且您需要在每個單獨的應用程序中實現此身份驗證。 通過URL從一個應用程序鏈接到另一個應用程序時,我設法獲得了無縫登錄的體驗。
這個答案很好地總結了身份驗證與授權: 身份驗證與授權
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.