57 lines
1.7 KiB
C#
57 lines
1.7 KiB
C#
using IdentityModel.Client;
|
|
using System;
|
|
using System.Net.Http;
|
|
|
|
namespace Client
|
|
{
|
|
class Program
|
|
{
|
|
static void Main(string[] args)
|
|
{
|
|
var response = GetClientToken();
|
|
CallApi(response);
|
|
|
|
//response = GetUserToken();
|
|
//CallApi(response);
|
|
}
|
|
|
|
static void CallApi(TokenResponse response)
|
|
{
|
|
var client = new HttpClient();
|
|
client.SetBearerToken(response.AccessToken);
|
|
|
|
Console.WriteLine(client.GetStringAsync("http://localhost:44399/api/StrongAuth/GetAuthUrl").Result);
|
|
}
|
|
|
|
static TokenResponse GetClientToken()
|
|
{
|
|
|
|
//new Client
|
|
//{
|
|
// ClientId = "client",
|
|
// ClientSecrets = { new Secret("9eR6Xvb5wztKMWfSsecret".Sha256()) },
|
|
// AllowedGrantTypes = GrantTypes.ClientCredentials,
|
|
// AllowedScopes = { "api1" }
|
|
//},
|
|
var client = new TokenClient(
|
|
//"http://win-jphfo4kpi87:5000/connect/token",
|
|
"http://localhost:5000/connect/token",
|
|
//"client",
|
|
"webapi",
|
|
//"9eR6Xvb5wztKMWfSsecret");
|
|
"F621F470-9731-4A25-80EF-67A6F7C5F4B8");
|
|
|
|
return client.RequestClientCredentialsAsync("api1").Result;
|
|
}
|
|
|
|
static TokenResponse GetUserToken()
|
|
{
|
|
var client = new TokenClient(
|
|
"http://localhost:5000/connect/token",
|
|
"carbon",
|
|
"21B5F798-BE55-42BC-8AA8-0025B903DC3B");
|
|
|
|
return client.RequestResourceOwnerPasswordAsync("bob", "secret", "api1").Result;
|
|
}
|
|
}
|
|
} |