2017-01-01 106 views
0

我在Azure Active Directory網站配置回覆URL中指定了兩個URL。當我運行本地代碼時,一個重定向到我的localhost環境,另一個在運行prod網站時重定向到我的Azure託管網站。但Azure Active Directory似乎忽略了該設置。它僅使用一個或另一個URL但不能同時 這是我startup.Auth.csAzure Active Directory網站重定向意外

public partial class Startup 
{ 
    private static string clientId = ConfigurationManager.AppSettings["ida:ClientId"]; 
    private static string aadInstance = ConfigurationManager.AppSettings["ida:AADInstance"]; 
    private static string tenantId = ConfigurationManager.AppSettings["ida:TenantId"]; 
    private static string postLogoutRedirectUri = ConfigurationManager.AppSettings["ida:PostLogoutRedirectUri"]; 

    private static string authority = aadInstance + tenantId;  

    public void ConfigureAuth(IAppBuilder app) 
    { 
     app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType); 

     app.UseCookieAuthentication(new CookieAuthenticationOptions()); 

     AntiForgeryConfig.UniqueClaimTypeIdentifier = ClaimTypes.GivenName; 

     app.UseOpenIdConnectAuthentication(
      new OpenIdConnectAuthenticationOptions 
      { 
       ClientId = clientId, 
       Authority = authority, 
       PostLogoutRedirectUri = postLogoutRedirectUri,      

       TokenValidationParameters = new TokenValidationParameters 
       {             
        RoleClaimType = "roles" 
       }, 

      });    
    } 
} 

,這我startup.cs

public void Configuration(IAppBuilder app) 
    { 
     ConfigureAuth(app);  
    } 

,最後,這是我的web.config設置

<appSettings> 
<add key="ida:ClientId" value="*************************" /> 
<add key="ida:AADInstance" value="https://login.microsoftonline.com/" /> 
<add key="ida:AppKey" value="******************************" /> 
<add key="ida:TenantId" value="****************************" /> 
<add key="ida:PostLogoutRedirectUri" value="url of production website" /> 
<add key="ida:Domain" value="company domain" /> 
</appSettings> 

我不知道爲什麼這種重定向發生

回答

1

我找到了解決辦法我的問題

你應該Startup.Auth

   Notifications = new OpenIdConnectAuthenticationNotifications() 
       { 
        RedirectToIdentityProvider = (context) => 
        { 
         context.ProtocolMessage.RedirectUri = HttpContext.Current.Request.Url.GetLeftPart(System.UriPartial.Path); 
         context.ProtocolMessage.PostLogoutRedirectUri = new UrlHelper(HttpContext.Current.Request.RequestContext).Action("Index", "Home", null, HttpContext.Current.Request.Url.Scheme); 
         context.ProtocolMessage.Resource = GraphAPIIdentifier;        
         return Task.FromResult(0); 
        }} 

添加以下代碼OpenIdConnectAuthenticationOptions這樣重定向URI是基於動態運行它

希望這是有幫助的機器上。