Authentication will be required for the following behaviors
Getting a sequencer co-signature on a built block.
Retrieving bundles from the bundle relay.
Authentication will be performed using a standard OAuth2 client credential grant and then the access token you receive can be used to authorize all requests to the sequencer and bundle relay.
[dependencies]
oauth2 = { version = "4" }
reqwest = { version = "0.11", features = ["json", "native-tls"] }
tokio = { version = "1", features = ["full", "macros", "rt-multi-thread"] }
use oauth2::basic::BasicClient;
use oauth2::{AuthUrl, ClientId, ClientSecret, TokenResponse, TokenUrl};
use oauth2::reqwest::async_http_client;
use reqwest::Client;
use std::env;
use tokio;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Retrieve client ID and secret from environment variables
let client_id = ClientId::new(
env::var("CLIENT_ID").expect("Missing CLIENT_ID environment variable"),
);
let client_secret = ClientSecret::new(
env::var("CLIENT_SECRET").expect("Missing CLIENT_SECRET environment variable"),
);
// OAuth2 provider URLs
let auth_url = AuthUrl::new("https://auth.holesky.signet.sh/authorize".to_string())?;
let token_url = TokenUrl::new("https://auth.holesky.signet.sh/oauth/token".to_string())?;
// Set up the OAuth2 client
let client = BasicClient::new(
client_id,
Some(client_secret),
auth_url,
Some(token_url),
);
// Perform the client credentials grant
let token = client
.exchange_client_credentials()
// Add the required `audience` param
.add_extra_param("audience", "https://transactions.pecorino.signet.sh")
.request(async_http_client)?;i
let access_token = token.access_token().secret();
// Use the access token to make an API call
let api_client = Client::new();
let response = api_client
.get("https://transactions.pecorino.signet.sh/get-bundles")
.bearer_auth(access_token)
.send()
.await?;
Ok(())
}