在MVC中使用Identity Server V3的customuserservice示例无法重定向到登录页面

时间:2015-03-29 12:42:46

标签: thinktecture-ident-server thinktecture-ident-model thinktecture identityserver3

我正在使用Identity Server v3的CustomUserService示例。我添加了如下控制器 - “public class HomeController:Controller”     {         //         // 回家/         公共ActionResult索引()         {             return View();         }

    [Authorize]
    public ActionResult About()
    {
        //ViewBag.Message = "Your application description page.";

        //return View();
        return View((User as ClaimsPrincipal).Claims);

    }`

并添加了2个关于About.cshtml和Index.cshtml的视图。 如您所见,关于action有Authorize属性。因此,当我导航到About时,我应该被重定向到Identity Server V3的登录页面,但是没有发生这种情况。我的完整startup.cs如下 -

public void Configuration(IAppBuilder app)
    {
        LogProvider.SetCurrentLogProvider(new DiagnosticsTraceLogProvider());

        app.Map("/core", coreApp =>
        {
            var factory = InMemoryFactory.Create(
                clients: Clients.Get(),
                scopes: Scopes.Get());

            // different examples of custom user services
            var userService = new RegisterFirstExternalRegistrationUserService();
            //var userService = new ExternalRegistrationUserService();
            //var userService = new EulaAtLoginUserService();
            //var userService = new LocalRegistrationUserService();

            factory.UserService = new Registration<IUserService>(resolver => userService);

            var options = new IdentityServerOptions
            {
                //IssuerUri = "https://idsrv3.com",
                IssuerUri = "https://localhost:44333/",
                SiteName = "Thinktecture IdentityServer3 - CustomUserService",
                //SigningCertificate = LoadCertificate(),
                SigningCertificate = Certificate.Get(),
                Factory = factory,
                CorsPolicy = CorsPolicy.AllowAll,

                AuthenticationOptions = new Thinktecture.IdentityServer.Core.Configuration.AuthenticationOptions
                {
                    IdentityProviders = ConfigureAdditionalIdentityProviders,
                    LoginPageLinks = new LoginPageLink[] { 
                        new LoginPageLink{
                            Text = "Register",
                            //Href = "~/localregistration"
                            Href = "localregistration"
                        }
                    }
                },

                EventsOptions = new EventsOptions
                {
                    RaiseSuccessEvents = true,
                    RaiseErrorEvents = true,
                    RaiseFailureEvents = true,
                    RaiseInformationEvents = true
                }
            };

            coreApp.UseIdentityServer(options);
        });

我正在使用CustomerUserService示例,因为我想使用WSfederation。因此ADFS将向身份服务器提供声明,而身份服务器应将这些声明返回给关于视图。 任何人都可以帮助我。

1 个答案:

答案 0 :(得分:2)

当Identity Server初始化期间出现错误时,我遇到了类似的情况。我打开了登录Web.config:

http://identityserver.github.io/Documentation/docs/configuration/logging.html

    <system.diagnostics>
      <trace autoflush="true" indentsize="4">
       <listeners>
        <add name="myListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="d:\logs\STS.log" />
        <remove name="Default" />
       </listeners>
      </trace>
     </system.diagnostics> 

日志显示我的证书密钥长度小于2048位。您可能遇到了另一个记录的错误。