Search code examples
c#jwttokenidentityserver4c#-2.0

IdentityServer4 how to create identity token?


I follow several tutorials and the IdentityServer4 documentation and its terminology : Terminology But I do not understand which endpoint to get a id token for a user. I thought I can change the existing way to have access token to get the id token, but none of method give a result :

        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;

I understand that resourceownerpassword way is only for access to a resource using the password, not for identify the user.

When i tried to configure my jwtendpoint, i thought i can ask a id token but no result :

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

I don't know which endpoint user to get the jwt id token.


Solution

  • You can't get identity tokens with password grant.

    The endpoint to use to get an identity token is the Authorize EndPoint but you can't use password grant with this endpoint.

    You can access user information (claims) from the UserInfo Endpoint using the access token