Пример #1
0
        protected override async Task OnInitializedAsync()
        {
            base.OnInitialized();
            await Task.Delay(2000);

            var loggedinUser = (await AuthenticationStateTask).User;

            if (loggedinUser.IsInRole("Admin"))
            {
                Console.WriteLine($"User {loggedinUser.Identity.Name} is in role admin");
            }
            //var user = await LocalStorage.GetItemAsync<UserDto>(MagicStrings.Local_UserDetails);
            var token = await LocalStorage.GetItemAsync <string>(MagicStrings.Local_Token);

            var id   = JwtParser.ParseIdFromJwt(token);
            var user = await AuthenticationApiService.GetUserAsync(id);

            AuthenticatedUser = new UserDetailsDto();
            MiniMapper.CopyProperties(AuthenticatedUser, user);
            AuthenticatedUser.Role = JwtParser.ParseRolesFromJwt(token).FirstOrDefault();
            FormUser = new UserDetailsDto();
            MiniMapper.CopyProperties(FormUser, AuthenticatedUser);
            EditContext = new EditContext(FormUser);
            EditContext.OnFieldChanged += EditContext_OnFieldChanged;
        }
Пример #2
0
        public void JwtParser_GetRoles_ShouldReturn1Role()
        {
            var roles = JwtParser.ParseRolesFromJwt(token);

            Assert.AreEqual(1, roles.Length);
        }