Ejemplo n.º 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));
        }
Ejemplo n.º 2
0
        public async Task <DeviceCode> FindByUserCodeAsync(string userCode)
        {
            Check.NotNull(userCode, nameof(userCode));

            var deviceCodes = await DeviceFlowCodesRepository
                              .FindByUserCodeAsync(userCode)
                              .ConfigureAwait(false);

            if (deviceCodes == null)
            {
                return(null);
            }

            return(DeserializeToDeviceCode(deviceCodes.Data));
        }
Ejemplo n.º 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)
            ;
        }
Ejemplo n.º 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)
            }
                );
        }
Ejemplo n.º 5
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)
            ;
        }