1

我將Identity Server 4與Asp.net 4.5 MVC 4 Web應用程序集成在一起。在授權操作重定向到Identity Server登錄頁面後,但在成功登錄後,它不會再次返回到客戶端MVC應用程序。Asp.net MVC 4.5.2在用IdentityServer4登錄後不重定向

我的身份服務器4的客戶是

new Client { ClientId = "demo", 
        AllowedScopes = new List<string> { "openid"}, 
        AllowedGrantTypes = GrantTypes.Hybrid, 
        RedirectUris = new List<string>{"http://localhost:51048/signin-oidc"},} 

我的啓動包含

app.UseCookieAuthentication(new CookieAuthenticationOptions 
      { 
       AuthenticationType = "Cookies" 
      }); 
      app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions 
      { 
       Authority = "http://localhost:5000", //ID Server 
       ClientId = "demo", 
       ResponseType = "id_token code", 
       SignInAsAuthenticationType = "Cookies", 
       RedirectUri = "http://localhost:51048/signin-oidc", 
       Scope = "openid",    
      }); 
+1

什麼日誌說?您爲客戶端和UseOpenIdConnectAuthentication的RedirectUri配置的RedirectUri也不相同。 – Lutando

+0

重定向uri的端口不匹配 – devqon

+0

現在的問題是MVC4還是ASP.NET Core MVC相關?標籤似乎很混亂,從第一個觀點來看,它與asp.net核心 – Tseng

回答

0

添加AuthenticationSchemeSigninSchemeUseOpenIdConnectAuthorization選項:

app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions 
{ 
    AuthenticationScheme = "oidc", 
    SignInScheme = "Cookies" 
    // other options omitted... 
}); 
0

我的情況的原因此錯誤是添加自定義授權attrib utes和用戶獲得授權保存用戶信息後開啓會話。

[CustomAuthorize] 
public class SecureController 

所以我的解決辦法是不上AuthorizeCore功能打開會話但增加要求所需的數據如下

 app.UseCookieAuthentication(new CookieAuthenticationOptions 
     { 
      AuthenticationType = CookieAuthenticationDefaults.AuthenticationType 
     }); 

     app.UseOpenIdConnectAuthentication(

      new OpenIdConnectAuthenticationOptions 
      { 
       ClientId = Settings.Default.AuthenticationOptionsClientId, 
       ClientSecret = Settings.Default.AuthenticationOptionsClientSecret, 
       SignInAsAuthenticationType = CookieAuthenticationDefaults.AuthenticationType, 
       AuthenticationType = Settings.Default.AuthenticationOptionsAuthenticationType, 
       Authority = Settings.Default.AuthenticationOptionsAuthority, 
       RedirectUri = Settings.Default.AuthenticationOptionsRedirectUri, 
       ResponseType = Settings.Default.AuthenticationOptionsResponseType, 
       UseTokenLifetime = Settings.Default.AuthenticationOptionsUseTokenLifetime, 
       AuthenticationMode = AuthenticationMode.Active, 


       Notifications = new OpenIdConnectAuthenticationNotifications 
       { 
        SecurityTokenValidated = async context => 
        { 
         var claimsIdentity = new ClaimsIdentity(context.AuthenticationTicket.Identity.AuthenticationType); 

         claimsIdentity.AddClaim(new Claim("UserData", "User Data Content")); 

         context.AuthenticationTicket = new AuthenticationTicket(
          claimsIdentity, 
          context.AuthenticationTicket.Properties); 
        } 
       } 
      });