diff --git a/Cargo.lock b/Cargo.lock index ba2b83a..47a1af5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -455,7 +455,7 @@ dependencies = [ [[package]] name = "discoursio-presence" -version = "0.2.14" +version = "0.2.15" dependencies = [ "actix-web", "futures", diff --git a/Cargo.toml b/Cargo.toml index b3a3e33..9cabc22 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "discoursio-presence" -version = "0.2.14" +version = "0.2.15" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/data.rs b/src/data.rs index 190fd3a..fc1fc66 100644 --- a/src/data.rs +++ b/src/data.rs @@ -1,4 +1,4 @@ -use reqwest::header::{HeaderMap, HeaderValue, AUTHORIZATION, CONTENT_TYPE}; +use reqwest::header::{HeaderMap, HeaderValue, CONTENT_TYPE}; use reqwest::Client as HTTPClient; use serde_json::json; use std::collections::HashMap; @@ -9,19 +9,22 @@ use crate::SSEMessageData; pub async fn get_auth_id(token: &str) -> Result> { let auth_api_base = env::var("AUTH_URL")?; - let (query_name, query_type) = match auth_api_base.contains("auth.discours.io") { - true => ("session", "query"), // authorizer - _ => ("getSession", "mutation"), // v2 - }; - let operation = "GetUserId"; let mut headers = HeaderMap::new(); - headers.insert(AUTHORIZATION, HeaderValue::from_str(token)?); headers.insert(CONTENT_TYPE, HeaderValue::from_static("application/json")); let gql = json!({ - "query": format!("{} {} {{ {} {{ user {{ id }} }} }}", query_type, operation, query_name), - "operationName": operation, - "variables": HashMap::::new() + "query": r#"query ValidateJWTToken($params: ValidateJWTTokenInput) { + validate_jwt_token(params: $params) { + is_valid + claims + } + }"#, + "variables": { + "params": { + "token_type": "access_token", + "token": token, + } + } }); let client = HTTPClient::new(); @@ -36,9 +39,9 @@ pub async fn get_auth_id(token: &str) -> Result> { let r: HashMap = response.json().await?; let user_id = r .get("data") - .and_then(|data| data.get(query_name)) - .and_then(|query| query.get("user")) - .and_then(|user| user.get("id")) + .and_then(|data| data.get("validate_jwt_token")) + .and_then(|query| query.get("clams")) + .and_then(|claims| claims.get("sub")) .and_then(|id| id.as_i64()); match user_id { @@ -117,7 +120,7 @@ pub async fn is_fitting( // TODO: check all community subscribers if no then // TODO: check all topics subscribers if no then // TODO: check all authors subscribers - + Ok(true) } else if message_data.entity == "chat" { // payload is Chat