refactoring token -> claim processing
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
use dashmap::DashMap;
|
||||
use reqwest::StatusCode;
|
||||
use std::sync::Arc;
|
||||
use axum::extract::{ws::{Message, WebSocket, WebSocketUpgrade}, State};
|
||||
use axum::{Extension, extract::{State, ws::{Message, WebSocket, WebSocketUpgrade}}};
|
||||
use tokio::sync::mpsc;
|
||||
use axum::extract::Path;
|
||||
use axum::response::IntoResponse;
|
||||
//use futures_util::stream::stream::StreamExt;
|
||||
use futures_util::{StreamExt, SinkExt};
|
||||
|
||||
use crate::utils::{auth::AuthClaims, db_pool::{AppState, HotelPool}};
|
||||
use crate::utils::{auth::{AuthClaims, JwtKeys, auth_claims_from_token}, db_pool::{AppState, HotelPool}};
|
||||
|
||||
|
||||
|
||||
@@ -89,12 +90,37 @@ async fn handle_socket(
|
||||
}
|
||||
|
||||
pub async fn ws_handler(
|
||||
AuthClaims {user_id, hotel_id}: AuthClaims,
|
||||
//AuthClaims {user_id, hotel_id}: AuthClaims,
|
||||
ws: WebSocketUpgrade,
|
||||
Extension(keys): Extension<JwtKeys>,
|
||||
State(state): State<AppState>,
|
||||
//Path((hotel_id, user_id)): Path<(i32, i32)>,
|
||||
Path((req_token)): Path<(String)>,
|
||||
) -> impl IntoResponse {
|
||||
ws.on_upgrade(move |socket| handle_socket(socket, state, hotel_id, user_id))
|
||||
|
||||
|
||||
let token = req_token;
|
||||
|
||||
let claims = match auth_claims_from_token(&token, &keys) {
|
||||
Err(_) => {
|
||||
print!("error during auth claims processing");
|
||||
return StatusCode::UNAUTHORIZED.into_response();
|
||||
|
||||
}
|
||||
Ok(c) => c
|
||||
|
||||
};
|
||||
|
||||
print!("{token}, web socket tried to connect", );
|
||||
|
||||
/*
|
||||
let claims = match auth_claims_from_token(&token, &keys) {
|
||||
Ok(c) => c,
|
||||
Err(_) => return StatusCode::UNAUTHORIZED.into_response(),
|
||||
};
|
||||
*/
|
||||
|
||||
|
||||
ws.on_upgrade(move |socket| handle_socket(socket, state, claims.hotel_id, claims.user_id))
|
||||
}
|
||||
|
||||
fn print_ws_state(state: &AppState) {
|
||||
|
||||
Reference in New Issue
Block a user