Beispiel #1
0
 public async Task StoreDeviceAuthorizationAsync(string deviceCode, string userCode, Models.DeviceCode data)
 {
     if (deviceCode == null || userCode == null || data == null)
     {
         return;
     }
     using (var connection = new SqlConnection(_dapperStoreOptions.DbConnectionString))
     {
         var entity = new Entities.DeviceFlowCodes
         {
             DeviceCode   = deviceCode,
             UserCode     = userCode,
             ClientId     = data.ClientId,
             SubjectId    = data.Subject?.FindFirst(JwtClaimTypes.Subject).Value,
             CreationTime = data.CreationTime,
             Expiration   = data.CreationTime.AddSeconds(data.Lifetime),
             Data         = _persistentGrantSerializer.Serialize(data)
         };
         var sql = $@"
         INSERT
         INTO DeviceFlowCodes(DeviceCode, UserCode, SubjectId, ClientId, CreationTime, Expiration, Data)
         VALUES(@DeviceCode, @UserCode, @SubjectId, @ClientId, @CreationTime, @Expiration, @Data);
         ";
         await connection.ExecuteAsync(sql, new { entity.DeviceCode, entity.UserCode, entity.SubjectId, entity.ClientId, entity.CreationTime, entity.Expiration, entity.Data });
     }
 }
Beispiel #2
0
        public async Task UpdateByUserCodeAsync(string userCode, Models.DeviceCode data)
        {
            if (userCode == null || data == null)
            {
                return;
            }
            using (var connection = new SqlConnection(_dapperStoreOptions.DbConnectionString))
            {
                var sql            = $@"
                SELECT
	                DeviceCode,
                    UserCode,
                    SubjectId,
                    ClientId,
                    CreationTime,
                    Expiration,
                    Data
                FROM DeviceFlowCodes
                WHERE UserCode = @userCode;
                ";
                var deviceFlowCode = await connection.QueryFirstOrDefaultAsync <Entities.DeviceFlowCodes>(sql, new { userCode });

                if (deviceFlowCode == null)
                {
                    return;
                }
                var entity = new Entities.DeviceFlowCodes
                {
                    DeviceCode   = deviceFlowCode.DeviceCode,
                    UserCode     = userCode,
                    ClientId     = data.ClientId,
                    SubjectId    = data.Subject?.FindFirst(JwtClaimTypes.Subject).Value,
                    CreationTime = data.CreationTime,
                    Expiration   = data.CreationTime.AddSeconds(data.Lifetime),
                    Data         = _persistentGrantSerializer.Serialize(data)
                };
                sql = $@"
                UPDATE DeviceFlowCodes
                SET DeviceCode = @DeviceCode, UserCode = @UserCode, SubjectId = @SubjectId, ClientId = @ClientId, CreationTime = @CreationTime, Expiration = @Expiration, Data = @Data
                WHERE UserCode = @UserCode
                ";
                await connection.ExecuteAsync(sql, new { entity.DeviceCode, entity.UserCode, entity.SubjectId, entity.ClientId, entity.CreationTime, entity.Expiration, entity.Data });
            }
        }