Some changes
parent
b423a57a9b
commit
4c07e18787
|
@ -5,10 +5,14 @@ use rand::{thread_rng, Rng};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sha2::Sha256;
|
use sha2::Sha256;
|
||||||
|
|
||||||
use crate::{
|
#[derive(Debug, Deserialize, Serialize, Clone)]
|
||||||
errors::{RbError, RbResult},
|
pub struct JwtConf {
|
||||||
RbJwtConf,
|
key: String,
|
||||||
};
|
refresh_token_size: usize,
|
||||||
|
refresh_token_expire: i64,
|
||||||
|
}
|
||||||
|
|
||||||
|
use crate::errors::{RbError, RbResult};
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
|
@ -26,7 +30,7 @@ pub struct Claims {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn generate_jwt_token(
|
pub fn generate_jwt_token(
|
||||||
jwt: &RbJwtConf,
|
jwt: &JwtConf,
|
||||||
id: uuid::Uuid,
|
id: uuid::Uuid,
|
||||||
username: String,
|
username: String,
|
||||||
is_admin: bool,
|
is_admin: bool,
|
||||||
|
@ -64,7 +68,7 @@ pub fn generate_jwt_token(
|
||||||
|
|
||||||
pub fn refresh_token(
|
pub fn refresh_token(
|
||||||
conn: &PgConnection,
|
conn: &PgConnection,
|
||||||
jwt: &RbJwtConf,
|
jwt: &JwtConf,
|
||||||
refresh_token: &str,
|
refresh_token: &str,
|
||||||
) -> RbResult<JWTResponse> {
|
) -> RbResult<JWTResponse> {
|
||||||
let token_bytes =
|
let token_bytes =
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
use serde::{Serialize, Deserialize}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize, Serialize, Clone)]
|
||||||
|
pub struct RbJwtConf {
|
||||||
|
key: String,
|
||||||
|
refresh_token_size: usize,
|
||||||
|
refresh_token_expire: i64,
|
||||||
|
}
|
|
@ -1,3 +1,4 @@
|
||||||
pub mod auth;
|
pub mod auth;
|
||||||
|
pub mod config;
|
||||||
pub mod errors;
|
pub mod errors;
|
||||||
pub mod guards;
|
pub mod guards;
|
||||||
|
|
Loading…
Reference in New Issue