Skip to content

Commit 5046666

Browse files
committed
auth token for node
1 parent e7bcb55 commit 5046666

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

.env

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
IOTA_NODE_ENDPOINT=
2+
IOTA_NODE_AUTH_TOKEN=
23
IOTA_SMR_NODE_ENDPOINT=
4+
IOTA_SMR_NODE_AUTH_TOKEN=
35
IOTA_CUSTOM_NETWORK_NAME=rms
46
IOTA_CUSTOM_NODE_ENDPOINT=https://api.testnet.shimmer.network
7+
IOTA_CUSTOM_NODE_AUTH_TOKEN=

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,19 @@ cargo run --release
7777
## Driver Environment Variables
7878

7979
`IOTA_NODE_ENDPOINT` Endpoint for the `iota` network.
80+
8081
`IOTA_SMR_NODE_ENDPOINT` Endpoint for the `smr` network.
82+
8183
`IOTA_CUSTOM_NETWORK_NAME` HRP a of custom network.
84+
8285
`IOTA_CUSTOM_NODE_ENDPOINT` Endpoint for the custom network.
8386

87+
`IOTA_NODE_AUTH_TOKEN` JWT auth token for `iota`'s node.
88+
89+
`IOTA_SMR_NODE_AUTH_TOKEN` JWT auth token for `smr`'s node.
90+
91+
`IOTA_CUSTOM_NODE_AUTH_TOKEN` JWT auth token for custom network's node.
92+
8493
Note: at least one network must be configured.
8594

8695
## Contributing

src/lib.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use identity_iota::{
1313
iota::{IotaDID, IotaDocument, IotaDocumentMetadata},
1414
resolver::{ErrorCause, Resolver},
1515
};
16-
use iota_sdk::client::Client;
16+
use iota_sdk::client::{node_manager::node::NodeAuth, Client};
1717
use serde::{Deserialize, Serialize};
1818
use std::{env, sync::Arc};
1919
use tokio::net::TcpListener;
@@ -106,7 +106,7 @@ async fn resolver() -> anyhow::Result<SharedResolver> {
106106

107107
if let Ok(iota_endpoint) = env::var(IOTA_NODE_ENDPOINT) {
108108
let client: Client = Client::builder()
109-
.with_primary_node(&iota_endpoint, None)
109+
.with_primary_node(&iota_endpoint, auth_token("IOTA_NODE"))
110110
.context("unable to create a client for the provided endpoint")?
111111
.finish()
112112
.await
@@ -117,7 +117,7 @@ async fn resolver() -> anyhow::Result<SharedResolver> {
117117

118118
if let Ok(iota_endpoint) = env::var(SMR_NODE_ENDPOINT) {
119119
let client: Client = Client::builder()
120-
.with_primary_node(&iota_endpoint, None)
120+
.with_primary_node(&iota_endpoint, auth_token("IOTA_SMR_NODE"))
121121
.context("unable to create a client for the provided endpoint")?
122122
.finish()
123123
.await
@@ -130,7 +130,7 @@ async fn resolver() -> anyhow::Result<SharedResolver> {
130130
let custom_endpoint = env::var(IOTA_CUSTOM_NODE_ENDPOINT).ok();
131131
if let (Some(custom_hrp), Some(custom_endpoint)) = (custom_hrp, custom_endpoint) {
132132
let client: Client = Client::builder()
133-
.with_primary_node(&custom_endpoint, None)
133+
.with_primary_node(&custom_endpoint, auth_token("IOTA_CUSTOM_NODE"))
134134
.expect("unable to create a client for the provided endpoint")
135135
.finish()
136136
.await
@@ -151,3 +151,11 @@ async fn resolver() -> anyhow::Result<SharedResolver> {
151151

152152
Ok(Arc::new(resolver))
153153
}
154+
155+
fn auth_token(node_name: &str) -> Option<NodeAuth> {
156+
let var_name = format!("{node_name}_AUTH_TOKEN");
157+
std::env::var(var_name).ok().map(|auth| NodeAuth {
158+
jwt: Some(auth),
159+
basic_auth_name_pwd: None,
160+
})
161+
}

0 commit comments

Comments
 (0)