public async Task StoreDeviceAuthorizationAsync_should_add_data_in_db() { CreateSut(out IServiceScope scope, out OperationalDbContext context, out DeviceFlowStore sut); var code = GenerateId(); var userCode = GenerateId(); var deviceCode = new ISModels.DeviceCode { ClientId = GenerateId(), }; await sut.StoreDeviceAuthorizationAsync(code, userCode, deviceCode); using (scope) { Assert.NotNull(await context.DeviceCodes.FirstOrDefaultAsync(d => d.Code == code && d.UserCode == userCode)); } }
public async Task UpdateByUserCodeAsync(string userCode, models.DeviceCode data) { userCode = userCode ?? throw new ArgumentNullException(nameof(userCode)); data = data ?? throw new ArgumentNullException(nameof(data)); var response = await _store.GetAsync(new PageRequest { Filter = $"{nameof(DeviceCode.UserCode)} eq '{userCode}'" }).ConfigureAwait(false); if (response.Items.Any()) { var entity = response.Items.First(); entity.Data = _serializer.Serialize(data); entity.Expiration = data.CreationTime.AddSeconds(data.Lifetime); entity.SubjectId = data.Subject?.FindFirst(JwtClaimTypes.Subject).Value; await _store.UpdateAsync(entity).ConfigureAwait(false); return; } throw new InvalidOperationException($"Device code for {userCode} not found"); }
public Task StoreDeviceAuthorizationAsync(string deviceCode, string userCode, models.DeviceCode data) { deviceCode = deviceCode ?? throw new ArgumentNullException(nameof(deviceCode)); userCode = userCode ?? throw new ArgumentNullException(nameof(userCode)); data = data ?? throw new ArgumentNullException(nameof(data)); var entity = new DeviceCode { Code = deviceCode, UserCode = userCode, Data = _serializer.Serialize(data), ClientId = data.ClientId, SubjectId = data.Subject?.FindFirst(JwtClaimTypes.Subject).Value, Expiration = data.CreationTime.AddSeconds(data.Lifetime), }; return(_store.CreateAsync(entity)); }