【问题标题】:IdentityServer3 MVC sample loopsIdentityServer3 MVC 示例循环
【发布时间】:2023-03-24 15:09:01
【问题描述】:

我正在查看https://identityserver.github.io/Documentation/docs/overview/mvcGettingStarted.html 的示例。这是在VS2013中。我使用谷歌浏览器作为浏览器。我已经设法进入“添加受保护的资源并显示声明”,我在 About 中添加了 AuthorizeAttribute。我运行应用程序。我点击关于。正如预期的那样,我看到了登录表单。我使用“秘密”密码以“bob”身份登录。我希望看到列有声明的“关于”表单。相反,我看到一个带有长 URI 的空白表单,然后是某种循环。

我查看了 Fiddler 以获得线索。循环是:

  1. GET /Home/关于 HTTP/1.1
  2. GET /identity/connect/authorize?...
  3. POST / HTTP/1.1
  4. POST /skypectoc/v1/pnr/parse HTTP/1.1
  5. 转到 1

这表明应用重定向到身份服务器,该服务器重定向回原始 URL,但应用无法识别用户已通过身份验证,因此它重定向到身份服务器。以此类推。

我的 Startup 课程是:

public class Startup
{
    private static readonly OpenIdConnectAuthenticationOptions OpenIdConnectAuthenticationOptions = new OpenIdConnectAuthenticationOptions
    {
        Authority = "https://localhost:44300/identity/",
        ClientId = "mvc",
        Scope = "openid profile roles",
        RedirectUri = "https://localhost:44300/",
        ResponseType = "id_token",
        SignInAsAuthenticationType = "Cookies"
    };

    private static readonly CookieAuthenticationOptions CookieAuthenticationOptions = new CookieAuthenticationOptions
    {
        AuthenticationType = "Cookies"
    };

    public void Configuration(IAppBuilder app)
    {
        IdentityServerServiceFactory identityServerServiceFactory = new IdentityServerServiceFactory()
            .UseInMemoryUsers(Users.Get())
            .UseInMemoryClients(Clients.Get())
            .UseInMemoryScopes(Scopes.Get());
        IdentityServerOptions identityServerOptions = new IdentityServerOptions
        {
            SiteName = "Embedded IdentityServer",
            SigningCertificate = LoadCertificate(),
            Factory = identityServerServiceFactory
        };
        app.Map("/identity", idsrvApp => idsrvApp.UseIdentityServer(identityServerOptions));
        app.UseCookieAuthentication(CookieAuthenticationOptions);
        app.UseOpenIdConnectAuthentication(OpenIdConnectAuthenticationOptions);
    }

    private X509Certificate2 LoadCertificate()
    {
        string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"bin\idsrv3test.pfx");
        return new X509Certificate2(path, "idsrv3test");
    }
}

我有客户

public static class Clients
{
    public static IEnumerable<Client> Get()
    {
        return new[]
        {
            new Client
            {
                Enabled = true,
                ClientName = "MVC Client",
                ClientId = "mvc",
                Flow = Flows.Implicit,
                RedirectUris = new List<string>
                {
                    "https://localhost:44300/"
                },
                AllowAccessToAllScopes = true
            }
        };
    }
}

范围:

public static class Scopes
{
    public static IEnumerable<Scope> Get()
    {
        List<Scope> scopes = new List<Scope>
        {
            new Scope
            {
                Enabled = true,
                Name = "roles",
                Type = ScopeType.Identity,
                Claims = new List<ScopeClaim>
                {
                    new ScopeClaim("roles")
                }
            }
        };
        scopes.AddRange(StandardScopes.All);
        return scopes;
    } 
}

用户:

public static class Users
{
    public static List<InMemoryUser> Get()
    {
        return new List<InMemoryUser>
        {
            new InMemoryUser
            {
                Username = "bob",
                Password = "secret",
                Subject = "1",
                Claims = new[]
                {
                    new Claim(Constants.ClaimTypes.GivenName, "Bob"),
                    new Claim(Constants.ClaimTypes.FamilyName, "Smith"),
                    new Claim(Constants.ClaimTypes.Role, "Geek"), 
                    new Claim(Constants.ClaimTypes.Role, "Foo")
                }
            }
        };
    }
}

我认为这几乎就是从样本中转录而来的。 Startup 被重构了一点,所以我可以研究这些部分。我错过了什么?

TIA

【问题讨论】:

  • 我在 Chrome 中禁用了 Skype 解析器,但问题仍然存在,只是循环的第 4 步没有发生。

标签: asp.net-mvc thinktecture-ident-server


【解决方案1】:

我一定是看错了文章。我下载了应用程序的源代码,发现有很多部分我没有编码。示例中包含的源代码按预期执行。我需要了解更多。

【讨论】:

    猜你喜欢
    • 2016-04-26
    • 1970-01-01
    • 2016-01-26
    • 2012-07-06
    • 1970-01-01
    • 1970-01-01
    • 2017-05-20
    • 1970-01-01
    • 2010-12-03
    相关资源
    最近更新 更多