mirror of
https://github.com/ditkrg/AuthorizationServerDemos.git
synced 2026-01-22 22:47:02 +00:00
tax app now asks for real estate too
This commit is contained in:
parent
b0a0eb7a18
commit
536944aa05
@ -137,6 +137,7 @@ namespace OidcSamples.AuthorizationServer
|
||||
IdentityServerConstants.StandardScopes.Address,
|
||||
IdentityServerConstants.StandardScopes.Email,
|
||||
"traffic-police-api",
|
||||
"real-estate-api",
|
||||
},
|
||||
ClientSecrets =
|
||||
{
|
||||
|
||||
@ -26,6 +26,14 @@ namespace OidcSamples.TaxApp.Pages
|
||||
public VehicleType Type { get; set; }
|
||||
}
|
||||
|
||||
public class RealEstate
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int Area { get; set; }
|
||||
public string Address { get; set; }
|
||||
public string Citizen_upn { get; set; }
|
||||
}
|
||||
|
||||
[Authorize] //(AuthenticationSchemes = CookieAuthenticationDefaults.AuthenticationScheme)]
|
||||
public class IndexModel : PageModel
|
||||
{
|
||||
@ -43,29 +51,61 @@ namespace OidcSamples.TaxApp.Pages
|
||||
public decimal TotalTax { get; set; }
|
||||
|
||||
public List<Vehicle> Vehicles { get; set; }
|
||||
public List<RealEstate> RealEstate { get; set; }
|
||||
|
||||
public async Task OnGet()
|
||||
{
|
||||
var client = _httpClientFactory.CreateClient("APIClient");
|
||||
var response = await client.GetAsync($"/api/vehicles");
|
||||
var tpClient = _httpClientFactory.CreateClient("TP-APIClient");
|
||||
var tpResponse = await tpClient.GetAsync($"/api/vehicles");
|
||||
|
||||
if (response.IsSuccessStatusCode)
|
||||
Vehicles = await GetVehicles();
|
||||
RealEstate = await GetRealEstate();
|
||||
|
||||
TotalTax = Vehicles.Sum(v => 20_000) + RealEstate.Sum(r => 100_000);
|
||||
|
||||
FirstName = User.Claims.First(c => c.Type == "given_name").Value;
|
||||
LastName = User.Claims.First(c => c.Type == "family_name").Value;
|
||||
}
|
||||
|
||||
private async Task<List<Vehicle>> GetVehicles()
|
||||
{
|
||||
using (var responseStream = await response.Content.ReadAsStreamAsync())
|
||||
var tpClient = _httpClientFactory.CreateClient("TP-APIClient");
|
||||
var tpResponse = await tpClient.GetAsync($"/api/vehicles");
|
||||
|
||||
if (tpResponse.IsSuccessStatusCode)
|
||||
{
|
||||
Vehicles = await JsonSerializer.DeserializeAsync<List<Vehicle>>(responseStream, new JsonSerializerOptions
|
||||
using (var responseStream = await tpResponse.Content.ReadAsStreamAsync())
|
||||
{
|
||||
return await JsonSerializer.DeserializeAsync<List<Vehicle>>(responseStream, new JsonSerializerOptions
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
});
|
||||
|
||||
TotalTax = Vehicles.Sum(v => 20_000);
|
||||
FirstName = User.Claims.First(c => c.Type == "given_name").Value;
|
||||
LastName = User.Claims.First(c => c.Type == "family_name").Value;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new System.Exception("Problem accessing the API");
|
||||
throw new System.Exception("Problem accessing Traffic Police the API");
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<List<RealEstate>> GetRealEstate()
|
||||
{
|
||||
var tpClient = _httpClientFactory.CreateClient("RE-APIClient");
|
||||
var tpResponse = await tpClient.GetAsync($"/real-estate");
|
||||
|
||||
if (tpResponse.IsSuccessStatusCode)
|
||||
{
|
||||
using (var responseStream = await tpResponse.Content.ReadAsStreamAsync())
|
||||
{
|
||||
return await JsonSerializer.DeserializeAsync<List<RealEstate>>(responseStream, new JsonSerializerOptions
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new System.Exception("Problem accessing the Real Estate API");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -65,6 +65,7 @@ namespace OidcSamples.TaxApp
|
||||
options.UsePkce = true;
|
||||
|
||||
options.Scope.Add("traffic-police-api");
|
||||
options.Scope.Add("real-estate-api");
|
||||
options.Scope.Add("offline_access");
|
||||
options.Scope.Add("profile");
|
||||
options.Scope.Add("email");
|
||||
@ -83,13 +84,20 @@ namespace OidcSamples.TaxApp
|
||||
services.AddTransient<BearerTokenHandler>();
|
||||
|
||||
// create an HttpClient used for accessing the API
|
||||
services.AddHttpClient("APIClient", client =>
|
||||
services.AddHttpClient("TP-APIClient", client =>
|
||||
{
|
||||
client.BaseAddress = new Uri("http://localhost:9000/");
|
||||
client.DefaultRequestHeaders.Clear();
|
||||
client.DefaultRequestHeaders.Add(HeaderNames.Accept, "application/json");
|
||||
}).AddHttpMessageHandler<BearerTokenHandler>();
|
||||
|
||||
services.AddHttpClient("RE-APIClient", client =>
|
||||
{
|
||||
client.BaseAddress = new Uri("http://localhost:8000/");
|
||||
client.DefaultRequestHeaders.Clear();
|
||||
client.DefaultRequestHeaders.Add(HeaderNames.Accept, "application/json");
|
||||
}).AddHttpMessageHandler<BearerTokenHandler>();
|
||||
|
||||
services.AddHttpClient("IDPClient", client =>
|
||||
{
|
||||
client.BaseAddress = new Uri("http://localhost:10000/");
|
||||
|
||||
16282
React/real-estate/package-lock.json
generated
16282
React/real-estate/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user