示例#1
0
        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));
        }
示例#2
0
    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;
            }
        }
    }
示例#3
0
        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)
            ;
        }
示例#4
0
        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)
            }
                );
        }
示例#5
0
        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;
                }
            }
        }
示例#6
0
        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)
            ;
        }