Skip to content

Commit

Permalink
Change Auth struct signature field to Vec<u8>
Browse files Browse the repository at this point in the history
  • Loading branch information
mnordstr authored Nov 4, 2024
1 parent 02bd0e9 commit 21ea5ca
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion async-nats/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub struct Auth {
pub jwt: Option<String>,
pub nkey: Option<String>,
pub(crate) signature_callback: Option<CallbackArg1<String, Result<String, AuthError>>>,
pub signature: Option<String>,
pub signature: Option<Vec<u8>>,
pub username: Option<String>,
pub password: Option<String>,
pub token: Option<String>,
Expand Down
22 changes: 22 additions & 0 deletions async-nats/tests/client_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,28 @@ mod client {
.unwrap();
}

#[tokio::test]
async fn custom_auth_callback_jwt() {
let server = nats_server::run_server("tests/configs/jwt.conf");

ConnectOptions::with_auth_callback(move |nonce| async move {
let mut auth = async_nats::Auth::new();
auth.jwt = Some("eyJ0eXAiOiJKV1QiLCJhbGciOiJlZDI1NTE5LW5rZXkifQ.".to_owned() +
"eyJqdGkiOiJMN1dBT1hJU0tPSUZNM1QyNEhMQ09ENzJRT1czQkNVWEdETjRKVU1SSUtHTlQ3RzdZVFRRIiwiaWF0IjoxNjUxNzkwOTgyLCJpc3MiOiJBRFRRUzdaQ0ZWSk5XNTcyNkdPWVhXNVRTQ1pGTklRU0hLMlpHWVVCQ0Q1RDc3T1ROTE9PS1pPWiIsIm5hbWUiOiJUZXN0V" +
"XNlciIsInN1YiI6IlVBRkhHNkZVRDJVVTRTREZWQUZVTDVMREZPMlhNNFdZTTc2VU5YVFBKWUpLN0VFTVlSQkhUMlZFIiwibmF0cyI6eyJwdWIiOnt9LCJzdWIiOnt9LCJzdWJzIjotMSwiZGF0YSI6LTEsInBheWxvYWQiOi0xLCJ0eXBlIjoidXNlciIsInZlcnNpb24iOjJ9fQ." +
"bp2-Jsy33l4ayF7Ku1MNdJby4WiMKUrG-rSVYGBusAtV3xP4EdCa-zhSNUaBVIL3uYPPCQYCEoM1pCUdOnoJBg");

let key_pair = nkeys::KeyPair::from_seed("SUACH75SWCM5D2JMJM6EKLR2WDARVGZT4QC6LX3AGHSWOMVAKERABBBRWM").unwrap();
let sign = key_pair.sign(&nonce).map_err(async_nats::AuthError::new)?;
auth.signature = Some(sign);

Ok(auth)
})
.connect(server.client_url())
.await
.unwrap();
}

#[tokio::test]
async fn max_reconnects() {
let (tx, mut rx) = tokio::sync::mpsc::unbounded_channel();
Expand Down

0 comments on commit 21ea5ca

Please sign in to comment.