Store refresh tokens in the database for later when we support using them
This commit is contained in:
parent
bbbb28b45f
commit
5f1bd066ae
16
.sqlx/query-1e7d0d2dd54b60b2d71c25fdeae16890d776a1f9120384769d72781f3d857b63.json
generated
Normal file
16
.sqlx/query-1e7d0d2dd54b60b2d71c25fdeae16890d776a1f9120384769d72781f3d857b63.json
generated
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"db_name": "PostgreSQL",
|
||||||
|
"query": "\n INSERT INTO application_refresh_tokens (refresh_token_hash, session_id, issued_at_utc, expires_at_utc)\n VALUES ($1, $2, NOW(), $3)\n ",
|
||||||
|
"describe": {
|
||||||
|
"columns": [],
|
||||||
|
"parameters": {
|
||||||
|
"Left": [
|
||||||
|
"Bytea",
|
||||||
|
"Int4",
|
||||||
|
"Timestamp"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"nullable": []
|
||||||
|
},
|
||||||
|
"hash": "1e7d0d2dd54b60b2d71c25fdeae16890d776a1f9120384769d72781f3d857b63"
|
||||||
|
}
|
20
src/store.rs
20
src/store.rs
@ -166,6 +166,26 @@ impl<'a, 'txn> IdCoopStoreTxn<'a, 'txn> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn issue_refresh_token(
|
||||||
|
&mut self,
|
||||||
|
refresh_token_hash: &[u8],
|
||||||
|
session_id: i32,
|
||||||
|
expires_at: DateTime<Utc>,
|
||||||
|
) -> eyre::Result<()> {
|
||||||
|
let expires_at = expires_at.naive_utc();
|
||||||
|
sqlx::query!(
|
||||||
|
"
|
||||||
|
INSERT INTO application_refresh_tokens (refresh_token_hash, session_id, issued_at_utc, expires_at_utc)
|
||||||
|
VALUES ($1, $2, NOW(), $3)
|
||||||
|
",
|
||||||
|
refresh_token_hash, session_id, expires_at
|
||||||
|
)
|
||||||
|
.execute(&mut **self.txn)
|
||||||
|
.await
|
||||||
|
.context("failed to issue access token")?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
/// Creates a user and returns the user ID.
|
/// Creates a user and returns the user ID.
|
||||||
pub async fn create_user(&mut self, cu: CreateUser) -> eyre::Result<Uuid> {
|
pub async fn create_user(&mut self, cu: CreateUser) -> eyre::Result<Uuid> {
|
||||||
let r = sqlx::query!(
|
let r = sqlx::query!(
|
||||||
|
@ -302,6 +302,14 @@ pub async fn oidc_token(
|
|||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.context("issue_access_token")?;
|
.context("issue_access_token")?;
|
||||||
|
txn.issue_refresh_token(
|
||||||
|
&refresh_token_hash,
|
||||||
|
session_id,
|
||||||
|
// TODO Support custom expiry, not 100 years
|
||||||
|
Utc::now() + Duration::days(365 * 100),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.context("issue_refresh_token")?;
|
||||||
|
|
||||||
Ok(Ok(session_id))
|
Ok(Ok(session_id))
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user