examples(authz): update the readme to explain using Authenticator cli

This commit is contained in:
nazeh
2024-11-07 12:04:32 +03:00
parent d1b221083d
commit 8deda4e523
2 changed files with 22 additions and 7 deletions

View File

@@ -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 <RECOVERY_FILE> "<Auth_URL>" [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.

View File

@@ -17,6 +17,9 @@ struct Cli {
/// Pubky Auth url
url: Url,
// Whether or not to use testnet Dht network (local testing)
testnet: Option<bool>,
}
#[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...");