7 Commits
Author SHA1 Message Date
phoenix 438b19e170 Update dependencies (#17)
Rust Build / Rustfmt (push) Successful in 44s
Rust Build / Clippy (push) Successful in 1m10s
Rust Build / Test Suite (push) Failing after 2m0s
Rust Build / build (push) Successful in 2m7s
Rust Build / Check (push) Successful in 1m12s
Rust Build / Check (pull_request) Has been cancelled
Rust Build / Clippy (pull_request) Has been cancelled
Rust Build / Rustfmt (pull_request) Has been cancelled
Reviewed-on: phoenix/textsender_auth#17
2026-06-27 17:47:19 -04:00
phoenix 69d908bac3 Update (#16)
Rust Build / Rustfmt (push) Successful in 1m26s
Rust Build / build (push) Successful in 1m45s
Rust Build / Check (push) Successful in 2m14s
Rust Build / Test Suite (push) Successful in 2m18s
Rust Build / Clippy (push) Successful in 1m40s
Rust Build / Rustfmt (pull_request) Successful in 54s
Rust Build / Check (pull_request) Successful in 1m28s
Rust Build / Clippy (pull_request) Successful in 1m41s
Reviewed-on: phoenix/textsender_auth#16
2026-06-14 18:51:51 -04:00
phoenix 7d2faba4f2 Update packages (#15)
Rust Build / Rustfmt (push) Successful in 59s
Rust Build / Test Suite (push) Successful in 1m50s
Rust Build / Clippy (push) Successful in 1m12s
Rust Build / Check (push) Successful in 2m30s
Rust Build / build (push) Successful in 1m45s
Reviewed-on: phoenix/textsender_auth#15
2026-06-13 19:06:51 -04:00
phoenix e9b59fc1dd Update packages (#14)
Rust Build / Rustfmt (push) Successful in 59s
Rust Build / Test Suite (push) Successful in 1m34s
Rust Build / Check (push) Successful in 2m1s
Rust Build / Clippy (push) Successful in 1m13s
Rust Build / build (push) Successful in 2m17s
Reviewed-on: phoenix/textsender_auth#14
2026-06-13 17:01:54 -04:00
phoenix 1ab7bd4ae1 gitignore cleanup (#13)
Rust Build / Rustfmt (push) Successful in 41s
Rust Build / Check (push) Successful in 1m31s
Rust Build / Clippy (push) Successful in 1m46s
Rust Build / Test Suite (push) Successful in 2m35s
Rust Build / build (push) Successful in 1m49s
Rust Build / Rustfmt (pull_request) Successful in 40s
Rust Build / Check (pull_request) Successful in 1m44s
Rust Build / Test Suite (pull_request) Successful in 1m31s
Rust Build / Clippy (pull_request) Successful in 2m10s
Rust Build / build (pull_request) Successful in 3m26s
Reviewed-on: phoenix/textsender_auth#13
2026-06-13 12:54:17 -04:00
phoenix d83591c8a4 Updating package name (#12)
Rust Build / Rustfmt (push) Successful in 52s
Rust Build / Check (push) Successful in 1m21s
Rust Build / Test Suite (push) Successful in 1m52s
Rust Build / Clippy (push) Successful in 2m0s
Rust Build / build (push) Successful in 1m42s
Reviewed-on: phoenix/textsender-auth#12
2026-06-13 12:42:25 -04:00
phoenix 0cab4e8530 Update postgresql port (#11)
Rust Build / Test Suite (push) Successful in 1m6s
Rust Build / Check (push) Successful in 1m7s
Rust Build / Rustfmt (push) Successful in 1m59s
Rust Build / Clippy (push) Successful in 1m43s
Rust Build / build (push) Successful in 2m28s
Reviewed-on: phoenix/textsender-auth#11
2026-06-13 11:26:43 -04:00
11 changed files with 618 additions and 419 deletions
+7 -7
View File
@@ -1,10 +1,10 @@
SECRET_KEY=NULqYIzgt28bTiyziCd7IOO7b6LnWDW! SECRET_KEY=NULqYIzgt28bTiyziCd7IOO7b6LnWDW!
DB_NAME=textsender_auth_db DB_AUTH_NAME=textsender_auth_db
DB_USER=textsender_auth DB_AUTH_USER=textsender_auth
DB_PASSWORD=password DB_AUTH_PASSWORD=password
DB_HOST=auth_db DB_AUTH_HOST=auth_db
DB_PORT=5432 DB_AUTH_PORT=5432
DB_SSLMODE=disable DB_AUTH_SSLMODE=disable
DATABASE_URL=postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:5432/${DB_NAME} DATABASE_URL=postgres://${DB_AUTH_USER}:${DB_AUTH_PASSWORD}@${DB_AUTH_HOST}:${DB_AUTH_PORT}/${DB_AUTH_NAME}
ENABLE_REGISTRATION=true ENABLE_REGISTRATION=true
ALLOWED_ORIGINS="http://textsender.com" ALLOWED_ORIGINS="http://textsender.com"
+7 -7
View File
@@ -1,10 +1,10 @@
SECRET_KEY=NULqYIzgt28bTiyziCd7IOO7b6LnWDW! SECRET_KEY=NULqYIzgt28bTiyziCd7IOO7b6LnWDW!
DB_NAME=textsender_auth_db DB_AUTH_NAME=textsender_auth_db
DB_USER=textsender_auth DB_AUTH_USER=textsender_auth
DB_PASSWORD=password DB_AUTH_PASSWORD=password
DB_HOST=localhost DB_AUTH_HOST=localhost
DB_PORT=5432 DB_AUTH_PORT=5432
DB_SSLMODE=disable DB_AUTH_SSLMODE=disable
DATABASE_URL=postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:5432/${DB_NAME} DATABASE_URL=postgres://${DB_AUTH_USER}:${DB_AUTH_PASSWORD}@${DB_AUTH_HOST}:${DB_AUTH_PORT}/${DB_AUTH_NAME}
ENABLE_REGISTRATION=true ENABLE_REGISTRATION=true
ALLOWED_ORIGINS="http://textsender.com" ALLOWED_ORIGINS="http://textsender.com"
+72
View File
@@ -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
+11 -9
View File
@@ -4,9 +4,10 @@ on:
push: push:
branches: branches:
- main - main
pull_request:
branches: concurrency:
- main group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs: jobs:
check: check:
@@ -16,7 +17,7 @@ jobs:
- uses: actions/checkout@v5 - uses: actions/checkout@v5
- uses: actions-rust-lang/setup-rust-toolchain@v1 - uses: actions-rust-lang/setup-rust-toolchain@v1
with: with:
toolchain: 1.95 toolchain: 1.96
- uses: Swatinem/rust-cache@v2 - uses: Swatinem/rust-cache@v2
- run: | - run: |
mkdir -p ~/.ssh mkdir -p ~/.ssh
@@ -41,6 +42,7 @@ jobs:
POSTGRES_USER: ${{ secrets.DB_TEST_USER || 'testuser' }} POSTGRES_USER: ${{ secrets.DB_TEST_USER || 'testuser' }}
POSTGRES_PASSWORD: ${{ secrets.DB_TEST_PASSWORD || 'testpassword' }} POSTGRES_PASSWORD: ${{ secrets.DB_TEST_PASSWORD || 'testpassword' }}
POSTGRES_DB: ${{ secrets.DB_TEST_NAME || 'testdb' }} POSTGRES_DB: ${{ secrets.DB_TEST_NAME || 'testdb' }}
POSTGRES_PORT: ${{ secrets.DB_PORT || 5432 }}
# Options to wait until the database is ready # Options to wait until the database is ready
options: >- options: >-
--health-cmd pg_isready --health-cmd pg_isready
@@ -52,7 +54,7 @@ jobs:
- uses: actions/checkout@v5 - uses: actions/checkout@v5
- uses: actions-rust-lang/setup-rust-toolchain@v1 - uses: actions-rust-lang/setup-rust-toolchain@v1
with: with:
toolchain: 1.95 toolchain: 1.96
- uses: Swatinem/rust-cache@v2 - uses: Swatinem/rust-cache@v2
# --- Add this step for explicit verification --- # --- Add this step for explicit verification ---
- name: Verify Docker Environment - name: Verify Docker Environment
@@ -71,7 +73,7 @@ jobs:
- name: Run tests - name: Run tests
env: env:
# Define DATABASE_URL for tests to use # 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 RUST_LOG: info # Optional: configure test log level
SECRET_KEY: ${{ secrets.TOKEN_SECRET_KEY }} SECRET_KEY: ${{ secrets.TOKEN_SECRET_KEY }}
# Make SSH agent available if tests fetch private dependencies # Make SSH agent available if tests fetch private dependencies
@@ -95,7 +97,7 @@ jobs:
- uses: actions/checkout@v5 - uses: actions/checkout@v5
- uses: actions-rust-lang/setup-rust-toolchain@v1 - uses: actions-rust-lang/setup-rust-toolchain@v1
with: with:
toolchain: 1.95 toolchain: 1.96
- uses: Swatinem/rust-cache@v2 - uses: Swatinem/rust-cache@v2
- run: rustup component add rustfmt - run: rustup component add rustfmt
- run: | - run: |
@@ -115,7 +117,7 @@ jobs:
- uses: actions/checkout@v5 - uses: actions/checkout@v5
- uses: actions-rust-lang/setup-rust-toolchain@v1 - uses: actions-rust-lang/setup-rust-toolchain@v1
with: with:
toolchain: 1.95 toolchain: 1.96
- uses: Swatinem/rust-cache@v2 - uses: Swatinem/rust-cache@v2
- run: rustup component add clippy - run: rustup component add clippy
- run: | - run: |
@@ -135,7 +137,7 @@ jobs:
- uses: actions/checkout@v5 - uses: actions/checkout@v5
- uses: actions-rust-lang/setup-rust-toolchain@v1 - uses: actions-rust-lang/setup-rust-toolchain@v1
with: with:
toolchain: 1.95 toolchain: 1.96
- uses: Swatinem/rust-cache@v2 - uses: Swatinem/rust-cache@v2
- run: | - run: |
mkdir -p ~/.ssh mkdir -p ~/.ssh
-2
View File
@@ -1,5 +1,3 @@
/textsender-auth
.env .env
.env.local .env.local
.env.docker .env.docker
Generated
+452 -294
View File
File diff suppressed because it is too large Load Diff
+10 -10
View File
@@ -1,27 +1,27 @@
[package] [package]
name = "textsender_auth" name = "textsender_auth"
version = "0.1.20" version = "0.2.0"
edition = "2024" edition = "2024"
rust-version = "1.95" rust-version = "1.96"
[dependencies] [dependencies]
axum = { version = "0.8.9" } axum = { version = "0.8.9" }
serde = { version = "1.0.228", features = ["derive"] } serde = { version = "1.0.228", features = ["derive"] }
serde_json = { version = "1.0.149" } serde_json = { version = "1.0.150" }
tokio = { version = "1.52.2", features = ["rt-multi-thread"] } tokio = { version = "1.52.3", features = ["rt-multi-thread"] }
tracing-subscriber = { version = "0.3.23" } tracing-subscriber = { version = "0.3.23" }
tower = { version = "0.5.3", features = ["full"] } tower = { version = "0.5.3", features = ["full"] }
tower-http = { version = "0.6.10", features = ["cors"] } tower-http = { version = "0.6.11", features = ["cors"] }
hyper = { version = "1.9.0" } hyper = { version = "1.10.1" }
sqlx = { version = "0.8.6", features = ["postgres", "runtime-tokio-native-tls", "time", "uuid"] } sqlx = { version = "0.9.0", features = ["runtime-tokio", "tls-native-tls", "postgres", "time", "uuid"] }
uuid = { version = "1.23.1", features = ["v4", "serde"] } uuid = { version = "1.23.3", features = ["v4", "serde"] }
argon2 = { version = "0.5.3", features = ["std"] } # Use the latest 0.5.x version argon2 = { version = "0.5.3", features = ["std"] } # Use the latest 0.5.x version
rand = { version = "0.10.1" } 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" } josekit = { version = "0.10.3" }
utoipa = { version = "5.5.0", features = ["axum_extras"] } utoipa = { version = "5.5.0", features = ["axum_extras"] }
utoipa-swagger-ui = { version = "9.0.2", features = ["axum"] } 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] [dev-dependencies]
http-body-util = { version = "0.1.3" } http-body-util = { version = "0.1.3" }
+1 -1
View File
@@ -1,7 +1,7 @@
# Stage 1: Build the application # Stage 1: Build the application
# Use a specific Rust version for reproducibility. Choose one that matches your development environment. # Use a specific Rust version for reproducibility. Choose one that matches your development environment.
# Using slim variant for smaller base image # 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 # Set the working directory inside the container
WORKDIR /usr/src/app WORKDIR /usr/src/app
+5 -4
View File
@@ -23,13 +23,14 @@ services:
container_name: textsender_auth_db # Optional: Give the container a specific name container_name: textsender_auth_db # Optional: Give the container a specific name
environment: environment:
# These MUST match the user, password, and database name in the DATABASE_URL above # These MUST match the user, password, and database name in the DATABASE_URL above
POSTGRES_USER: ${DB_USER:-textsender_op} POSTGRES_USER: ${DB_AUTH_USER:-textsender_op}
POSTGRES_PASSWORD: ${DB_PASSWORD:-password} POSTGRES_PASSWORD: ${DB_AUTH_PASSWORD:-password}
POSTGRES_DB: ${DB_NAME:-textsender_auth_db} POSTGRES_DB: ${DB_AUTH_NAME:-textsender_auth_db}
volumes: volumes:
# Persist database data using a named volume # Persist database data using a named volume
- postgres_data:/var/lib/postgresql - postgres_data:/var/lib/postgresql
ports: [] ports:
- "5433:5432"
healthcheck: healthcheck:
# Checks if Postgres is ready to accept connections # Checks if Postgres is ready to accept connections
test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB"] test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB"]
+44 -76
View File
@@ -189,10 +189,9 @@ pub async fn user_login(
let key = textsender_models::envy::environment::get_secret_key() let key = textsender_models::envy::environment::get_secret_key()
.await .await
.value; .value;
let (token_literal, duration) = let cst = token_stuff::create_token(&key, &user.id).unwrap();
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 current_time = time::OffsetDateTime::now_utc();
let _ = let _ =
repo::user::update_last_login(&pool, &user, &current_time) repo::user::update_last_login(&pool, &user, &current_time)
@@ -204,12 +203,12 @@ pub async fn user_login(
message: String::from("Successful"), message: String::from("Successful"),
data: vec![textsender_models::token::LoginResult { data: vec![textsender_models::token::LoginResult {
user_id: user.id, user_id: user.id,
access_token: token_literal, access_token: cst.access_token,
token_type: String::from( token_type: String::from(
textsender_models::token::TOKEN_TYPE, textsender_models::token::TOKEN_TYPE,
), ),
issued_at: duration, issued_at: cst.issued,
..Default::default() expires_in: cst.expires_in,
}], }],
}), }),
) )
@@ -330,10 +329,10 @@ pub async fn service_user_login(
let key = textsender_models::envy::environment::get_secret_key() let key = textsender_models::envy::environment::get_secret_key()
.await .await
.value; .value;
let (token_literal, duration) = let cst =
token_stuff::create_token(&key, &service_user.id).unwrap(); 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 current_time = time::OffsetDateTime::now_utc();
let _ = repo::service::update_last_login( let _ = repo::service::update_last_login(
&pool, &pool,
@@ -350,12 +349,12 @@ pub async fn service_user_login(
), ),
data: vec![textsender_models::token::LoginResult { data: vec![textsender_models::token::LoginResult {
user_id: service_user.id, user_id: service_user.id,
access_token: token_literal, access_token: cst.access_token,
token_type: String::from( token_type: String::from(
textsender_models::token::TOKEN_TYPE, textsender_models::token::TOKEN_TYPE,
), ),
issued_at: duration, issued_at: cst.issued,
..Default::default() expires_in: cst.expires_in,
}], }],
}), }),
) )
@@ -440,12 +439,10 @@ pub async fn refresh_token(
if token_stuff::verify_token(&key, &payload.access_token) { if token_stuff::verify_token(&key, &payload.access_token) {
match token_stuff::extract_id_from_token(&key, &payload.access_token) { match token_stuff::extract_id_from_token(&key, &payload.access_token) {
Ok(id) => { Ok(id) => {
let generate_service_token = |id, key| -> (Option<String>, Option<i64>) { let generate_service_token =
match token_stuff::create_service_refresh_token(key, id) { |id, key| -> Option<textsender_models::token::CreateTokenResult> {
Ok((token, issued)) => (Some(token), Some(issued)), token_stuff::create_service_refresh_token(key, id).ok()
Err(_err) => (None, None), };
}
};
let mut response = response::RefreshTokenResponse { let mut response = response::RefreshTokenResponse {
message: String::new(), message: String::new(),
@@ -453,21 +450,43 @@ pub async fn refresh_token(
}; };
match repo::user::get_with_id(&pool, &id).await { match repo::user::get_with_id(&pool, &id).await {
Ok(_user) => { Ok(_user) => match generate_service_token(&id, &key) {
let (refresh_token, issued) = generate_service_token(&id, &key); Some(cst) => {
match refresh_token { response.message =
Some(token) => match issued { String::from(super::messages::SUCCESSFUL_MESSAGE);
Some(issued_at) => { 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 = response.message =
String::from(super::messages::SUCCESSFUL_MESSAGE); String::from(super::messages::SUCCESSFUL_MESSAGE);
let lr = textsender_models::token::LoginResult { let lr = textsender_models::token::LoginResult {
user_id: id, user_id: id,
access_token: token, access_token: cst.access_token,
issued_at, issued_at: cst.issued,
expires_in: cst.expires_in,
token_type: String::from( token_type: String::from(
textsender_models::token::TOKEN_TYPE, textsender_models::token::TOKEN_TYPE,
), ),
..Default::default()
}; };
response.data.push(lr); response.data.push(lr);
(axum::http::StatusCode::OK, axum::Json(response)) (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) => ( Err(err) => (
axum::http::StatusCode::INTERNAL_SERVER_ERROR, axum::http::StatusCode::INTERNAL_SERVER_ERROR,
axum::Json(response::RefreshTokenResponse { axum::Json(response::RefreshTokenResponse {
+9 -9
View File
@@ -19,12 +19,12 @@ pub fn get_expiration(issued: &time::OffsetDateTime) -> Result<time::OffsetDateT
pub fn create_token( pub fn create_token(
provided_key: &String, provided_key: &String,
id: &uuid::Uuid, id: &uuid::Uuid,
) -> Result<(String, i64), josekit::JoseError> { ) -> Result<textsender_models::token::CreateTokenResult, josekit::JoseError> {
let resource = textsender_models::token::TokenResource { let resource = textsender_models::token::TokenResource {
message: String::from(MESSAGE), message: String::from(MESSAGE),
issuer: String::from(ISSUER), issuer: String::from(ISSUER),
audiences: vec![String::from(AUDIENCE)], audiences: vec![String::from(AUDIENCE)],
id: *id, user_id: *id,
}; };
textsender_models::token::create_token(provided_key, &resource, time::Duration::hours(4)) 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( pub fn create_service_token(
provided: &String, provided: &String,
id: &uuid::Uuid, id: &uuid::Uuid,
) -> Result<(String, i64), josekit::JoseError> { ) -> Result<textsender_models::token::CreateTokenResult, josekit::JoseError> {
let resource = textsender_models::token::TokenResource { let resource = textsender_models::token::TokenResource {
message: String::from(SERVICE_SUBJECT), message: String::from(SERVICE_SUBJECT),
issuer: String::from(ISSUER), issuer: String::from(ISSUER),
audiences: vec![String::from(AUDIENCE)], audiences: vec![String::from(AUDIENCE)],
id: *id, user_id: *id,
}; };
textsender_models::token::create_token(provided, &resource, time::Duration::hours(1)) 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( pub fn create_service_refresh_token(
key: &String, key: &String,
id: &uuid::Uuid, id: &uuid::Uuid,
) -> Result<(String, i64), josekit::JoseError> { ) -> Result<textsender_models::token::CreateTokenResult, josekit::JoseError> {
let resource = textsender_models::token::TokenResource { let resource = textsender_models::token::TokenResource {
message: String::from(SERVICE_SUBJECT), message: String::from(SERVICE_SUBJECT),
issuer: String::from(ISSUER), issuer: String::from(ISSUER),
audiences: vec![String::from(AUDIENCE)], audiences: vec![String::from(AUDIENCE)],
id: *id, user_id: *id,
}; };
textsender_models::token::create_token(key, &resource, time::Duration::hours(4)) 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> { pub fn extract_id_from_token(key: &String, token: &String) -> Result<uuid::Uuid, std::io::Error> {
match get_payload(key, token) { 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()) { Some(id) => match uuid::Uuid::parse_str(id.as_str().unwrap()) {
Ok(extracted) => Ok(extracted), Ok(extracted) => Ok(extracted),
Err(err) => Err(std::io::Error::other(err.to_string())), Err(err) => Err(std::io::Error::other(err.to_string())),
@@ -125,8 +125,8 @@ mod tests {
.value; .value;
let id = uuid::Uuid::new_v4(); let id = uuid::Uuid::new_v4();
match create_token(&special_key, &id) { match create_token(&special_key, &id) {
Ok((token, _duration)) => { Ok(cst) => {
let result = verify_token(&special_key, &token); let result = verify_token(&special_key, &cst.access_token);
assert!(result, "Token not verified"); assert!(result, "Token not verified");
} }
Err(err) => { Err(err) => {