mirror of https://github.com/abpframework/abp.git
csharpabpc-sharpframeworkblazoraspnet-coredotnet-coreaspnetcorearchitecturesaasdomain-driven-designangularmulti-tenancy
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.5 KiB
54 lines
1.5 KiB
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, "test-client", "secret");
|
|
var tokenResponse = await tokenClient.RequestClientCredentialsAsync("api1");
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|