refresh_tokens: add app inside each refresh token
This commit is contained in:
parent
2caf584cb7
commit
956f28f7e5
11 changed files with 109 additions and 75 deletions
|
|
@ -3,7 +3,7 @@ use crate::RefreshToken;
|
|||
use chrono::{Duration, Utc};
|
||||
use database::sqlx::SqliteExecutor;
|
||||
use database::RefreshTokens as DatabaseRefreshTokens;
|
||||
use id::UserID;
|
||||
use id::{AppID, UserID};
|
||||
|
||||
impl From<DatabaseRefreshTokens> for RefreshToken {
|
||||
fn from(db: DatabaseRefreshTokens) -> Self {
|
||||
|
|
@ -12,6 +12,7 @@ impl From<DatabaseRefreshTokens> for RefreshToken {
|
|||
token: db.token,
|
||||
ip_address: db.ip_address,
|
||||
user: UserID(db.user),
|
||||
app: AppID(db.app),
|
||||
|
||||
// Timings
|
||||
created_at: db.created_at,
|
||||
|
|
@ -28,6 +29,7 @@ impl RefreshToken {
|
|||
token: &str,
|
||||
ip_address: String,
|
||||
user: &UserID,
|
||||
app: &AppID,
|
||||
duration_days: i64,
|
||||
) -> Result<Option<()>, Error> {
|
||||
let expires_at = Utc::now() + Duration::days(duration_days);
|
||||
|
|
@ -37,6 +39,7 @@ impl RefreshToken {
|
|||
token,
|
||||
ip_address.as_str(),
|
||||
user.as_ref(),
|
||||
app.as_ref(),
|
||||
expires_at.timestamp(),
|
||||
)
|
||||
.await?)
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ mod database;
|
|||
mod error;
|
||||
|
||||
use chrono::{DateTime, Utc};
|
||||
use id::UserID;
|
||||
use id::{AppID, UserID};
|
||||
|
||||
pub use crate::error::Error;
|
||||
|
||||
|
|
@ -12,6 +12,7 @@ pub struct RefreshToken {
|
|||
token: String,
|
||||
ip_address: String,
|
||||
user: UserID,
|
||||
app: AppID,
|
||||
|
||||
// Timings
|
||||
created_at: DateTime<Utc>,
|
||||
|
|
@ -36,4 +37,8 @@ impl RefreshToken {
|
|||
pub fn user(&self) -> &UserID {
|
||||
&self.user
|
||||
}
|
||||
|
||||
pub fn app(&self) -> &AppID {
|
||||
&self.app
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue