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
|
// TODO: Get Default Cache Duration from Config
|
||||||
private static readonly TimeSpan UserCacheRefreshInterval = TimeSpan.FromSeconds(60);
|
private static readonly TimeSpan UserCacheRefreshInterval = TimeSpan.FromSeconds(60);
|
||||||
|
|
||||||
private readonly AuthService _authService;
|
|
||||||
private readonly HttpClient _httpClient;
|
private readonly HttpClient _httpClient;
|
||||||
private readonly ILogger<CustomAuthStateProvider> _logger;
|
private readonly ILogger<CustomAuthStateProvider> _logger;
|
||||||
|
|
||||||
private DateTimeOffset _userLastCheck = DateTimeOffset.FromUnixTimeSeconds(0);
|
private DateTimeOffset _userLastCheck = DateTimeOffset.FromUnixTimeSeconds(0);
|
||||||
private ClaimsPrincipal _cachedUser = new ClaimsPrincipal(new ClaimsIdentity());
|
private ClaimsPrincipal _cachedUser = new ClaimsPrincipal(new ClaimsIdentity());
|
||||||
|
|
||||||
public CustomAuthStateProvider(AuthService authService,
|
public CustomAuthStateProvider(HttpClient httpClient,
|
||||||
HttpClient httpClient,
|
|
||||||
ILogger<CustomAuthStateProvider> logger)
|
ILogger<CustomAuthStateProvider> logger)
|
||||||
{
|
{
|
||||||
_authService = authService;
|
|
||||||
_httpClient = httpClient;
|
_httpClient = httpClient;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
@inject ILogger<Create> Logger
|
@inject ILogger<Create> Logger
|
||||||
@inject AuthService Auth
|
|
||||||
@inject IJSRuntime JSRuntime
|
@inject IJSRuntime JSRuntime
|
||||||
@inject ICatalogItemService CatalogItemService
|
@inject ICatalogItemService CatalogItemService
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
@inject ILogger<Delete> Logger
|
@inject ILogger<Delete> Logger
|
||||||
@inject AuthService Auth
|
|
||||||
@inject IJSRuntime JSRuntime
|
@inject IJSRuntime JSRuntime
|
||||||
@inject ICatalogItemService CatalogItemService
|
@inject ICatalogItemService CatalogItemService
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
@inject ILogger<Details> Logger
|
@inject ILogger<Details> Logger
|
||||||
@inject AuthService Auth
|
|
||||||
@inject IJSRuntime JSRuntime
|
@inject IJSRuntime JSRuntime
|
||||||
@inject ICatalogItemService CatalogItemService
|
@inject ICatalogItemService CatalogItemService
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
@inject ILogger<Edit> Logger
|
@inject ILogger<Edit> Logger
|
||||||
@inject AuthService Auth
|
|
||||||
@inject IJSRuntime JSRuntime
|
@inject IJSRuntime JSRuntime
|
||||||
@inject ICatalogItemService CatalogItemService
|
@inject ICatalogItemService CatalogItemService
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
@page "/admin"
|
@page "/admin"
|
||||||
@attribute [Authorize(Roles = BlazorShared.Authorization.Constants.Roles.ADMINISTRATORS)]
|
@attribute [Authorize(Roles = BlazorShared.Authorization.Constants.Roles.ADMINISTRATORS)]
|
||||||
@inject AuthService Auth
|
|
||||||
@inherits BlazorAdmin.Helpers.BlazorComponent
|
@inherits BlazorAdmin.Helpers.BlazorComponent
|
||||||
@namespace BlazorAdmin.Pages.CatalogItemPage
|
@namespace BlazorAdmin.Pages.CatalogItemPage
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
@page "/logout"
|
@page "/logout"
|
||||||
@inject AuthService AuthService
|
|
||||||
@inject IJSRuntime JSRuntime
|
@inject IJSRuntime JSRuntime
|
||||||
|
@inject HttpClient HttpClient
|
||||||
@inherits BlazorAdmin.Helpers.BlazorComponent
|
@inherits BlazorAdmin.Helpers.BlazorComponent
|
||||||
|
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
|
|
||||||
protected override async Task OnInitializedAsync()
|
protected override async Task OnInitializedAsync()
|
||||||
{
|
{
|
||||||
await AuthService.Logout();
|
await HttpClient.PostAsync("Identity/Account/Logout", null);
|
||||||
await new Route(JSRuntime).RouteOutside("/Identity/Account/Login");
|
await new Route(JSRuntime).RouteOutside("/Identity/Account/Login");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ namespace BlazorAdmin
|
|||||||
builder.Services.AddScoped<HttpService>();
|
builder.Services.AddScoped<HttpService>();
|
||||||
|
|
||||||
builder.Services.AddScoped<ILocalStorageService, LocalStorageService>();
|
builder.Services.AddScoped<ILocalStorageService, LocalStorageService>();
|
||||||
builder.Services.AddScoped<AuthService>();
|
|
||||||
|
|
||||||
builder.Services.AddAuthorizationCore();
|
builder.Services.AddAuthorizationCore();
|
||||||
builder.Services.AddScoped<AuthenticationStateProvider, CustomAuthStateProvider>();
|
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
|
EXPOSE 443
|
||||||
|
|
||||||
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
|
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
|
||||||
WORKDIR /src
|
WORKDIR /app
|
||||||
COPY ["src/PublicApi/PublicApi.csproj", "src/PublicApi/"]
|
|
||||||
RUN dotnet restore "src/PublicApi/PublicApi.csproj"
|
|
||||||
COPY . .
|
COPY . .
|
||||||
WORKDIR "/src/src/PublicApi"
|
#COPY ["src/PublicApi/PublicApi.csproj", "./PublicApi/"]
|
||||||
RUN dotnet build "PublicApi.csproj" -c Release -o /app/build
|
#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
|
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
|
FROM base AS final
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|||||||
@@ -157,7 +157,6 @@ namespace Microsoft.eShopWeb.Web
|
|||||||
// add blazor services
|
// add blazor services
|
||||||
services.AddBlazoredLocalStorage();
|
services.AddBlazoredLocalStorage();
|
||||||
services.AddServerSideBlazor();
|
services.AddServerSideBlazor();
|
||||||
services.AddScoped<AuthService>();
|
|
||||||
|
|
||||||
services.AddScoped<HttpService>();
|
services.AddScoped<HttpService>();
|
||||||
services.AddBlazorServices();
|
services.AddBlazorServices();
|
||||||
|
|||||||
Reference in New Issue
Block a user