Skip to content

Commit 92d1536

Browse files
committed
fix: rename tokens_verified, tokens_for_auth
1 parent a28fa02 commit 92d1536

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

adapter/src/dummy.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ use std::collections::HashMap;
88
pub struct DummyAdapter {
99
identity: String,
1010
config: Config,
11-
tokens_verified: HashMap<String, String>,
12-
tokens_for_auth: HashMap<String, String>,
11+
// Auth tokens that we have verified (tokenId => session)
12+
session_tokens: HashMap<String, String>,
13+
// Auth tokens that we've generated to authenticate with someone (address => token)
14+
authorization_tokens: HashMap<String, String>,
1315
}
1416

1517
// Enables DummyAdapter to be able to
@@ -20,10 +22,10 @@ impl Adapter for DummyAdapter {
2022
type Output = DummyAdapter;
2123

2224
fn init(opts: AdapterOptions, config: &Config) -> AdapterResult<DummyAdapter> {
23-
let (identity, tokens_for_auth, tokens_verified) =
25+
let (identity, authorization_tokens, session_tokens) =
2426
match (opts.dummy_identity, opts.dummy_auth, opts.dummy_auth_tokens) {
25-
(Some(identity), Some(tokens_for_auth), Some(tokens_verified)) => {
26-
(identity, tokens_for_auth, tokens_verified)
27+
(Some(identity), Some(authorization_tokens), Some(session_tokens)) => {
28+
(identity, authorization_tokens, session_tokens)
2729
}
2830
(_, _, _) => {
2931
return Err(AdapterError::Configuration(
@@ -35,8 +37,8 @@ impl Adapter for DummyAdapter {
3537
Ok(Self {
3638
identity,
3739
config: config.to_owned(),
38-
tokens_verified,
39-
tokens_for_auth,
40+
session_tokens,
41+
authorization_tokens,
4042
})
4143
}
4244

@@ -77,7 +79,7 @@ impl Adapter for DummyAdapter {
7779

7880
fn session_from_token(&self, token: &str) -> AdapterResult<Session> {
7981
let identity = self
80-
.tokens_for_auth
82+
.authorization_tokens
8183
.clone()
8284
.into_iter()
8385
.find(|(_, id)| *id == token);
@@ -93,14 +95,14 @@ impl Adapter for DummyAdapter {
9395

9496
fn get_auth(&self, _validator: &ValidatorDesc) -> AdapterResult<String> {
9597
let who = self
96-
.tokens_verified
98+
.session_tokens
9799
.clone()
98100
.into_iter()
99101
.find(|(_, id)| *id == self.identity);
100102

101103
match who {
102104
Some((id, _)) => {
103-
let auth = self.tokens_for_auth.get(&id).expect("id should exist");
105+
let auth = self.authorization_tokens.get(&id).expect("id should exist");
104106
Ok(auth.to_owned())
105107
}
106108
None => Err(AdapterError::Authentication(format!(

adapter/src/ethereum.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ pub struct EthereumAdapter {
3434
keystore_json: String,
3535
keystore_pwd: Password,
3636
config: Config,
37-
tokens_verified: RefCell<HashMap<String, Session>>,
38-
tokens_for_auth: RefCell<HashMap<String, String>>,
37+
// Auth tokens that we have verified (tokenId => session)
38+
session_tokens: RefCell<HashMap<String, Session>>,
39+
// Auth tokens that we've generated to authenticate with someone (address => token)
40+
authorization_tokens: RefCell<HashMap<String, String>>,
3941
wallet: RefCell<Option<SafeAccount>>,
4042
}
4143

@@ -59,8 +61,8 @@ impl Adapter for EthereumAdapter {
5961
Ok(Self {
6062
keystore_json,
6163
keystore_pwd: keystore_pwd.into(),
62-
tokens_verified: RefCell::new(HashMap::new()),
63-
tokens_for_auth: RefCell::new(HashMap::new()),
64+
session_tokens: RefCell::new(HashMap::new()),
65+
authorization_tokens: RefCell::new(HashMap::new()),
6466
wallet: RefCell::new(None),
6567
config: config.to_owned(),
6668
})
@@ -194,7 +196,7 @@ impl Adapter for EthereumAdapter {
194196

195197
fn session_from_token(&self, token: &str) -> AdapterResult<Session> {
196198
let token_id = token.to_owned()[..16].to_string();
197-
let result = self.tokens_verified.borrow_mut();
199+
let result = self.session_tokens.borrow_mut();
198200
if result.get(&token_id).is_some() {
199201
return Ok(result.get(&token_id).unwrap().to_owned());
200202
}
@@ -246,17 +248,17 @@ impl Adapter for EthereumAdapter {
246248
},
247249
};
248250

249-
self.tokens_verified
251+
self.session_tokens
250252
.borrow_mut()
251253
.insert(token_id, sess.clone());
252254
Ok(sess)
253255
}
254256

255257
fn get_auth(&self, validator: &ValidatorDesc) -> AdapterResult<String> {
256-
let tokens_for_auth = self.tokens_for_auth.borrow();
258+
let authorization_tokens = self.authorization_tokens.borrow();
257259
match (
258260
self.wallet.borrow().clone(),
259-
tokens_for_auth.get(&validator.id),
261+
authorization_tokens.get(&validator.id),
260262
) {
261263
(Some(_), Some(token)) => Ok(token.to_owned()),
262264
(Some(wallet), None) => {
@@ -269,7 +271,7 @@ impl Adapter for EthereumAdapter {
269271
let token = ewt_sign(&wallet, &self.keystore_pwd, &payload)
270272
.map_err(|_| map_error("Failed to sign token"))?;
271273

272-
self.tokens_for_auth
274+
self.authorization_tokens
273275
.borrow_mut()
274276
.insert(validator.id.clone(), token.clone());
275277

0 commit comments

Comments
 (0)