【问题标题】:.Net Core 3.1 as a standalone Identity Server.Net Core 3.1 作为独立的身份服务器
【发布时间】:2020-11-01 13:08:53
【问题描述】:

我想使用 .Net Core 3.1 网络应用程序来允许应用程序(例如 iPhone 或 Web Javascript)使用用户名和密码进行身份验证,并接收包含有关用户声明的 Jason Web 令牌 (JWT)。 . 如果成功,则 JWT 可以作为不记名令牌发送到 API,该 API 将解码和验证 JWT(令牌将是非对称的并使用公钥/私钥对)并检索嵌入的任何声明......如果应用程序也可以解码 JWT 以检索任何声明,这可能是一个奖励。

对这种方法是否可行有任何想法吗?而且,如果有任何关于如何做到这一点的讨论或示例,那就太好了。

【问题讨论】:

    标签: .net-core jwt identityserver4 asp.net-core-3.1 encryption-asymmetric


    【解决方案1】:

    查看 IdentityServer4 提供的示例。此示例/快速入门包括您所描述的案例。 https://github.com/IdentityServer/IdentityServer4/tree/main/samples/Quickstarts/6_AspNetIdentity/src

    API 需要是 IdentityServer4 配置中的一个范围。它与权限(IdentityServer4)有连接:

    services.AddAuthentication("Bearer")
                    .AddJwtBearer("Bearer", options =>
                    {
                        options.Authority = "https://localhost:5001";
                        
                        options.TokenValidationParameters = new TokenValidationParameters
                        {
                            ValidateAudience = false
                        };
                    });
    

    客户端,在本例中为 MVC 客户端,需要是 IdentityServer4 中的客户端。 GrantType 有多种类型。 https://identityserver4.readthedocs.io/en/latest/topics/grant_types.html

    services.AddAuthentication(options =>
                {
                    options.DefaultScheme = "Cookies";
                    options.DefaultChallengeScheme = "oidc";
                })
                .AddCookie("Cookies")
                .AddOpenIdConnect("oidc", options =>
                {
                    options.Authority = "https://localhost:5001";
    
                    options.ClientId = "mvc";
                    options.ClientSecret = "secret";
                    options.ResponseType = "code";
                    
                    options.Scope.Add("api1");
    
                    options.SaveTokens = true;
                });
    

    希望对你有所帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-01
      • 2021-04-16
      • 2020-10-08
      • 2020-05-07
      • 2021-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多