public virtual async Task <DeviceCode> FindByDeviceCodeAsync(string deviceCode) { Check.NotNull(deviceCode, nameof(deviceCode)); var deviceCodes = await DeviceFlowCodesRepository .FindByDeviceCodeAsync(deviceCode) ; if (deviceCodes == null) { return(null); } return(DeserializeToDeviceCode(deviceCodes.Data)); }
protected virtual async Task RemoveDeviceCodesAsync() { for (var i = 0; i < Options.CleanupLoopCount; i++) { var deviceFlowCodeses = await DeviceFlowCodesRepository.GetListByExpirationAsync(DateTime.UtcNow, Options.CleanupBatchSize); await DeviceFlowCodesRepository.DeleteManyAsync(deviceFlowCodeses); //No need to continue to query if it gets more than max items. if (deviceFlowCodeses.Count < Options.CleanupBatchSize) { break; } } }
public virtual async Task RemoveByDeviceCodeAsync(string deviceCode) { Check.NotNull(deviceCode, nameof(deviceCode)); var deviceCodes = await DeviceFlowCodesRepository .FindByDeviceCodeAsync(deviceCode) ; if (deviceCodes == null) { return; } await DeviceFlowCodesRepository .DeleteAsync(deviceCodes, autoSave : true) ; }
public virtual async Task StoreDeviceAuthorizationAsync(string deviceCode, string userCode, DeviceCode data) { Check.NotNull(deviceCode, nameof(deviceCode)); Check.NotNull(userCode, nameof(userCode)); Check.NotNull(data, nameof(data)); await DeviceFlowCodesRepository .InsertAsync( new DeviceFlowCodes(GuidGenerator.Create()) { DeviceCode = deviceCode, UserCode = userCode, ClientId = data.ClientId, SubjectId = data.Subject?.FindFirst(JwtClaimTypes.Subject).Value, CreationTime = data.CreationTime, Expiration = data.CreationTime.AddSeconds(data.Lifetime), Data = Serialize(data) } ); }
protected virtual async Task RemoveDeviceCodesAsync() { for (int i = 0; i < Options.CleanupLoopCount; i++) { var deviceFlowCodeses = await DeviceFlowCodesRepository .GetListByExpirationAsync(Clock.Now, Options.CleanupBatchSize); //TODO: Can be optimized if the repository implements the batch deletion foreach (var deviceFlowCodes in deviceFlowCodeses) { await DeviceFlowCodesRepository .DeleteAsync(deviceFlowCodes); } //No need to continue to query if it gets more than max items. if (deviceFlowCodeses.Count < Options.CleanupBatchSize) { break; } } }
public virtual async Task UpdateByUserCodeAsync(string userCode, DeviceCode data) { Check.NotNull(userCode, nameof(userCode)); Check.NotNull(data, nameof(data)); var deviceCodes = await DeviceFlowCodesRepository .FindByUserCodeAsync(userCode) ; if (deviceCodes == null) { throw new InvalidOperationException($"Could not update device code by the given userCode: {userCode}"); } deviceCodes.SubjectId = data.Subject?.FindFirst(JwtClaimTypes.Subject).Value; deviceCodes.Data = Serialize(data); await DeviceFlowCodesRepository .UpdateAsync(deviceCodes, autoSave : true) ; }