Ejemplo n.º 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();
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
0
 private void UserInfoHasChanged()
 {
     UserInfoChanged?.Invoke(this, EventArgs.Empty);
 }
Ejemplo n.º 4
0
 protected virtual void RaiseUserInfoChanged()
 {
     // NOTE: Either subscribe to the event or handle the logic here.
     UserInfoChanged?.Invoke(this, EventArgs.Empty);
 }
Ejemplo n.º 5
0
 public void Apply(UserInfoChanged e)
 {
 }
 protected void NotifyAuthenticationStateChanged()
 {
     UserInfoChanged?.Invoke(userInfo);
 }
Ejemplo n.º 7
0
 public void Handle(UserInfoChanged e)
 {
     Update(e.Id, c => c.UserName = e.UserName);
 }