public async ValueTask <string> GetTokenAsync() { var user = _authenticatedUserProvider.GetUser(); if (user == null) { return(string.Empty); } var token = await _cachingService.GetAsync <string>(_userTokenKeyProvider.GetKey(user.Id)); if (string.IsNullOrEmpty(token)) { token = (await _identityClient.GetTokenAsync(new IdentityTokenServiceRequest { UserId = user.Id }) .ResponseAsync)?.Token; if (!string.IsNullOrEmpty(token)) { await _cachingService.SetAsync(_userTokenKeyProvider.GetKey(user.Id), token); } } return(token); }
public Task HandleAsync(UserTokenChanged obj, CancellationToken token = default) { return(_cachingService.SetAsync( _userTokenKeyProvider.GetKey(obj.UserId), obj.Token, TimeSpan.FromHours(3), token )); }
public Task HandleAsync(UserTokenRemoved obj, CancellationToken token = default) { return(_cachingService.RemoveAsync(_userTokenKeyProvider.GetKey(obj.UserId), token)); }