我有一个Azure VM,其中包含ASP.NET Web应用程序的部署。我部署Web应用程序的方式是通过Web部署,并在部署完成后将文件复制到 C:\ inetpub \ WebApplication1 中。
当前身份验证 NLTM ,为此, web.config 文件在身份验证部分中显示如下。
<system.webServer>
<security xdt:Transform="InsertIfMissing">
<authentication>
<windowsAuthentication enabled="true">
<providers>
<clear />
<add value="NTLM" />
<add value="Negotiate" />
</providers>
</windowsAuthentication>
<anonymousAuthentication enabled="false" />
</authentication>
</security>
</system.webServer>
如何切换到OAuth并使用Azure Active Directory作为授权机制来访问Web App?
到目前为止,我进入了 Azure门户中的 Azure Active Directory 并注册了一个新的应用程序(应用程序类型= Web App / API )然后使用Web应用程序的主页面(http://azureMachineName:60)
设置主页此注册过程生成了对象ID和应用程序ID。在这一点上,我真的不知道如何将其与我的Web App解决方案联系起来。
这就是Startup类的样子
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
}
}
在App_Start内部,我只有以下条款:
BundleConfig.cs
IdentityConfig.cs
RouteConfig.cs
知道如何切换到OAuth并使用AAD吗?
答案 0 :(得分:0)
根据我的理解,您希望使用AAD而不是原始身份验证,如果是这种情况,我们可以添加以下代码。它是使用 ASP.Net OpenID Connect OWIN 中间件的demo code的片段。
// The Client ID is used by the application to uniquely identify itself to Azure AD.
// The Metadata Address is used by the application to retrieve the signing keys used by Azure AD.
// The AAD Instance is the instance of Azure, for example public Azure or Azure China.
// The Authority is the sign-in URL of the tenant.
// The Post Logout Redirect Uri is the URL where the user will be redirected after they sign out.
//
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,
RedirectUri = postLogoutRedirectUri,
Notifications = new OpenIdConnectAuthenticationNotifications
{
AuthenticationFailed = context =>
{
context.HandleResponse();
context.Response.Redirect("/Error?message=" + context.Exception.Message);
return Task.FromResult(0);
}
}
});
}