diff --git a/examples/authz/3rd-party-app/src/pubky-auth-widget.js b/examples/authz/3rd-party-app/src/pubky-auth-widget.js index 9c4ae33..82e4689 100644 --- a/examples/authz/3rd-party-app/src/pubky-auth-widget.js +++ b/examples/authz/3rd-party-app/src/pubky-auth-widget.js @@ -133,11 +133,11 @@ export class PubkyAuthWidget extends LitElement { // Create a Uint8Array from the ArrayBuffer const authToken = new Uint8Array(arrayBuffer); - this.pubkyClient.thirdPartySignin(authToken, this.secret) + let publicKey = await this.pubkyClient.thirdPartySignin(authToken, this.secret) - let session = await this.pubkyClient.session(); + let session = await this.pubkyClient.session(publicKey); - console.log({ session }) + alert(`Succssfully signed in as ${publicKey.z32()}`) } catch (error) { console.error('PubkyAuthWidget: Failed to read incoming AuthToken', error); } diff --git a/examples/authz/authenticator/src/main.rs b/examples/authz/authenticator/src/main.rs index cb99e9b..44e1a52 100644 --- a/examples/authz/authenticator/src/main.rs +++ b/examples/authz/authenticator/src/main.rs @@ -72,6 +72,7 @@ async fn main() -> Result<()> { let keypair = pubky_common::recovery_file::decrypt_recovery_file(&recovery_file, &passphrase)?; println!("Successfully decrypted recovery file..."); + println!("PublicKey: {}", keypair.public_key()); let client = PubkyClient::testnet(); @@ -83,11 +84,11 @@ async fn main() -> Result<()> { .await?; }; + println!("Sending AuthToken to the 3rd party app..."); + client .authorize(&keypair, required_capabilities, client_secret, &relay) .await?; - println!("Sending AuthToken to the client..."); - Ok(()) } diff --git a/pubky/src/shared/auth.rs b/pubky/src/shared/auth.rs index 0761126..368efde 100644 --- a/pubky/src/shared/auth.rs +++ b/pubky/src/shared/auth.rs @@ -136,8 +136,6 @@ impl PubkyClient { drop(path_segments); - dbg!(callback.to_string()); - self.request(Method::POST, callback) .body(encrypted_token) .send() @@ -150,7 +148,7 @@ impl PubkyClient { &self, encrypted_token: &[u8], client_secret: &[u8; 32], - ) -> Result<()> { + ) -> Result { let decrypted = decrypt(encrypted_token, client_secret)?; let token = AuthToken::deserialize(&decrypted)?; @@ -168,7 +166,7 @@ impl PubkyClient { self.store_session(response); - Ok(()) + Ok(pubky.to_owned()) } } diff --git a/pubky/src/wasm.rs b/pubky/src/wasm.rs index 304caed..d994d37 100644 --- a/pubky/src/wasm.rs +++ b/pubky/src/wasm.rs @@ -109,7 +109,7 @@ impl PubkyClient { &self, auth_token: &[u8], client_secret: js_sys::Uint8Array, - ) -> Result<(), JsValue> { + ) -> Result { if !js_sys::Uint8Array::instanceof(&client_secret) { return Err("Expected client_secret to be an instance of Uint8Array".into()); } @@ -124,6 +124,7 @@ impl PubkyClient { self.inner_third_party_signin(auth_token, &client_secret_bytes) .await + .map(|p| PublicKey(p)) .map_err(|e| e.into()) } diff --git a/pubky/src/wasm/keys.rs b/pubky/src/wasm/keys.rs index c3454ac..c3005e9 100644 --- a/pubky/src/wasm/keys.rs +++ b/pubky/src/wasm/keys.rs @@ -57,7 +57,7 @@ impl From for Keypair { } #[wasm_bindgen] -pub struct PublicKey(pkarr::PublicKey); +pub struct PublicKey(pub(crate) pkarr::PublicKey); #[wasm_bindgen] impl PublicKey {