From 8deda4e523ae3f1a52b19e6e333b6034da8923a6 Mon Sep 17 00:00:00 2001 From: nazeh Date: Thu, 7 Nov 2024 12:04:32 +0300 Subject: [PATCH] examples(authz): update the readme to explain using Authenticator cli --- examples/authz/README.md | 8 +++++++- examples/authz/authenticator.rs | 21 +++++++++++++++------ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/examples/authz/README.md b/examples/authz/README.md index 905bda6..86adf64 100644 --- a/examples/authz/README.md +++ b/examples/authz/README.md @@ -5,7 +5,7 @@ This example shows 3rd party authorization in Pubky. It consists of 2 parts: 1. [3rd party app](./3rd-party-app): A web component showing the how to implement a Pubky Auth widget. -2. [Authenticator CLI](./authenticator): A CLI showing the authenticator (key chain) asking user for consent and generating the AuthToken. +2. [Authenticator CLI](./authenticator.rs): A CLI showing the authenticator (key chain) asking user for consent and generating the AuthToken. ## Usage @@ -26,4 +26,10 @@ Copy the Pubky Auth URL from the frontend. Finally run the CLI to paste the Pubky Auth in. +```bash +cargo run --bin authenticator "" [Testnet] +``` + +Where the auth url should be within qutoatino marks, and the Testnet is an option you can set to true to use the local homeserver + You should see the frontend reacting by showing the success of authorization and session details. diff --git a/examples/authz/authenticator.rs b/examples/authz/authenticator.rs index 410b8f5..97999c0 100644 --- a/examples/authz/authenticator.rs +++ b/examples/authz/authenticator.rs @@ -17,6 +17,9 @@ struct Cli { /// Pubky Auth url url: Url, + + // Whether or not to use testnet Dht network (local testing) + testnet: Option, } #[tokio::main] @@ -62,14 +65,20 @@ async fn main() -> Result<()> { println!("Successfully decrypted recovery file..."); println!("PublicKey: {}", keypair.public_key()); - let client = PubkyClient::testnet(); + let client = if cli.testnet.unwrap_or_default() { + let client = PubkyClient::testnet(); + + // For the purposes of this demo, we need to make sure + // the user has an account on the local homeserver. + if client.signin(&keypair).await.is_err() { + client + .signup(&keypair, &PublicKey::try_from(HOMESERVER).unwrap()) + .await?; + }; - // For the purposes of this demo, we need to make sure - // the user has an account on the local homeserver. - if client.signin(&keypair).await.is_err() { client - .signup(&keypair, &PublicKey::try_from(HOMESERVER).unwrap()) - .await?; + } else { + PubkyClient::builder().build() }; println!("Sending AuthToken to the 3rd party app...");