From ee5d4be0a6e9a5ca87f43e4ff4d0024e260f1847 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Tue, 11 Jan 2022 22:23:53 -0500 Subject: [PATCH] add ip address at creation --- .../lib/database_queries/src/twitch_oauth/insert.rs | 13 +++++++++++++ .../2022-01-11-042235_twitch_oauth_tokens/up.sql | 6 ++++++ 2 files changed, 19 insertions(+) diff --git a/crates/lib/database_queries/src/twitch_oauth/insert.rs b/crates/lib/database_queries/src/twitch_oauth/insert.rs index 233847901a..724074724e 100644 --- a/crates/lib/database_queries/src/twitch_oauth/insert.rs +++ b/crates/lib/database_queries/src/twitch_oauth/insert.rs @@ -20,6 +20,9 @@ pub struct TwitchOauthTokenInsertBuilder { /// Storyteller/FakeYou username. maybe_user_token: Option, + /// Abuse tracking. + maybe_ip_address_creation: Option, + /// Twitch username / channel name. maybe_twitch_username: Option, @@ -42,6 +45,7 @@ impl TwitchOauthTokenInsertBuilder { access_token: access_token.to_string(), maybe_refresh_token: None, maybe_user_token: None, + maybe_ip_address_creation: None, maybe_twitch_username: None, token_type: None, expires_in_seconds: None, @@ -62,6 +66,11 @@ impl TwitchOauthTokenInsertBuilder { self } + pub fn set_ip_address_creation(mut self, ip_address_creation: Option<&str>) -> Self { + self.maybe_ip_address_creation = ip_address_creation.map(|t| t.to_string()); + self + } + pub fn set_twitch_username(mut self, maybe_twitch_username: Option<&str>) -> Self { self.maybe_twitch_username = maybe_twitch_username.map(|t| t.to_string()); self @@ -117,6 +126,7 @@ SET has_channel_read_subscriptions = ?, has_channel_read_redemptions= ?, has_user_read_follows = ?, + ip_address_creation = ?, expires_at = DATE_ADD(NOW(), INTERVAL ? SECOND) "#, self.maybe_user_token.clone(), @@ -130,6 +140,7 @@ SET self.has_channel_read_subscriptions.clone(), self.has_channel_read_redemptions.clone(), self.has_user_read_follows.clone(), + self.maybe_ip_address_creation.clone(), expires_in_seconds, ) } else { @@ -148,6 +159,7 @@ SET has_channel_read_subscriptions = ?, has_channel_read_redemptions= ?, has_user_read_follows = ?, + ip_address_creation = ?, expires_at = NULL "#, self.maybe_user_token.clone(), @@ -160,6 +172,7 @@ SET self.has_channel_read_subscriptions.clone(), self.has_channel_read_redemptions.clone(), self.has_user_read_follows.clone(), + self.maybe_ip_address_creation.clone(), ) }; diff --git a/migrations/2022-01-11-042235_twitch_oauth_tokens/up.sql b/migrations/2022-01-11-042235_twitch_oauth_tokens/up.sql index 3ab0b077fe..2fa6c51e7b 100644 --- a/migrations/2022-01-11-042235_twitch_oauth_tokens/up.sql +++ b/migrations/2022-01-11-042235_twitch_oauth_tokens/up.sql @@ -66,6 +66,12 @@ CREATE TABLE twitch_oauth_tokens( -- THERE ARE MORE SCOPES... PERHAPS WE SHOULD ADD THEM? + -- ========== SECURITY ========== + + -- For abuse tracking. + -- Wide enough for IPv4/6 + ip_address_creation VARCHAR(40) DEFAULT NULL, + -- ========== VECTOR CLOCK ========== -- Incremented with every update.