Пример #1
0
        private async Task ClearAuthorizationAsync()
        {
            if (BearerToken != null)
            {
                BearerToken       = null;
                UserId            = null;
                UserName          = null;
                Api.Authorization = null;
                await TokenStorage.ClearAsync();

                UserChanged?.Invoke();
                UserInfoChanged?.Invoke();
            }
        }
Пример #2
0
        private bool LoadUserInfo(string bearerToken)
        {
            if (!string.IsNullOrEmpty(bearerToken))
            {
                JwtSecurityTokenHandler tokenHandler = new JwtSecurityTokenHandler();
                JwtSecurityToken        jwtToken     = tokenHandler.ReadJwtToken(bearerToken);
                if (jwtToken.ValidTo > DateTime.Now)
                {
                    var claims = jwtToken.Claims;

                    UserId     = claims.FindUserId();
                    UserName   = claims.FirstOrDefault(c => c.Type == ClaimTypes.Name)?.Value;
                    IsReadOnly = claims.IsReadOnly();
                    UserInfoChanged?.Invoke();
                    return(true);
                }
            }

            return(false);
        }
Пример #3
0
 private void UserInfoHasChanged()
 {
     UserInfoChanged?.Invoke(this, EventArgs.Empty);
 }
Пример #4
0
 protected virtual void RaiseUserInfoChanged()
 {
     // NOTE: Either subscribe to the event or handle the logic here.
     UserInfoChanged?.Invoke(this, EventArgs.Empty);
 }
Пример #5
0
 public void Apply(UserInfoChanged e)
 {
 }
 protected void NotifyAuthenticationStateChanged()
 {
     UserInfoChanged?.Invoke(userInfo);
 }
Пример #7
0
 public void Handle(UserInfoChanged e)
 {
     Update(e.Id, c => c.UserName = e.UserName);
 }