From 0920c4d4f30a3345870d385d5c6f3e0919228b56 Mon Sep 17 00:00:00 2001
From: benj <benj@rse8.com>
Date: Mon, 12 Dec 2022 17:06:57 -0800
Subject: (oauth2 + email added): a mess that may or may not really work and
 needs to be refactored...

---
 .../store/sqlite/sql/write_oauth_validation.sql    | 45 ++++++++++++++++++++++
 1 file changed, 45 insertions(+)
 create mode 100644 crates/secd/store/sqlite/sql/write_oauth_validation.sql

(limited to 'crates/secd/store/sqlite/sql/write_oauth_validation.sql')

diff --git a/crates/secd/store/sqlite/sql/write_oauth_validation.sql b/crates/secd/store/sqlite/sql/write_oauth_validation.sql
new file mode 100644
index 0000000..ccb11aa
--- /dev/null
+++ b/crates/secd/store/sqlite/sql/write_oauth_validation.sql
@@ -0,0 +1,45 @@
+insert into oauth_validation (
+       oauth_validation_public_id
+       , oauth_provider_id
+       , access_token
+       , raw_response
+       , created_at
+       , validated_at
+) values (
+       ?1
+       , (
+         select oauth_provider_id
+         from oauth_provider
+         where name = ?2
+         and flow = ?3
+       )
+       , ?4
+       , ?5
+       , ?6
+       , ?7
+) on conflict (oauth_validation_public_id) do update
+  set access_token = excluded.access_token
+      , validated_at = excluded.validated_at
+      , raw_response = excluded.raw_response;
+--
+insert into identity_oauth_validation (
+       identity_id
+       , oauth_validation_id
+       , revoked_at
+       , deleted_at
+) values (
+       (
+       select identity_id
+       from identity
+       where identity_public_id = ?1
+       )
+       , (
+         select oauth_validation_id
+         from oauth_validation
+         where oauth_validation_public_id = ?2
+       )
+       , ?3
+       , ?4
+) on conflict (identity_id, oauth_validation_id) do update
+  set revoked_at = excluded.revoked_at
+      , deleted_at = excluded.deleted_at;
-- 
cgit v1.2.3

