.net core .Net Core 3.1作为独立身份服务器

.net core .Net Core 3.1作为独立身份服务器,.net-core,jwt,identityserver4,asp.net-core-3.1,encryption-asymmetric,.net Core,Jwt,Identityserver4,Asp.net Core 3.1,Encryption Asymmetric,我想使用.Net Core 3.1 web应用程序来允许应用程序(例如iPhone或web Javascript)使用用户名和密码进行身份验证,并接收包含用户声明的Jason web令牌(JWT)。。。如果成功,那么JWT可以作为承载令牌发送给API,该API将解码和验证JWT(该令牌是不对称的,并使用公钥/私钥对),并检索嵌入的任何声明。。。如果应用程序能够解码JWT以检索任何声明,那么这可能是一个额外的好处 有没有想过这种方法是否可行?而且,如果有任何关于如何做到这一点的讨论或例子,那将是非

我想使用.Net Core 3.1 web应用程序来允许应用程序(例如iPhone或web Javascript)使用用户名和密码进行身份验证,并接收包含用户声明的Jason web令牌(JWT)。。。如果成功,那么JWT可以作为承载令牌发送给API,该API将解码和验证JWT(该令牌是不对称的,并使用公钥/私钥对),并检索嵌入的任何声明。。。如果应用程序能够解码JWT以检索任何声明,那么这可能是一个额外的好处

有没有想过这种方法是否可行?而且,如果有任何关于如何做到这一点的讨论或例子,那将是非常棒的


看看IdentityServer 4提供的示例。此示例/快速入门包括您正在描述的案例

API必须是IdentityServer4配置中的作用域。它与权限(IdentityServer4)有连接:

该客户机(在本例中为MVC客户机)需要是IdentityServer4中的客户机。格兰特类型有很多种


希望这对您有所帮助

看看IdentityServer 4提供的示例。此示例/快速入门包括您正在描述的案例

API必须是IdentityServer4配置中的作用域。它与权限(IdentityServer4)有连接:

该客户机(在本例中为MVC客户机)需要是IdentityServer4中的客户机。格兰特类型有很多种

希望这对你有帮助

services.AddAuthentication("Bearer")
                .AddJwtBearer("Bearer", options =>
                {
                    options.Authority = "https://localhost:5001";
                    
                    options.TokenValidationParameters = new TokenValidationParameters
                    {
                        ValidateAudience = false
                    };
                });
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;
            });