Skip to content

Commit

Permalink
examples(authz): update the readme to explain using Authenticator cli
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuhvi committed Nov 7, 2024
1 parent d1b2210 commit 8deda4e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
8 changes: 7 additions & 1 deletion examples/authz/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.
21 changes: 15 additions & 6 deletions examples/authz/authenticator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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...");
Expand Down

0 comments on commit 8deda4e

Please sign in to comment.