mirror of https://github.com/abpframework/abp.git
3 changed files with 73 additions and 0 deletions
@ -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…
Reference in new issue