13 changed files with 12 additions and 86 deletions
@ -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"); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue