diff --git a/BlazorAuth0Bff/Client/GlobalUsings.cs b/BlazorAuth0Bff/Client/GlobalUsings.cs index 36f172f..a78f1bc 100644 --- a/BlazorAuth0Bff/Client/GlobalUsings.cs +++ b/BlazorAuth0Bff/Client/GlobalUsings.cs @@ -1,15 +1,13 @@ -global using System.Net; -global using System.Net.Http.Headers; -global using System.Net.Http.Json; -global using System.Security.Claims; - -global using BlazorAuth0Bff.Client; +global using BlazorAuth0Bff.Client; global using BlazorAuth0Bff.Client.Services; global using BlazorAuth0Bff.Shared.Authorization; global using BlazorAuth0Bff.Shared.Defaults; - global using Microsoft.AspNetCore.Components; global using Microsoft.AspNetCore.Components.Authorization; global using Microsoft.AspNetCore.Components.WebAssembly.Hosting; global using Microsoft.Extensions.DependencyInjection.Extensions; global using Microsoft.JSInterop; +global using System.Net; +global using System.Net.Http.Headers; +global using System.Net.Http.Json; +global using System.Security.Claims; diff --git a/BlazorAuth0Bff/Server/Controllers/CallServiceApiController.cs b/BlazorAuth0Bff/Server/Controllers/CallServiceApiController.cs index 2cf8bcf..be226b3 100644 --- a/BlazorAuth0Bff/Server/Controllers/CallServiceApiController.cs +++ b/BlazorAuth0Bff/Server/Controllers/CallServiceApiController.cs @@ -1,9 +1,4 @@ -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authentication.Cookies; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; - -namespace BlazorAuth0Bff.Server.Controllers; +namespace BlazorAuth0Bff.Server.Controllers; [ValidateAntiForgeryToken] [Authorize(AuthenticationSchemes = CookieAuthenticationDefaults.AuthenticationScheme)] diff --git a/BlazorAuth0Bff/Server/Controllers/CallUserApiController.cs b/BlazorAuth0Bff/Server/Controllers/CallUserApiController.cs index ed3126d..d72989e 100644 --- a/BlazorAuth0Bff/Server/Controllers/CallUserApiController.cs +++ b/BlazorAuth0Bff/Server/Controllers/CallUserApiController.cs @@ -1,10 +1,4 @@ -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Authentication.Cookies; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; - -namespace BlazorAuth0Bff.Server.Controllers; +namespace BlazorAuth0Bff.Server.Controllers; [ValidateAntiForgeryToken] [Authorize(AuthenticationSchemes = CookieAuthenticationDefaults.AuthenticationScheme)] @@ -24,7 +18,7 @@ public async Task GetAsync() { // call user API string? accessToken = await HttpContext.GetTokenAsync("access_token"); - if(accessToken != null) + if (accessToken != null) { var userData = await _myApiUserOneClient.GetUserOneApiData(accessToken); diff --git a/BlazorAuth0Bff/Server/GlobalUsings.cs b/BlazorAuth0Bff/Server/GlobalUsings.cs index 4c41559..47705db 100644 --- a/BlazorAuth0Bff/Server/GlobalUsings.cs +++ b/BlazorAuth0Bff/Server/GlobalUsings.cs @@ -1,11 +1,7 @@ -global using System.Diagnostics; -global using System.Security.Claims; - -global using BlazorAuth0Bff.Server; +global using BlazorAuth0Bff.Server; global using BlazorAuth0Bff.Server.Services; global using BlazorAuth0Bff.Shared.Authorization; global using BlazorAuth0Bff.Shared.Defaults; - global using Microsoft.AspNetCore.Authentication; global using Microsoft.AspNetCore.Authentication.Cookies; global using Microsoft.AspNetCore.Authentication.OpenIdConnect; @@ -14,4 +10,6 @@ global using Microsoft.AspNetCore.Mvc; global using Microsoft.AspNetCore.Mvc.RazorPages; global using Microsoft.IdentityModel.Protocols.OpenIdConnect; +global using System.Diagnostics; +global using System.Security.Claims; diff --git a/BlazorAuth0Bff/Server/Program.cs b/BlazorAuth0Bff/Server/Program.cs index e12b76d..2a4daf3 100644 --- a/BlazorAuth0Bff/Server/Program.cs +++ b/BlazorAuth0Bff/Server/Program.cs @@ -11,8 +11,8 @@ services.AddSecurityHeaderPolicies() .SetPolicySelector((PolicySelectorContext ctx) => { - return SecurityHeadersDefinitions.GetHeaderPolicyCollection( - builder.Environment.IsDevelopment(), idp); + return SecurityHeadersDefinitions.GetHeaderPolicyCollection( + builder.Environment.IsDevelopment(), idp); }); services.AddAntiforgery(options => diff --git a/BlazorAuth0Bff/Server/Services/Auth0CCTokenApiService.cs b/BlazorAuth0Bff/Server/Services/Auth0CCTokenApiService.cs index 5ce8e2e..da0f4e7 100644 --- a/BlazorAuth0Bff/Server/Services/Auth0CCTokenApiService.cs +++ b/BlazorAuth0Bff/Server/Services/Auth0CCTokenApiService.cs @@ -1,12 +1,7 @@ -using System; -using System.Threading.Tasks; -using Microsoft.Extensions.Caching.Distributed; -using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Caching.Distributed; using Microsoft.Extensions.Options; -using System.Net.Http; -using System.Net.Http.Json; -using System.Text.Json.Serialization; using System.Text.Json; +using System.Text.Json.Serialization; namespace BlazorAuth0Bff.Server; @@ -91,10 +86,10 @@ private async Task GetApiTokenClient(HttpClient client) if (tokenResponse.StatusCode == System.Net.HttpStatusCode.OK) { var result = await tokenResponse.Content.ReadFromJsonAsync(); - if(result != null) + if (result != null) { DateTime expirationTime = DateTimeOffset.FromUnixTimeSeconds(result.ExpiresIn).DateTime; - + return new AccessTokenResult { AcessToken = result.AccessToken, diff --git a/BlazorAuth0Bff/Server/Services/MyApiServiceTwoClient.cs b/BlazorAuth0Bff/Server/Services/MyApiServiceTwoClient.cs index b368aec..8de52ab 100644 --- a/BlazorAuth0Bff/Server/Services/MyApiServiceTwoClient.cs +++ b/BlazorAuth0Bff/Server/Services/MyApiServiceTwoClient.cs @@ -27,7 +27,7 @@ public async Task> GetServiceTwoApiData() var access_token = await _auth0TokenApiService.GetApiToken(client, "ServiceTwoApi"); - client.DefaultRequestHeaders.Authorization + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", access_token); var response = await client.GetAsync("api/ServiceTwo"); @@ -36,7 +36,7 @@ public async Task> GetServiceTwoApiData() var data = await JsonSerializer.DeserializeAsync>( await response.Content.ReadAsStreamAsync()); - if(data != null) + if (data != null) return data; } diff --git a/MyApi/Controllers/AzureADUserOneController.cs b/MyApi/Controllers/AzureADUserOneController.cs index 55eaa84..9cdd026 100644 --- a/MyApi/Controllers/AzureADUserOneController.cs +++ b/MyApi/Controllers/AzureADUserOneController.cs @@ -1,9 +1,9 @@ -using System.Collections.Generic; -using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Identity.Web; using Swashbuckle.AspNetCore.Annotations; +using System.Collections.Generic; namespace MyApi.Controllers; diff --git a/MyApi/Controllers/ServiceTwoController.cs b/MyApi/Controllers/ServiceTwoController.cs index d35171e..7646894 100644 --- a/MyApi/Controllers/ServiceTwoController.cs +++ b/MyApi/Controllers/ServiceTwoController.cs @@ -1,8 +1,8 @@ -using System.Collections.Generic; -using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Swashbuckle.AspNetCore.Annotations; +using System.Collections.Generic; namespace MyApi.Controllers; diff --git a/MyApi/Controllers/UserOneController.cs b/MyApi/Controllers/UserOneController.cs index e77fac7..8ade4f2 100644 --- a/MyApi/Controllers/UserOneController.cs +++ b/MyApi/Controllers/UserOneController.cs @@ -1,8 +1,8 @@ -using System.Collections.Generic; -using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Swashbuckle.AspNetCore.Annotations; +using System.Collections.Generic; namespace MyApi.Controllers; diff --git a/RazorMicrosoftEntraID/CallMyApiOne/MyApiOneService.cs b/RazorMicrosoftEntraID/CallMyApiOne/MyApiOneService.cs index 3e2d192..9eba962 100644 --- a/RazorMicrosoftEntraID/CallMyApiOne/MyApiOneService.cs +++ b/RazorMicrosoftEntraID/CallMyApiOne/MyApiOneService.cs @@ -40,7 +40,7 @@ public async Task> GetApiDataAsync() var responseContent = await response.Content.ReadAsStringAsync(); var data = System.Text.Json.JsonSerializer.Deserialize>(responseContent); - if(data != null) + if (data != null) return data; } diff --git a/RazorMicrosoftEntraID/Pages/Error.cshtml.cs b/RazorMicrosoftEntraID/Pages/Error.cshtml.cs index f91b888..366edaf 100644 --- a/RazorMicrosoftEntraID/Pages/Error.cshtml.cs +++ b/RazorMicrosoftEntraID/Pages/Error.cshtml.cs @@ -1,6 +1,6 @@ -using System.Diagnostics; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; +using System.Diagnostics; namespace MicrosoftEntraID.Pages; diff --git a/RazorMicrosoftEntraID/Program.cs b/RazorMicrosoftEntraID/Program.cs index a7ee3de..7eede5e 100644 --- a/RazorMicrosoftEntraID/Program.cs +++ b/RazorMicrosoftEntraID/Program.cs @@ -8,7 +8,6 @@ using Microsoft.Identity.Web.UI; using MicrosoftEntraID; using NetEscapades.AspNetCore.SecurityHeaders.Infrastructure; -using System.Configuration; var builder = WebApplication.CreateBuilder(args);