Integrated AuthenticationStateProvider using .NET Core Identity

This commit is contained in:
Shaun Walker
2019-07-08 12:52:40 -04:00
parent 46821b8a10
commit 6cf1eb1c31
21 changed files with 565 additions and 137 deletions

View File

@ -13,11 +13,13 @@ namespace Oqtane.Services
{
private readonly HttpClient http;
private readonly SiteState sitestate;
private readonly IUriHelper urihelper;
public UserService(HttpClient http, SiteState sitestate)
public UserService(HttpClient http, SiteState sitestate, IUriHelper urihelper)
{
this.http = http;
this.sitestate = sitestate;
this.urihelper = urihelper;
}
private string apiurl
@ -35,7 +37,7 @@ namespace Oqtane.Services
{
List<User> users = await http.GetJsonAsync<List<User>>(apiurl);
return users.Where(item => item.UserId == UserId).FirstOrDefault();
}
}
public async Task AddUserAsync(User user)
{
@ -51,6 +53,22 @@ namespace Oqtane.Services
await http.DeleteAsync(apiurl + "/" + UserId.ToString());
}
public async Task<User> GetCurrentUserAsync()
{
return await http.GetJsonAsync<User>(apiurl + "/current");
}
public async Task<User> LoginUserAsync(User user)
{
return await http.PostJsonAsync<User>(apiurl + "/login", user);
}
public async Task LogoutUserAsync()
{
// best practices recommend post is preferrable to get for logout
await http.PostJsonAsync(apiurl + "/logout", null);
}
// ACLs are stored in the format "!rolename1;![userid1];rolename2;rolename3;[userid2];[userid3]" where "!" designates Deny permissions
public bool IsAuthorized(User user, string accesscontrollist)
{