Skip to content

Commit

Permalink
style: format code with dotnet-format
Browse files Browse the repository at this point in the history
This commit fixes the style issues introduced in f8f9739 according to the output
from dotnet-format.

Details: None
  • Loading branch information
deepsource-autofix[bot] authored Mar 2, 2024
1 parent f8f9739 commit a3f5b46
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,35 @@ namespace Dgmjr.Blazor.Security.Services;
using Dgmjr.Blazor.Security.Models;
public class ApplicationAuthenticationStateProvider(ISecurityService securityService) : AuthenticationStateProvider
{
private ApplicationAuthenticationState? _authenticationState;

public override async Task<AuthenticationState> GetAuthenticationStateAsync()
{
var identity = new ClaimsIdentity();

try
{
var state = await GetApplicationAuthenticationStateAsync();

if (state.IsAuthenticated)
{
identity = new ClaimsIdentity(
state.Claims.Select(c => new Claim(c.Type, c.Value)),
BlazorSecurityConstants.BlazorSecurity
);
}
}
catch (HttpRequestException) { /* swallow the exception */ }

var result = new AuthenticationState(new ClaimsPrincipal(identity));

securityService.Initialize(result);

return result;
}

private async Task<ApplicationAuthenticationState> GetApplicationAuthenticationStateAsync()
{
return _authenticationState ??= await securityService.GetAuthenticationStateAsync();
}
private ApplicationAuthenticationState? _authenticationState;

public override async Task<AuthenticationState> GetAuthenticationStateAsync()
{
var identity = new ClaimsIdentity();

try
{
var state = await GetApplicationAuthenticationStateAsync();

if (state.IsAuthenticated)
{
identity = new ClaimsIdentity(
state.Claims.Select(c => new Claim(c.Type, c.Value)),
BlazorSecurityConstants.BlazorSecurity
);
}
}
catch (HttpRequestException) { /* swallow the exception */ }

var result = new AuthenticationState(new ClaimsPrincipal(identity));

securityService.Initialize(result);

return result;
}

private async Task<ApplicationAuthenticationState> GetApplicationAuthenticationStateAsync()
{
return _authenticationState ??= await securityService.GetAuthenticationStateAsync();
}
}
82 changes: 41 additions & 41 deletions src/Blazor.Security/Services/SecurityService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,45 +18,45 @@ namespace Dgmjr.Blazor.Security.Services;

public class SecurityService(NavigationManager navigationManager, IHttpClientFactory factory) : ISecurityService
{
private readonly HttpClient _httpClient = factory.CreateClient(BlazorSecurityConstants.BlazorSecurity);

public ApplicationUser User { get; private set; } = new ApplicationUser { Name = "Anonymous" };

public ClaimsPrincipal Principal { get; private set; }

public async Task<ApplicationAuthenticationState> GetAuthenticationStateAsync()
{
var uri = new Uri($"{navigationManager.BaseUri}{Uris.CurrentUser}");

var response = await _httpClient.SendAsync(new HttpRequestMessage(HttpMethod.Post, uri));

return await response.ReadAsync<ApplicationAuthenticationState>();
}

public bool IsInRole(params string[] roles)
=> roles.Contains("Everybody")
|| (IsAuthenticated() && (roles.Contains("Authenticated") || Exists(roles, role => Principal.IsInRole(role))));

public bool IsAuthenticated()
=> Principal?.Identity.IsAuthenticated == true;

public bool Initialize(AuthenticationState result)
{
Principal = result.User;

var name = Principal.FindFirstValue(ClaimTypes.Name) ?? Principal.FindFirstValue("name");

if (name != null)
{
User = new ApplicationUser { Name = name };
}

return IsAuthenticated();
}

public void Logout()
=> navigationManager.NavigateTo(Uris.Logout, true);

public void Login()
=> navigationManager.NavigateTo(Uris.Login, true);
private readonly HttpClient _httpClient = factory.CreateClient(BlazorSecurityConstants.BlazorSecurity);

public ApplicationUser User { get; private set; } = new ApplicationUser { Name = "Anonymous" };

public ClaimsPrincipal Principal { get; private set; }

public async Task<ApplicationAuthenticationState> GetAuthenticationStateAsync()
{
var uri = new Uri($"{navigationManager.BaseUri}{Uris.CurrentUser}");

var response = await _httpClient.SendAsync(new HttpRequestMessage(HttpMethod.Post, uri));

return await response.ReadAsync<ApplicationAuthenticationState>();
}

public bool IsInRole(params string[] roles)
=> roles.Contains("Everybody")
|| (IsAuthenticated() && (roles.Contains("Authenticated") || Exists(roles, role => Principal.IsInRole(role))));

public bool IsAuthenticated()
=> Principal?.Identity.IsAuthenticated == true;

public bool Initialize(AuthenticationState result)
{
Principal = result.User;

var name = Principal.FindFirstValue(ClaimTypes.Name) ?? Principal.FindFirstValue("name");

if (name != null)
{
User = new ApplicationUser { Name = name };
}

return IsAuthenticated();
}

public void Logout()
=> navigationManager.NavigateTo(Uris.Logout, true);

public void Login()
=> navigationManager.NavigateTo(Uris.Login, true);
}

0 comments on commit a3f5b46

Please sign in to comment.