Skip to content

Commit 1bec28d

Browse files
Permissions or categories accessed from cache instead of token
1 parent b4bfba6 commit 1bec28d

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

ApiIntegrationMvc/Views/Shared/Components/CategoryTreeViewComponent.cs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,27 @@
11
using Microsoft.AspNetCore.Mvc;
2-
using System.IdentityModel.Tokens.Jwt;
3-
using System.Security.Claims;
2+
using SharedLibrary.Cache;
43
using System.Text.Json;
5-
using UserManagement.Sdk.Abstractions;
64
using UserManagementApi.Contracts.Models;
75

86
namespace ApiIntegrationMvc.Views.Shared.Components
97
{
108

119
public sealed class CategoryTreeViewComponent: ViewComponent
1210
{
13-
private readonly IAccessTokenProvider _tokens;
14-
public CategoryTreeViewComponent(IAccessTokenProvider tokens)
11+
private readonly ICacheAccessProvider _tokens;
12+
public CategoryTreeViewComponent(ICacheAccessProvider tokens)
1513
=> _tokens = tokens;
1614

1715
public async Task<IViewComponentResult> InvokeAsync()
1816
{
19-
var ct = HttpContext?.RequestAborted ?? default;
20-
var token = await _tokens.GetAccessTokenAsync(ct);
17+
var ct = HttpContext?.RequestAborted ?? default;
18+
19+
var permissions = await _tokens.GetUserPermissionsAsync(ct);
2120

22-
var handler = new JwtSecurityTokenHandler();
23-
var jwt = handler.ReadJwtToken(token);
24-
IEnumerable<Claim> claims = jwt.Claims;
25-
var list = claims.Where(c => c.Type == "categories").Select(c => c.Value).ToList();
2621
IReadOnlyList<Category> categories = new List<Category>();
27-
if (list.Count == 1)
22+
if (permissions != null)
2823
{
29-
categories = JsonSerializer.Deserialize<List<Category>>(list[0]);
24+
categories = JsonSerializer.Deserialize<List<Category>>(permissions);
3025
}
3126

3227
return View(categories); // Views/Shared/Components/CategoryTree/Default.cshtml

0 commit comments

Comments
 (0)