4 Create client to access the protected Api - AbassiOmar/IdentityServer4 GitHub Wiki

  1. Create an console application to access the protected ressource (ProtectedApi project)

  2. in the main methode we'll use the Httpclient Class to try access to the protectedApi and get the claims data Add the IdentityModel package Nuget to poject

    step1: get the discovery document for our server of identity we use the DetDiscoveryDocumentAsync("http://localhost:5000"); methode step2: get the credential of client we use
    var tokenResponse = client.RequestClientCredentialsTokenAsync(new ClientCredentialsTokenRequest { Address = disco.Result.TokenEndpoint, ClientId = "client", ClientSecret = "secret", Scope = "protectedApi" }); ClientId : is registred in our server of identity actually in Config.cs file Scope : the allowed scope regidtred in config.cs for the client