private async Task ClearAuthorizationAsync() { if (BearerToken != null) { BearerToken = null; UserId = null; UserName = null; Api.Authorization = null; await TokenStorage.ClearAsync(); UserChanged?.Invoke(); UserInfoChanged?.Invoke(); } }
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); }
private void UserInfoHasChanged() { UserInfoChanged?.Invoke(this, EventArgs.Empty); }
protected virtual void RaiseUserInfoChanged() { // NOTE: Either subscribe to the event or handle the logic here. UserInfoChanged?.Invoke(this, EventArgs.Empty); }
public void Apply(UserInfoChanged e) { }
protected void NotifyAuthenticationStateChanged() { UserInfoChanged?.Invoke(userInfo); }
public void Handle(UserInfoChanged e) { Update(e.Id, c => c.UserName = e.UserName); }