The `oauth_extra_key` can sometimes contain sensitive data so we should encrypt
70 lines
1.7 KiB
SQL
70 lines
1.7 KiB
SQL
-- name: GetExternalAuthLink :one
|
|
SELECT * FROM external_auth_links WHERE provider_id = $1 AND user_id = $2;
|
|
|
|
-- name: DeleteExternalAuthLink :exec
|
|
DELETE FROM external_auth_links WHERE provider_id = $1 AND user_id = $2;
|
|
|
|
-- name: GetExternalAuthLinksByUserID :many
|
|
SELECT * FROM external_auth_links WHERE user_id = $1;
|
|
|
|
-- name: InsertExternalAuthLink :one
|
|
INSERT INTO external_auth_links (
|
|
provider_id,
|
|
user_id,
|
|
created_at,
|
|
updated_at,
|
|
oauth_access_token,
|
|
oauth_access_token_key_id,
|
|
oauth_refresh_token,
|
|
oauth_refresh_token_key_id,
|
|
oauth_expiry,
|
|
oauth_extra,
|
|
oauth_extra_key_id
|
|
) VALUES (
|
|
$1,
|
|
$2,
|
|
$3,
|
|
$4,
|
|
$5,
|
|
$6,
|
|
$7,
|
|
$8,
|
|
$9,
|
|
$10,
|
|
$11
|
|
) RETURNING *;
|
|
|
|
-- name: UpdateExternalAuthLink :one
|
|
-- If a refresh lease is provided, the row is only updated if the lease matches.
|
|
UPDATE external_auth_links SET
|
|
updated_at = $4,
|
|
oauth_access_token = $5,
|
|
oauth_access_token_key_id = $6,
|
|
oauth_refresh_token = $7,
|
|
oauth_refresh_token_key_id = $8,
|
|
oauth_expiry = $9,
|
|
oauth_extra = $10,
|
|
oauth_extra_key_id = $11,
|
|
oauth_refresh_failure_reason = $12
|
|
WHERE
|
|
provider_id = $1
|
|
AND user_id = $2
|
|
AND (refresh_lease_expires_at = $3 OR $3 IS NULL)
|
|
RETURNING *;
|
|
|
|
-- name: AcquireExternalAuthLinkRefreshLease :one
|
|
-- Set the lease to expire according to the provided timeout. If there is
|
|
-- already a lease, an exception is raised.
|
|
SELECT * from acquire_external_auth_link_refresh_lease(@provider_id, @user_id, @timeout_ms);
|
|
|
|
-- name: ReleaseExternalAuthLinkRefreshLease :exec
|
|
-- The lease is only removed if it is the current lease.
|
|
UPDATE
|
|
external_auth_links
|
|
SET
|
|
refresh_lease_expires_at = NULL
|
|
WHERE
|
|
provider_id = @provider_id
|
|
AND user_id = @user_id
|
|
AND refresh_lease_expires_at = @refresh_lease_expires_at;
|