wip: first demo of authz

This commit is contained in:
nazeh
2024-09-03 11:31:36 +03:00
parent 634d309766
commit 5773b2d046
5 changed files with 11 additions and 11 deletions

View File

@@ -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);
}

View File

@@ -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(())
}

View File

@@ -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<PublicKey> {
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())
}
}

View File

@@ -109,7 +109,7 @@ impl PubkyClient {
&self,
auth_token: &[u8],
client_secret: js_sys::Uint8Array,
) -> Result<(), JsValue> {
) -> Result<PublicKey, JsValue> {
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())
}

View File

@@ -57,7 +57,7 @@ impl From<pkarr::Keypair> for Keypair {
}
#[wasm_bindgen]
pub struct PublicKey(pkarr::PublicKey);
pub struct PublicKey(pub(crate) pkarr::PublicKey);
#[wasm_bindgen]
impl PublicKey {