IdentityServer4 如何创建身份令牌?

IdentityServer4 how to create identity token?

我遵循了几个教程和 IdentityServer4 文档及其术语:Terminology 但我不明白哪个端点可以为用户获取 id 令牌。 我想我可以改变现有的方式来获得访问令牌来获取 id 令牌,但是 none 方法给出了结果:

        var disco = new DiscoveryClient("http://localhost:55678");
        var discoResponse = disco.GetAsync().Result;
        if (discoResponse.IsError)
        {
            return null;
        }

        var tokenClient = new TokenClient(discoResponse.TokenEndpoint, "mvc", "secret");
        var tokenResponse = tokenClient.RequestResourceOwnerPasswordAsync(context.EmailAddress, context.Password, "email");
        var token = tokenResponse.Result;

我了解resourceownerpassword方式仅用于使用密码访问资源,不用于识别用户。

当我尝试配置我的 jwtendpoint 时,我想我可以询问一个 id 令牌但没有结果:

        services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(opts =>
            {
                opts.Authority = "http://localhost:55678/";
                opts.Audience = "api1";
                opts.RequireHttpsMetadata = false;
                opts.SaveToken = true;
            });

我不知道哪个端点用户可以获取 jwt id 令牌。

您无法通过密码授予获得身份令牌

用于获取身份令牌的端点是Authorize EndPoint,但您不能使用密码授予这个端点。

您可以使用 访问令牌

UserInfo Endpoint 访问用户信息(声明)