Added console client

pull/570/head
Halil ibrahim Kalkan 7 years ago
parent f431152544
commit 663ce77700

@ -39,6 +39,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MyCompanyName.MyProjectName
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IdentityServerHost", "host\IdentityServerHost\IdentityServerHost.csproj", "{3F3E0DCA-DA28-42FA-ABC8-F49E5A920D68}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleClient", "host\ConsoleClient\ConsoleClient.csproj", "{2A9E859C-BB5A-4A10-BB33-97ECBF10A8C8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -105,6 +107,10 @@ Global
{3F3E0DCA-DA28-42FA-ABC8-F49E5A920D68}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3F3E0DCA-DA28-42FA-ABC8-F49E5A920D68}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3F3E0DCA-DA28-42FA-ABC8-F49E5A920D68}.Release|Any CPU.Build.0 = Release|Any CPU
{2A9E859C-BB5A-4A10-BB33-97ECBF10A8C8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2A9E859C-BB5A-4A10-BB33-97ECBF10A8C8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2A9E859C-BB5A-4A10-BB33-97ECBF10A8C8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2A9E859C-BB5A-4A10-BB33-97ECBF10A8C8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -125,6 +131,7 @@ Global
{13A9EAD6-F3A4-4357-BA4A-A7E8FEB4A264} = {CCD2960C-23CC-4AB4-B84D-60C7AAA52F4D}
{E7353C9A-4357-4A40-A39A-52B73F5A0CA1} = {E400416D-2895-4512-9D17-90681EEC7E0A}
{3F3E0DCA-DA28-42FA-ABC8-F49E5A920D68} = {E400416D-2895-4512-9D17-90681EEC7E0A}
{2A9E859C-BB5A-4A10-BB33-97ECBF10A8C8} = {E400416D-2895-4512-9D17-90681EEC7E0A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4324B3B4-B60B-4E3C-91D8-59576B4E26DD}

@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="IdentityModel" Version="3.10.1" />
</ItemGroup>
</Project>

@ -0,0 +1,54 @@
using System;
using System.Net.Http;
using System.Threading.Tasks;
using IdentityModel.Client;
namespace ConsoleClient
{
class Program
{
static void Main(string[] args)
{
RunDemo().Wait();
Console.ReadLine();
}
private static async Task RunDemo()
{
// discover endpoints from metadata
var disco = await DiscoveryClient.GetAsync("http://localhost:61517");
if (disco.IsError)
{
Console.WriteLine(disco.Error);
return;
}
// request token
var tokenClient = new TokenClient(disco.TokenEndpoint, "client", "secret");
var tokenResponse = await tokenClient.RequestClientCredentialsAsync("multi-tenancy-api");
if (tokenResponse.IsError)
{
Console.WriteLine(tokenResponse.Error);
return;
}
Console.WriteLine(tokenResponse.Json);
// call api
var client = new HttpClient();
client.SetBearerToken(tokenResponse.AccessToken);
var response = await client.GetAsync("http://localhost:57992/api/MyProjectName/todos/");
if (!response.IsSuccessStatusCode)
{
Console.WriteLine(response.StatusCode);
}
else
{
var content = await response.Content.ReadAsStringAsync();
Console.WriteLine(content);
}
}
}
}
Loading…
Cancel
Save