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); 
        } 
       } 
      });