feat: allow passing auth token for chat
This commit is contained in:
parent
52ed43745d
commit
c6f9d34490
3 changed files with 19 additions and 9 deletions
|
@ -37,7 +37,7 @@ impl History {
|
|||
|
||||
|
||||
pub async fn run<T: ratatui::backend::Backend>(term: &mut Terminal<T>, args: crate::Args) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let mut chat = Chat::register(&args.server).await?;
|
||||
let mut chat = Chat::register(&args.server, args.token).await?;
|
||||
|
||||
let mut stream = crossterm::event::EventStream::new();
|
||||
let mut input = String::new();
|
||||
|
|
22
src/chat.rs
22
src/chat.rs
|
@ -55,15 +55,21 @@ pub struct Chat {
|
|||
}
|
||||
|
||||
impl Chat {
|
||||
pub async fn register(server: &str) -> Result<Chat, ChatError> {
|
||||
let registration : RegisterResponse = reqwest::Client::new()
|
||||
.post(format!("https://{server}/api/chat/register"))
|
||||
.send()
|
||||
.await?
|
||||
.json()
|
||||
.await?;
|
||||
pub async fn register(server: &str, token: Option<String>) -> Result<Chat, ChatError> {
|
||||
let token = match token {
|
||||
Some(t) => t,
|
||||
None => {
|
||||
let registration : RegisterResponse = reqwest::Client::new()
|
||||
.post(format!("https://{server}/api/chat/register"))
|
||||
.send()
|
||||
.await?
|
||||
.json()
|
||||
.await?;
|
||||
registration.access_token
|
||||
},
|
||||
};
|
||||
|
||||
let ws_url = format!("wss://{server}/ws?accessToken={}", registration.access_token);
|
||||
let ws_url = format!("wss://{server}/ws?accessToken={token}");
|
||||
|
||||
let (ws, _response) = tokio_tungstenite::connect_async(ws_url).await?;
|
||||
|
||||
|
|
|
@ -9,6 +9,10 @@ mod proto;
|
|||
struct Args {
|
||||
/// owncast server to connect to
|
||||
server: String,
|
||||
|
||||
/// access token to use for login
|
||||
#[arg(long)]
|
||||
token: Option<String>,
|
||||
}
|
||||
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
|
|
Loading…
Reference in a new issue