Added a "refreshed_at" stat to tokens.
This commit is contained in:
+3
-2
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"db_name": "PostgreSQL",
|
"db_name": "PostgreSQL",
|
||||||
"query": "\n INSERT INTO tokens (\n id, access_token_hash, refresh_token_hash,\n access_expires_at, refresh_expires_at, revoked_at, created_at\n )\n VALUES ($1, $2, $3, $4, $5, $6, $7)\n ",
|
"query": "\n INSERT INTO tokens (\n id, access_token_hash, refresh_token_hash,\n access_expires_at, refresh_expires_at, refreshed_at, revoked_at, created_at\n )\n VALUES ($1, $2, $3, $4, $5, $6, $7, $8)\n ",
|
||||||
"describe": {
|
"describe": {
|
||||||
"columns": [],
|
"columns": [],
|
||||||
"parameters": {
|
"parameters": {
|
||||||
@@ -11,10 +11,11 @@
|
|||||||
"Timestamptz",
|
"Timestamptz",
|
||||||
"Timestamptz",
|
"Timestamptz",
|
||||||
"Timestamptz",
|
"Timestamptz",
|
||||||
|
"Timestamptz",
|
||||||
"Timestamptz"
|
"Timestamptz"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"nullable": []
|
"nullable": []
|
||||||
},
|
},
|
||||||
"hash": "409368e6023d0e957be632a7d65879c75e1006af498c355a6ac8e5a6144a9dd0"
|
"hash": "8f11aa4a2d8b3208181f12fc5b6f87f80fbc7eade88f4ceaf17f9716622ad12a"
|
||||||
}
|
}
|
||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"db_name": "PostgreSQL",
|
"db_name": "PostgreSQL",
|
||||||
"query": "\n UPDATE tokens\n SET access_token_hash = $2,\n refresh_token_hash = $3,\n access_expires_at = $4,\n refresh_expires_at = $5\n WHERE refresh_token_hash = $1\n AND revoked_at IS NULL\n AND refresh_expires_at > now()\n RETURNING id\n ",
|
"query": "\n UPDATE tokens\n SET access_token_hash = $2,\n refresh_token_hash = $3,\n access_expires_at = $4,\n refresh_expires_at = $5,\n refreshed_at = now()\n WHERE refresh_token_hash = $1\n AND revoked_at IS NULL\n AND refresh_expires_at > now()\n RETURNING id\n ",
|
||||||
"describe": {
|
"describe": {
|
||||||
"columns": [
|
"columns": [
|
||||||
{
|
{
|
||||||
@@ -22,5 +22,5 @@
|
|||||||
false
|
false
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"hash": "398a4f8e5438799586f42687d120fd055e342ba311a12264e34454414cb2325d"
|
"hash": "f90d488ec2fff2e09bfbc83c287313aaeaa275cf6e41272347821735d4b401d6"
|
||||||
}
|
}
|
||||||
@@ -8,6 +8,7 @@ CREATE TABLE tokens (
|
|||||||
),
|
),
|
||||||
access_expires_at TIMESTAMPTZ NOT NULL,
|
access_expires_at TIMESTAMPTZ NOT NULL,
|
||||||
refresh_expires_at TIMESTAMPTZ NOT NULL,
|
refresh_expires_at TIMESTAMPTZ NOT NULL,
|
||||||
|
refreshed_at TIMESTAMPTZ,
|
||||||
revoked_at TIMESTAMPTZ,
|
revoked_at TIMESTAMPTZ,
|
||||||
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
created_at TIMESTAMPTZ NOT NULL
|
||||||
);
|
);
|
||||||
@@ -7,6 +7,7 @@ pub struct TokenRow {
|
|||||||
pub refresh_token_hash: Vec<u8>,
|
pub refresh_token_hash: Vec<u8>,
|
||||||
pub access_expires_at: DateTime<Utc>,
|
pub access_expires_at: DateTime<Utc>,
|
||||||
pub refresh_expires_at: DateTime<Utc>,
|
pub refresh_expires_at: DateTime<Utc>,
|
||||||
|
pub refreshed_at: Option<DateTime<Utc>>,
|
||||||
pub revoked_at: Option<DateTime<Utc>>,
|
pub revoked_at: Option<DateTime<Utc>>,
|
||||||
pub created_at: DateTime<Utc>,
|
pub created_at: DateTime<Utc>,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,15 +10,16 @@ where
|
|||||||
r#"
|
r#"
|
||||||
INSERT INTO tokens (
|
INSERT INTO tokens (
|
||||||
id, access_token_hash, refresh_token_hash,
|
id, access_token_hash, refresh_token_hash,
|
||||||
access_expires_at, refresh_expires_at, revoked_at, created_at
|
access_expires_at, refresh_expires_at, refreshed_at, revoked_at, created_at
|
||||||
)
|
)
|
||||||
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
|
||||||
"#,
|
"#,
|
||||||
token.id,
|
token.id,
|
||||||
token.access_token_hash,
|
token.access_token_hash,
|
||||||
token.refresh_token_hash,
|
token.refresh_token_hash,
|
||||||
token.access_expires_at,
|
token.access_expires_at,
|
||||||
token.refresh_expires_at,
|
token.refresh_expires_at,
|
||||||
|
token.refreshed_at,
|
||||||
token.revoked_at,
|
token.revoked_at,
|
||||||
token.created_at,
|
token.created_at,
|
||||||
)
|
)
|
||||||
@@ -46,7 +47,8 @@ where
|
|||||||
SET access_token_hash = $2,
|
SET access_token_hash = $2,
|
||||||
refresh_token_hash = $3,
|
refresh_token_hash = $3,
|
||||||
access_expires_at = $4,
|
access_expires_at = $4,
|
||||||
refresh_expires_at = $5
|
refresh_expires_at = $5,
|
||||||
|
refreshed_at = now()
|
||||||
WHERE refresh_token_hash = $1
|
WHERE refresh_token_hash = $1
|
||||||
AND revoked_at IS NULL
|
AND revoked_at IS NULL
|
||||||
AND refresh_expires_at > now()
|
AND refresh_expires_at > now()
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ pub struct Token {
|
|||||||
pub refresh_token_hash: Vec<u8>,
|
pub refresh_token_hash: Vec<u8>,
|
||||||
pub access_expires_at: DateTime<Utc>,
|
pub access_expires_at: DateTime<Utc>,
|
||||||
pub refresh_expires_at: DateTime<Utc>,
|
pub refresh_expires_at: DateTime<Utc>,
|
||||||
|
pub refreshed_at: Option<DateTime<Utc>>,
|
||||||
pub revoked_at: Option<DateTime<Utc>>,
|
pub revoked_at: Option<DateTime<Utc>>,
|
||||||
pub created_at: DateTime<Utc>,
|
pub created_at: DateTime<Utc>,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ fn encode(token: Token) -> TokenRow {
|
|||||||
refresh_token_hash: token.refresh_token_hash,
|
refresh_token_hash: token.refresh_token_hash,
|
||||||
access_expires_at: token.access_expires_at,
|
access_expires_at: token.access_expires_at,
|
||||||
refresh_expires_at: token.refresh_expires_at,
|
refresh_expires_at: token.refresh_expires_at,
|
||||||
|
refreshed_at: token.refreshed_at,
|
||||||
revoked_at: token.revoked_at,
|
revoked_at: token.revoked_at,
|
||||||
created_at: token.created_at,
|
created_at: token.created_at,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -117,6 +117,7 @@ fn token(generated: &GeneratedTokenPair) -> Token {
|
|||||||
refresh_token_hash: generated.refresh_token_hash.clone(),
|
refresh_token_hash: generated.refresh_token_hash.clone(),
|
||||||
access_expires_at: generated.access_expires_at,
|
access_expires_at: generated.access_expires_at,
|
||||||
refresh_expires_at: generated.refresh_expires_at,
|
refresh_expires_at: generated.refresh_expires_at,
|
||||||
|
refreshed_at: None,
|
||||||
revoked_at: None,
|
revoked_at: None,
|
||||||
created_at: Utc::now(),
|
created_at: Utc::now(),
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user