Skip to content

Commit 1157eb7

Browse files
committed
refactor: login with user password
1 parent 048a8ca commit 1157eb7

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

crates/cashu/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//! CDK common types and traits
2-
//!
32
pub mod amount;
43
pub mod dhke;
54
#[cfg(feature = "mint")]

crates/cdk-cli/src/sub_commands/cat_login.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ pub async fn cat_login(
5252
let openid_discovery = mint_info
5353
.nuts
5454
.nutxx
55-
.expect("Nutxx definded")
55+
.expect("Nutxx defined")
5656
.openid_discovery;
5757

5858
let oidc_client = OidcClient::new(openid_discovery);
5959

6060
let access_token = oidc_client
61-
.get_access_token(
61+
.get_access_token_with_user_password(
6262
sub_command_args.username.clone(),
6363
sub_command_args.password.clone(),
6464
)

crates/cdk/src/oidc_client.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ pub enum Error {
3131
/// Unsupported Algo
3232
#[error("Unsupported signing algo")]
3333
UnsupportedSigningAlgo,
34+
/// Access token not returned
35+
#[error("Error getting access token")]
36+
AccessTokenMissing,
3437
}
3538

3639
impl From<Error> for cdk_common::error::Error {
@@ -183,7 +186,7 @@ impl OidcClient {
183186

184187
/// Get Access token (CAT)
185188
#[cfg(feature = "wallet")]
186-
pub async fn get_access_token(
189+
pub async fn get_access_token_with_user_password(
187190
&self,
188191
username: String,
189192
password: String,
@@ -206,7 +209,9 @@ impl OidcClient {
206209
.json()
207210
.await?;
208211

209-
let token = response.get("access_token").expect("access token");
212+
let token = response
213+
.get("access_token")
214+
.ok_or(Error::AccessTokenMissing)?;
210215

211216
Ok(token.to_string())
212217
}

crates/cdk/src/wallet/mint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ impl Wallet {
162162
/// use anyhow::Result;
163163
/// use cdk::amount::{Amount, SplitTarget};
164164
/// use cdk::cdk_database::WalletMemoryDatabase;
165-
/// use cdk::nuts::CurrencyUnit;
166165
/// use cdk::nuts::nut00::ProofsMethods;
166+
/// use cdk::nuts::CurrencyUnit;
167167
/// use cdk::wallet::Wallet;
168168
/// use rand::Rng;
169169
///

0 commit comments

Comments
 (0)