Repository navigation
Expand file tree
/
Copy pathexternalauth.sql
More file actions
66 lines (60 loc) · 1.68 KB
/
Copy pathexternalauth.sql
File metadata and controls
66 lines (60 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
-- 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
) VALUES (
$1,
$2,
$3,
$4,
$5,
$6,
$7,
$8,
$9,
$10
) 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_refresh_failure_reason = $11
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;