Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
438b19e170 | ||
|
|
69d908bac3 | ||
|
|
7d2faba4f2 | ||
|
|
e9b59fc1dd | ||
|
|
1ab7bd4ae1 | ||
|
|
d83591c8a4 | ||
|
|
0cab4e8530 |
+7
-7
@@ -1,10 +1,10 @@
|
||||
SECRET_KEY=NULqYIzgt28bTiyziCd7IOO7b6LnWDW!
|
||||
DB_NAME=textsender_auth_db
|
||||
DB_USER=textsender_auth
|
||||
DB_PASSWORD=password
|
||||
DB_HOST=auth_db
|
||||
DB_PORT=5432
|
||||
DB_SSLMODE=disable
|
||||
DATABASE_URL=postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:5432/${DB_NAME}
|
||||
DB_AUTH_NAME=textsender_auth_db
|
||||
DB_AUTH_USER=textsender_auth
|
||||
DB_AUTH_PASSWORD=password
|
||||
DB_AUTH_HOST=auth_db
|
||||
DB_AUTH_PORT=5432
|
||||
DB_AUTH_SSLMODE=disable
|
||||
DATABASE_URL=postgres://${DB_AUTH_USER}:${DB_AUTH_PASSWORD}@${DB_AUTH_HOST}:${DB_AUTH_PORT}/${DB_AUTH_NAME}
|
||||
ENABLE_REGISTRATION=true
|
||||
ALLOWED_ORIGINS="http://textsender.com"
|
||||
|
||||
+7
-7
@@ -1,10 +1,10 @@
|
||||
SECRET_KEY=NULqYIzgt28bTiyziCd7IOO7b6LnWDW!
|
||||
DB_NAME=textsender_auth_db
|
||||
DB_USER=textsender_auth
|
||||
DB_PASSWORD=password
|
||||
DB_HOST=localhost
|
||||
DB_PORT=5432
|
||||
DB_SSLMODE=disable
|
||||
DATABASE_URL=postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:5432/${DB_NAME}
|
||||
DB_AUTH_NAME=textsender_auth_db
|
||||
DB_AUTH_USER=textsender_auth
|
||||
DB_AUTH_PASSWORD=password
|
||||
DB_AUTH_HOST=localhost
|
||||
DB_AUTH_PORT=5432
|
||||
DB_AUTH_SSLMODE=disable
|
||||
DATABASE_URL=postgres://${DB_AUTH_USER}:${DB_AUTH_PASSWORD}@${DB_AUTH_HOST}:${DB_AUTH_PORT}/${DB_AUTH_NAME}
|
||||
ENABLE_REGISTRATION=true
|
||||
ALLOWED_ORIGINS="http://textsender.com"
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
name: Rust Build
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
check:
|
||||
name: Check
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
toolchain: 1.96
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
- run: |
|
||||
mkdir -p ~/.ssh
|
||||
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/textsender-models_deploy_key
|
||||
chmod 600 ~/.ssh/textsender-models_deploy_key
|
||||
ssh-keyscan ${{ secrets.MY_HOST }} >> ~/.ssh/known_hosts
|
||||
|
||||
eval $(ssh-agent -s)
|
||||
ssh-add -v ~/.ssh/textsender-models_deploy_key
|
||||
|
||||
cargo check
|
||||
|
||||
|
||||
fmt:
|
||||
name: Rustfmt
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
toolchain: 1.96
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
- run: rustup component add rustfmt
|
||||
- run: |
|
||||
mkdir -p ~/.ssh
|
||||
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/textsender-models_deploy_key
|
||||
chmod 600 ~/.ssh/textsender-models_deploy_key
|
||||
ssh-keyscan ${{ secrets.MY_HOST }} >> ~/.ssh/known_hosts
|
||||
|
||||
eval $(ssh-agent -s)
|
||||
ssh-add -v ~/.ssh/textsender-models_deploy_key
|
||||
cargo fmt --all -- --check
|
||||
|
||||
clippy:
|
||||
name: Clippy
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
toolchain: 1.96
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
- run: rustup component add clippy
|
||||
- run: |
|
||||
mkdir -p ~/.ssh
|
||||
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/textsender-models_deploy_key
|
||||
chmod 600 ~/.ssh/textsender-models_deploy_key
|
||||
ssh-keyscan ${{ secrets.MY_HOST }} >> ~/.ssh/known_hosts
|
||||
|
||||
eval $(ssh-agent -s)
|
||||
ssh-add -v ~/.ssh/textsender-models_deploy_key
|
||||
cargo clippy -- -D warnings
|
||||
@@ -4,9 +4,10 @@ on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
check:
|
||||
@@ -16,7 +17,7 @@ jobs:
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
toolchain: 1.95
|
||||
toolchain: 1.96
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
- run: |
|
||||
mkdir -p ~/.ssh
|
||||
@@ -41,6 +42,7 @@ jobs:
|
||||
POSTGRES_USER: ${{ secrets.DB_TEST_USER || 'testuser' }}
|
||||
POSTGRES_PASSWORD: ${{ secrets.DB_TEST_PASSWORD || 'testpassword' }}
|
||||
POSTGRES_DB: ${{ secrets.DB_TEST_NAME || 'testdb' }}
|
||||
POSTGRES_PORT: ${{ secrets.DB_PORT || 5432 }}
|
||||
# Options to wait until the database is ready
|
||||
options: >-
|
||||
--health-cmd pg_isready
|
||||
@@ -52,7 +54,7 @@ jobs:
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
toolchain: 1.95
|
||||
toolchain: 1.96
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
# --- Add this step for explicit verification ---
|
||||
- name: Verify Docker Environment
|
||||
@@ -71,7 +73,7 @@ jobs:
|
||||
- name: Run tests
|
||||
env:
|
||||
# Define DATABASE_URL for tests to use
|
||||
DATABASE_URL: postgresql://${{ secrets.DB_TEST_USER || 'testuser' }}:${{ secrets.DB_TEST_PASSWORD || 'testpassword' }}@postgres:5432/${{ secrets.DB_TEST_NAME || 'testdb' }}
|
||||
DATABASE_URL: postgresql://${{ secrets.DB_TEST_USER || 'testuser' }}:${{ secrets.DB_TEST_PASSWORD || 'testpassword' }}@postgres:${{ secrets.DB_PORT || 5432 }}/${{ secrets.DB_TEST_NAME || 'testdb' }}
|
||||
RUST_LOG: info # Optional: configure test log level
|
||||
SECRET_KEY: ${{ secrets.TOKEN_SECRET_KEY }}
|
||||
# Make SSH agent available if tests fetch private dependencies
|
||||
@@ -95,7 +97,7 @@ jobs:
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
toolchain: 1.95
|
||||
toolchain: 1.96
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
- run: rustup component add rustfmt
|
||||
- run: |
|
||||
@@ -115,7 +117,7 @@ jobs:
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
toolchain: 1.95
|
||||
toolchain: 1.96
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
- run: rustup component add clippy
|
||||
- run: |
|
||||
@@ -135,7 +137,7 @@ jobs:
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
toolchain: 1.95
|
||||
toolchain: 1.96
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
- run: |
|
||||
mkdir -p ~/.ssh
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
/textsender-auth
|
||||
|
||||
.env
|
||||
.env.local
|
||||
.env.docker
|
||||
|
||||
Generated
+452
-294
File diff suppressed because it is too large
Load Diff
+10
-10
@@ -1,27 +1,27 @@
|
||||
[package]
|
||||
name = "textsender_auth"
|
||||
version = "0.1.20"
|
||||
version = "0.2.0"
|
||||
edition = "2024"
|
||||
rust-version = "1.95"
|
||||
rust-version = "1.96"
|
||||
|
||||
[dependencies]
|
||||
axum = { version = "0.8.9" }
|
||||
serde = { version = "1.0.228", features = ["derive"] }
|
||||
serde_json = { version = "1.0.149" }
|
||||
tokio = { version = "1.52.2", features = ["rt-multi-thread"] }
|
||||
serde_json = { version = "1.0.150" }
|
||||
tokio = { version = "1.52.3", features = ["rt-multi-thread"] }
|
||||
tracing-subscriber = { version = "0.3.23" }
|
||||
tower = { version = "0.5.3", features = ["full"] }
|
||||
tower-http = { version = "0.6.10", features = ["cors"] }
|
||||
hyper = { version = "1.9.0" }
|
||||
sqlx = { version = "0.8.6", features = ["postgres", "runtime-tokio-native-tls", "time", "uuid"] }
|
||||
uuid = { version = "1.23.1", features = ["v4", "serde"] }
|
||||
tower-http = { version = "0.6.11", features = ["cors"] }
|
||||
hyper = { version = "1.10.1" }
|
||||
sqlx = { version = "0.9.0", features = ["runtime-tokio", "tls-native-tls", "postgres", "time", "uuid"] }
|
||||
uuid = { version = "1.23.3", features = ["v4", "serde"] }
|
||||
argon2 = { version = "0.5.3", features = ["std"] } # Use the latest 0.5.x version
|
||||
rand = { version = "0.10.1" }
|
||||
time = { version = "0.3.47", features = ["macros", "serde"] }
|
||||
time = { version = "0.3.49", features = ["macros", "serde"] }
|
||||
josekit = { version = "0.10.3" }
|
||||
utoipa = { version = "5.5.0", features = ["axum_extras"] }
|
||||
utoipa-swagger-ui = { version = "9.0.2", features = ["axum"] }
|
||||
textsender_models = { git = "ssh://git@git.kundeng.us/phoenix/textsender-models.git", tag = "v0.3.0" }
|
||||
textsender_models = { git = "ssh://git@git.kundeng.us/phoenix/textsender_models.git", tag = "v0.4.10", features = ["config", "user"] }
|
||||
|
||||
[dev-dependencies]
|
||||
http-body-util = { version = "0.1.3" }
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
# Stage 1: Build the application
|
||||
# Use a specific Rust version for reproducibility. Choose one that matches your development environment.
|
||||
# Using slim variant for smaller base image
|
||||
FROM rust:1.95 as builder
|
||||
FROM rust:1.96 as builder
|
||||
|
||||
# Set the working directory inside the container
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
+5
-4
@@ -23,13 +23,14 @@ services:
|
||||
container_name: textsender_auth_db # Optional: Give the container a specific name
|
||||
environment:
|
||||
# These MUST match the user, password, and database name in the DATABASE_URL above
|
||||
POSTGRES_USER: ${DB_USER:-textsender_op}
|
||||
POSTGRES_PASSWORD: ${DB_PASSWORD:-password}
|
||||
POSTGRES_DB: ${DB_NAME:-textsender_auth_db}
|
||||
POSTGRES_USER: ${DB_AUTH_USER:-textsender_op}
|
||||
POSTGRES_PASSWORD: ${DB_AUTH_PASSWORD:-password}
|
||||
POSTGRES_DB: ${DB_AUTH_NAME:-textsender_auth_db}
|
||||
volumes:
|
||||
# Persist database data using a named volume
|
||||
- postgres_data:/var/lib/postgresql
|
||||
ports: []
|
||||
ports:
|
||||
- "5433:5432"
|
||||
healthcheck:
|
||||
# Checks if Postgres is ready to accept connections
|
||||
test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB"]
|
||||
|
||||
+44
-76
@@ -189,10 +189,9 @@ pub async fn user_login(
|
||||
let key = textsender_models::envy::environment::get_secret_key()
|
||||
.await
|
||||
.value;
|
||||
let (token_literal, duration) =
|
||||
token_stuff::create_token(&key, &user.id).unwrap();
|
||||
let cst = token_stuff::create_token(&key, &user.id).unwrap();
|
||||
|
||||
if token_stuff::verify_token(&key, &token_literal) {
|
||||
if token_stuff::verify_token(&key, &cst.access_token) {
|
||||
let current_time = time::OffsetDateTime::now_utc();
|
||||
let _ =
|
||||
repo::user::update_last_login(&pool, &user, ¤t_time)
|
||||
@@ -204,12 +203,12 @@ pub async fn user_login(
|
||||
message: String::from("Successful"),
|
||||
data: vec![textsender_models::token::LoginResult {
|
||||
user_id: user.id,
|
||||
access_token: token_literal,
|
||||
access_token: cst.access_token,
|
||||
token_type: String::from(
|
||||
textsender_models::token::TOKEN_TYPE,
|
||||
),
|
||||
issued_at: duration,
|
||||
..Default::default()
|
||||
issued_at: cst.issued,
|
||||
expires_in: cst.expires_in,
|
||||
}],
|
||||
}),
|
||||
)
|
||||
@@ -330,10 +329,10 @@ pub async fn service_user_login(
|
||||
let key = textsender_models::envy::environment::get_secret_key()
|
||||
.await
|
||||
.value;
|
||||
let (token_literal, duration) =
|
||||
let cst =
|
||||
token_stuff::create_token(&key, &service_user.id).unwrap();
|
||||
|
||||
if token_stuff::verify_token(&key, &token_literal) {
|
||||
if token_stuff::verify_token(&key, &cst.access_token) {
|
||||
let current_time = time::OffsetDateTime::now_utc();
|
||||
let _ = repo::service::update_last_login(
|
||||
&pool,
|
||||
@@ -350,12 +349,12 @@ pub async fn service_user_login(
|
||||
),
|
||||
data: vec![textsender_models::token::LoginResult {
|
||||
user_id: service_user.id,
|
||||
access_token: token_literal,
|
||||
access_token: cst.access_token,
|
||||
token_type: String::from(
|
||||
textsender_models::token::TOKEN_TYPE,
|
||||
),
|
||||
issued_at: duration,
|
||||
..Default::default()
|
||||
issued_at: cst.issued,
|
||||
expires_in: cst.expires_in,
|
||||
}],
|
||||
}),
|
||||
)
|
||||
@@ -440,12 +439,10 @@ pub async fn refresh_token(
|
||||
if token_stuff::verify_token(&key, &payload.access_token) {
|
||||
match token_stuff::extract_id_from_token(&key, &payload.access_token) {
|
||||
Ok(id) => {
|
||||
let generate_service_token = |id, key| -> (Option<String>, Option<i64>) {
|
||||
match token_stuff::create_service_refresh_token(key, id) {
|
||||
Ok((token, issued)) => (Some(token), Some(issued)),
|
||||
Err(_err) => (None, None),
|
||||
}
|
||||
};
|
||||
let generate_service_token =
|
||||
|id, key| -> Option<textsender_models::token::CreateTokenResult> {
|
||||
token_stuff::create_service_refresh_token(key, id).ok()
|
||||
};
|
||||
|
||||
let mut response = response::RefreshTokenResponse {
|
||||
message: String::new(),
|
||||
@@ -453,21 +450,43 @@ pub async fn refresh_token(
|
||||
};
|
||||
|
||||
match repo::user::get_with_id(&pool, &id).await {
|
||||
Ok(_user) => {
|
||||
let (refresh_token, issued) = generate_service_token(&id, &key);
|
||||
match refresh_token {
|
||||
Some(token) => match issued {
|
||||
Some(issued_at) => {
|
||||
Ok(_user) => match generate_service_token(&id, &key) {
|
||||
Some(cst) => {
|
||||
response.message =
|
||||
String::from(super::messages::SUCCESSFUL_MESSAGE);
|
||||
let lr = textsender_models::token::LoginResult {
|
||||
user_id: id,
|
||||
access_token: cst.access_token,
|
||||
issued_at: cst.issued,
|
||||
expires_in: cst.expires_in,
|
||||
token_type: String::from(textsender_models::token::TOKEN_TYPE),
|
||||
};
|
||||
response.data.push(lr);
|
||||
(axum::http::StatusCode::OK, axum::Json(response))
|
||||
}
|
||||
None => (
|
||||
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||
axum::Json(response::RefreshTokenResponse {
|
||||
message: String::from("Refresh token not generated"),
|
||||
data: Vec::new(),
|
||||
}),
|
||||
),
|
||||
},
|
||||
Err(err) => {
|
||||
println!("Unable to find user, checking service user: {err:?}");
|
||||
match repo::service::get(&pool, &id).await {
|
||||
Ok(_service_user) => match generate_service_token(&id, &key) {
|
||||
Some(cst) => {
|
||||
response.message =
|
||||
String::from(super::messages::SUCCESSFUL_MESSAGE);
|
||||
let lr = textsender_models::token::LoginResult {
|
||||
user_id: id,
|
||||
access_token: token,
|
||||
issued_at,
|
||||
access_token: cst.access_token,
|
||||
issued_at: cst.issued,
|
||||
expires_in: cst.expires_in,
|
||||
token_type: String::from(
|
||||
textsender_models::token::TOKEN_TYPE,
|
||||
),
|
||||
..Default::default()
|
||||
};
|
||||
response.data.push(lr);
|
||||
(axum::http::StatusCode::OK, axum::Json(response))
|
||||
@@ -480,57 +499,6 @@ pub async fn refresh_token(
|
||||
}),
|
||||
),
|
||||
},
|
||||
None => (
|
||||
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||
axum::Json(response::RefreshTokenResponse {
|
||||
message: String::from("Refresh token not generated"),
|
||||
data: Vec::new(),
|
||||
}),
|
||||
),
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
println!("Unable to find user, checking service user: {err:?}");
|
||||
match repo::service::get(&pool, &id).await {
|
||||
Ok(_service_user) => {
|
||||
let (refresh_token, issued) = generate_service_token(&id, &key);
|
||||
match refresh_token {
|
||||
Some(token) => match issued {
|
||||
Some(issued_at) => {
|
||||
response.message = String::from(
|
||||
super::messages::SUCCESSFUL_MESSAGE,
|
||||
);
|
||||
let lr = textsender_models::token::LoginResult {
|
||||
user_id: id,
|
||||
access_token: token,
|
||||
issued_at,
|
||||
token_type: String::from(
|
||||
textsender_models::token::TOKEN_TYPE,
|
||||
),
|
||||
..Default::default()
|
||||
};
|
||||
response.data.push(lr);
|
||||
(axum::http::StatusCode::OK, axum::Json(response))
|
||||
}
|
||||
None => (
|
||||
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||
axum::Json(response::RefreshTokenResponse {
|
||||
message: String::from("Issued at not returned"),
|
||||
data: Vec::new(),
|
||||
}),
|
||||
),
|
||||
},
|
||||
None => (
|
||||
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||
axum::Json(response::RefreshTokenResponse {
|
||||
message: String::from(
|
||||
"Refresh token not generated",
|
||||
),
|
||||
data: Vec::new(),
|
||||
}),
|
||||
),
|
||||
}
|
||||
}
|
||||
Err(err) => (
|
||||
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||
axum::Json(response::RefreshTokenResponse {
|
||||
|
||||
@@ -19,12 +19,12 @@ pub fn get_expiration(issued: &time::OffsetDateTime) -> Result<time::OffsetDateT
|
||||
pub fn create_token(
|
||||
provided_key: &String,
|
||||
id: &uuid::Uuid,
|
||||
) -> Result<(String, i64), josekit::JoseError> {
|
||||
) -> Result<textsender_models::token::CreateTokenResult, josekit::JoseError> {
|
||||
let resource = textsender_models::token::TokenResource {
|
||||
message: String::from(MESSAGE),
|
||||
issuer: String::from(ISSUER),
|
||||
audiences: vec![String::from(AUDIENCE)],
|
||||
id: *id,
|
||||
user_id: *id,
|
||||
};
|
||||
textsender_models::token::create_token(provided_key, &resource, time::Duration::hours(4))
|
||||
}
|
||||
@@ -32,12 +32,12 @@ pub fn create_token(
|
||||
pub fn create_service_token(
|
||||
provided: &String,
|
||||
id: &uuid::Uuid,
|
||||
) -> Result<(String, i64), josekit::JoseError> {
|
||||
) -> Result<textsender_models::token::CreateTokenResult, josekit::JoseError> {
|
||||
let resource = textsender_models::token::TokenResource {
|
||||
message: String::from(SERVICE_SUBJECT),
|
||||
issuer: String::from(ISSUER),
|
||||
audiences: vec![String::from(AUDIENCE)],
|
||||
id: *id,
|
||||
user_id: *id,
|
||||
};
|
||||
textsender_models::token::create_token(provided, &resource, time::Duration::hours(1))
|
||||
}
|
||||
@@ -45,12 +45,12 @@ pub fn create_service_token(
|
||||
pub fn create_service_refresh_token(
|
||||
key: &String,
|
||||
id: &uuid::Uuid,
|
||||
) -> Result<(String, i64), josekit::JoseError> {
|
||||
) -> Result<textsender_models::token::CreateTokenResult, josekit::JoseError> {
|
||||
let resource = textsender_models::token::TokenResource {
|
||||
message: String::from(SERVICE_SUBJECT),
|
||||
issuer: String::from(ISSUER),
|
||||
audiences: vec![String::from(AUDIENCE)],
|
||||
id: *id,
|
||||
user_id: *id,
|
||||
};
|
||||
textsender_models::token::create_token(key, &resource, time::Duration::hours(4))
|
||||
}
|
||||
@@ -67,7 +67,7 @@ pub fn verify_token(key: &String, token: &String) -> bool {
|
||||
|
||||
pub fn extract_id_from_token(key: &String, token: &String) -> Result<uuid::Uuid, std::io::Error> {
|
||||
match get_payload(key, token) {
|
||||
Ok((payload, _header)) => match payload.claim("id") {
|
||||
Ok((payload, _header)) => match payload.claim("user_id") {
|
||||
Some(id) => match uuid::Uuid::parse_str(id.as_str().unwrap()) {
|
||||
Ok(extracted) => Ok(extracted),
|
||||
Err(err) => Err(std::io::Error::other(err.to_string())),
|
||||
@@ -125,8 +125,8 @@ mod tests {
|
||||
.value;
|
||||
let id = uuid::Uuid::new_v4();
|
||||
match create_token(&special_key, &id) {
|
||||
Ok((token, _duration)) => {
|
||||
let result = verify_token(&special_key, &token);
|
||||
Ok(cst) => {
|
||||
let result = verify_token(&special_key, &cst.access_token);
|
||||
assert!(result, "Token not verified");
|
||||
}
|
||||
Err(err) => {
|
||||
|
||||
Reference in New Issue
Block a user