Removing AuthService and fixing Dockerfile for PublicApi
This commit is contained in:
@@ -16,18 +16,15 @@ namespace BlazorAdmin
|
||||
// TODO: Get Default Cache Duration from Config
|
||||
private static readonly TimeSpan UserCacheRefreshInterval = TimeSpan.FromSeconds(60);
|
||||
|
||||
private readonly AuthService _authService;
|
||||
private readonly HttpClient _httpClient;
|
||||
private readonly ILogger<CustomAuthStateProvider> _logger;
|
||||
|
||||
private DateTimeOffset _userLastCheck = DateTimeOffset.FromUnixTimeSeconds(0);
|
||||
private ClaimsPrincipal _cachedUser = new ClaimsPrincipal(new ClaimsIdentity());
|
||||
|
||||
public CustomAuthStateProvider(AuthService authService,
|
||||
HttpClient httpClient,
|
||||
public CustomAuthStateProvider(HttpClient httpClient,
|
||||
ILogger<CustomAuthStateProvider> logger)
|
||||
{
|
||||
_authService = authService;
|
||||
_httpClient = httpClient;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
@inject ILogger<Create> Logger
|
||||
@inject AuthService Auth
|
||||
@inject IJSRuntime JSRuntime
|
||||
@inject ICatalogItemService CatalogItemService
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
@inject ILogger<Delete> Logger
|
||||
@inject AuthService Auth
|
||||
@inject IJSRuntime JSRuntime
|
||||
@inject ICatalogItemService CatalogItemService
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
@inject ILogger<Details> Logger
|
||||
@inject AuthService Auth
|
||||
@inject IJSRuntime JSRuntime
|
||||
@inject ICatalogItemService CatalogItemService
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
@inject ILogger<Edit> Logger
|
||||
@inject AuthService Auth
|
||||
@inject IJSRuntime JSRuntime
|
||||
@inject ICatalogItemService CatalogItemService
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
@page "/admin"
|
||||
@attribute [Authorize(Roles = BlazorShared.Authorization.Constants.Roles.ADMINISTRATORS)]
|
||||
@inject AuthService Auth
|
||||
@inherits BlazorAdmin.Helpers.BlazorComponent
|
||||
@namespace BlazorAdmin.Pages.CatalogItemPage
|
||||
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
@page "/logout"
|
||||
@inject AuthService AuthService
|
||||
@inject IJSRuntime JSRuntime
|
||||
@inject HttpClient HttpClient
|
||||
@inherits BlazorAdmin.Helpers.BlazorComponent
|
||||
|
||||
|
||||
@code {
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await AuthService.Logout();
|
||||
await HttpClient.PostAsync("Identity/Account/Logout", null);
|
||||
await new Route(JSRuntime).RouteOutside("/Identity/Account/Login");
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,6 @@ namespace BlazorAdmin
|
||||
builder.Services.AddScoped<HttpService>();
|
||||
|
||||
builder.Services.AddScoped<ILocalStorageService, LocalStorageService>();
|
||||
builder.Services.AddScoped<AuthService>();
|
||||
|
||||
builder.Services.AddAuthorizationCore();
|
||||
builder.Services.AddScoped<AuthenticationStateProvider, CustomAuthStateProvider>();
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
namespace BlazorAdmin.Services
|
||||
{
|
||||
public class AuthRequest
|
||||
{
|
||||
public string Username { get; set; }
|
||||
public string Password { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
namespace BlazorAdmin.Services
|
||||
{
|
||||
public class AuthResponse
|
||||
{
|
||||
public AuthResponse()
|
||||
{
|
||||
}
|
||||
|
||||
public bool Result { get; set; } = false;
|
||||
public string Token { get; set; } = string.Empty;
|
||||
public string Username { get; set; } = string.Empty;
|
||||
public bool IsLockedOut { get; set; } = false;
|
||||
public bool IsNotAllowed { get; set; } = false;
|
||||
public bool RequiresTwoFactor { get; set; } = false;
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using BlazorAdmin.JavaScript;
|
||||
using Blazored.LocalStorage;
|
||||
using Microsoft.JSInterop;
|
||||
|
||||
namespace BlazorAdmin.Services
|
||||
{
|
||||
public class AuthService
|
||||
{
|
||||
private readonly HttpClient _httpClient;
|
||||
private readonly ILocalStorageService _localStorage;
|
||||
private readonly IJSRuntime _jSRuntime;
|
||||
public bool IsLoggedIn { get; set; }
|
||||
|
||||
public AuthService(HttpClient httpClient,
|
||||
ILocalStorageService localStorage,
|
||||
IJSRuntime jSRuntime)
|
||||
{
|
||||
_httpClient = httpClient;
|
||||
_localStorage = localStorage;
|
||||
_jSRuntime = jSRuntime;
|
||||
}
|
||||
|
||||
public async Task Logout()
|
||||
{
|
||||
await DeleteCookies();
|
||||
IsLoggedIn = false;
|
||||
await LogoutIdentityManager();
|
||||
}
|
||||
|
||||
private async Task LogoutIdentityManager()
|
||||
{
|
||||
await _httpClient.PostAsync("Identity/Account/Logout", null);
|
||||
}
|
||||
|
||||
private async Task DeleteCookies()
|
||||
{
|
||||
await new Cookies(_jSRuntime).DeleteCookie("token");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,15 +6,18 @@ EXPOSE 80
|
||||
EXPOSE 443
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
|
||||
WORKDIR /src
|
||||
COPY ["src/PublicApi/PublicApi.csproj", "src/PublicApi/"]
|
||||
RUN dotnet restore "src/PublicApi/PublicApi.csproj"
|
||||
WORKDIR /app
|
||||
COPY . .
|
||||
WORKDIR "/src/src/PublicApi"
|
||||
RUN dotnet build "PublicApi.csproj" -c Release -o /app/build
|
||||
#COPY ["src/PublicApi/PublicApi.csproj", "./PublicApi/"]
|
||||
#RUN dotnet restore "./PublicApi/PublicApi.csproj"
|
||||
#COPY . .
|
||||
WORKDIR "/app/src/PublicApi"
|
||||
RUN dotnet restore
|
||||
|
||||
RUN dotnet build "./PublicApi.csproj" -c Release -o /app/build
|
||||
|
||||
FROM build AS publish
|
||||
RUN dotnet publish "PublicApi.csproj" -c Release -o /app/publish
|
||||
RUN dotnet publish "./PublicApi.csproj" -c Release -o /app/publish
|
||||
|
||||
FROM base AS final
|
||||
WORKDIR /app
|
||||
|
||||
@@ -157,7 +157,6 @@ namespace Microsoft.eShopWeb.Web
|
||||
// add blazor services
|
||||
services.AddBlazoredLocalStorage();
|
||||
services.AddServerSideBlazor();
|
||||
services.AddScoped<AuthService>();
|
||||
|
||||
services.AddScoped<HttpService>();
|
||||
services.AddBlazorServices();
|
||||
|
||||
Reference in New Issue
Block a user