Skip to content

Commit

Permalink
code clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
damienbod committed Jan 5, 2025
1 parent b508e3a commit 8ca63a8
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 48 deletions.
12 changes: 5 additions & 7 deletions BlazorAuth0Bff/Client/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
10 changes: 2 additions & 8 deletions BlazorAuth0Bff/Server/Controllers/CallUserApiController.cs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -24,7 +18,7 @@ public async Task<IActionResult> GetAsync()
{
// call user API
string? accessToken = await HttpContext.GetTokenAsync("access_token");
if(accessToken != null)
if (accessToken != null)
{
var userData = await _myApiUserOneClient.GetUserOneApiData(accessToken);

Expand Down
8 changes: 3 additions & 5 deletions BlazorAuth0Bff/Server/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

4 changes: 2 additions & 2 deletions BlazorAuth0Bff/Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down
13 changes: 4 additions & 9 deletions BlazorAuth0Bff/Server/Services/Auth0CCTokenApiService.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -91,10 +86,10 @@ private async Task<AccessTokenResult> GetApiTokenClient(HttpClient client)
if (tokenResponse.StatusCode == System.Net.HttpStatusCode.OK)
{
var result = await tokenResponse.Content.ReadFromJsonAsync<AccessTokenItem>();
if(result != null)
if (result != null)
{
DateTime expirationTime = DateTimeOffset.FromUnixTimeSeconds(result.ExpiresIn).DateTime;

return new AccessTokenResult
{
AcessToken = result.AccessToken,
Expand Down
4 changes: 2 additions & 2 deletions BlazorAuth0Bff/Server/Services/MyApiServiceTwoClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public async Task<List<string>> 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");
Expand All @@ -36,7 +36,7 @@ public async Task<List<string>> GetServiceTwoApiData()
var data = await JsonSerializer.DeserializeAsync<List<string>>(
await response.Content.ReadAsStreamAsync());

if(data != null)
if (data != null)
return data;
}

Expand Down
4 changes: 2 additions & 2 deletions MyApi/Controllers/AzureADUserOneController.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
4 changes: 2 additions & 2 deletions MyApi/Controllers/ServiceTwoController.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
4 changes: 2 additions & 2 deletions MyApi/Controllers/UserOneController.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
2 changes: 1 addition & 1 deletion RazorMicrosoftEntraID/CallMyApiOne/MyApiOneService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public async Task<List<string>> GetApiDataAsync()
var responseContent = await response.Content.ReadAsStringAsync();
var data = System.Text.Json.JsonSerializer.Deserialize<List<string>>(responseContent);

if(data != null)
if (data != null)
return data;
}

Expand Down
2 changes: 1 addition & 1 deletion RazorMicrosoftEntraID/Pages/Error.cshtml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.Diagnostics;

namespace MicrosoftEntraID.Pages;

Expand Down
1 change: 0 additions & 1 deletion RazorMicrosoftEntraID/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using Microsoft.Identity.Web.UI;
using MicrosoftEntraID;
using NetEscapades.AspNetCore.SecurityHeaders.Infrastructure;
using System.Configuration;

var builder = WebApplication.CreateBuilder(args);

Expand Down

0 comments on commit 8ca63a8

Please sign in to comment.