|
1 | 1 | using Microsoft.AspNetCore.Mvc; |
2 | | -using System.IdentityModel.Tokens.Jwt; |
3 | | -using System.Security.Claims; |
| 2 | +using SharedLibrary.Cache; |
4 | 3 | using System.Text.Json; |
5 | | -using UserManagement.Sdk.Abstractions; |
6 | 4 | using UserManagementApi.Contracts.Models; |
7 | 5 |
|
8 | 6 | namespace ApiIntegrationMvc.Views.Shared.Components |
9 | 7 | { |
10 | 8 |
|
11 | 9 | public sealed class CategoryTreeViewComponent: ViewComponent |
12 | 10 | { |
13 | | - private readonly IAccessTokenProvider _tokens; |
14 | | - public CategoryTreeViewComponent(IAccessTokenProvider tokens) |
| 11 | + private readonly ICacheAccessProvider _tokens; |
| 12 | + public CategoryTreeViewComponent(ICacheAccessProvider tokens) |
15 | 13 | => _tokens = tokens; |
16 | 14 |
|
17 | 15 | public async Task<IViewComponentResult> InvokeAsync() |
18 | 16 | { |
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); |
21 | 20 |
|
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(); |
26 | 21 | IReadOnlyList<Category> categories = new List<Category>(); |
27 | | - if (list.Count == 1) |
| 22 | + if (permissions != null) |
28 | 23 | { |
29 | | - categories = JsonSerializer.Deserialize<List<Category>>(list[0]); |
| 24 | + categories = JsonSerializer.Deserialize<List<Category>>(permissions); |
30 | 25 | } |
31 | 26 |
|
32 | 27 | return View(categories); // Views/Shared/Components/CategoryTree/Default.cshtml |
|
0 commit comments