2017-03-21 5 views
0

私はAzure VMを持っています。これにはASP.NET Webアプリケーションの展開が含まれています。私がWebアプリケーションを配備する方法は、Web Deployであり、配備が完了した後にファイルがC:\ inetpub \ WebApplication1にコピーされています。Azure VMに保存されているWebアプリケーションのOAuthを追加

現在の認証が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> 

そして、これは認証がAzureのVM IIS Configurator Editor

Configurator Editor2

どのように私はOAuthのに切り替えてWebにアクセスするための認証メカニズムとしてのAzure Active Directoryを使用することができますにどのように見えるかですアプリ?

はこれまでのところ、私はAzureのポータルのAzure Active Directoryのに行き、新しいアプリケーション(アプリケーションタイプ= Webアプリケーション/ API)を登録し、その後のメインページをホームページに設定しますWebアプリケーション(http://azureMachineName:60

この登録プロセスでは、オブジェクトIDとアプリケーションIDが生成されました。この時点で、私はこれを私のWeb Appソリューションにどのように接続するのか本当に分かりません。スタートアップクラスは

public partial class Startup 
{ 
    public void Configuration(IAppBuilder app) 
    { 

    } 
} 

のように見え、App_Startの内側に、私は次のようclasesを持っているか

これは、次のとおりです。

BundleConfig.cs 
IdentityConfig.cs 
RouteConfig.cs 
私はAADをOAuthのに切り替えて使用することができますどのように

任意のアイデア?

答えて

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); 
        } 
       } 
      }); 
    } 
関連する問題