Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6d84ef9

Browse files
committed
fix(token-storage): implement deletion of tokens
Previously this case was entirely uncovered. Interesting note: when a token is revoked, existing auth-tokens will still work. However, you may not refresh them in case permissions have been revoked. It's good as there is only one code-path to deal with (and we verified it to be working), and bad for the user as malicious software can keep using an account for certain time until the token expires. Fixes #79
1 parent e523ddb commit 6d84ef9

1 file changed

Lines changed: 22 additions & 8 deletions

File tree

src/rust/cli/cmn.rs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,29 @@ impl TokenStorage for JsonTokenStorage {
173173

174174
// NOTE: logging might be interesting, currently we swallow all errors
175175
fn set(&mut self, scope_hash: u64, _: &Vec<&str>, token: Option<Token>) -> Option<io::Error> {
176-
let json_token = json::encode(&token).unwrap();
177-
match fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)) {
178-
Ok(mut f) => {
179-
match f.write(json_token.as_bytes()) {
180-
Ok(_) => None,
181-
Err(io_err) => Some(io_err),
176+
match token {
177+
None => {
178+
match fs::remove_file(self.path(scope_hash)) {
179+
Err(err) =>
180+
match err.kind() {
181+
io::ErrorKind::NotFound => None,
182+
_ => Some(err)
183+
},
184+
Ok(_) => None
182185
}
183-
},
184-
Err(io_err) => Some(io_err)
186+
}
187+
Some(token) => {
188+
let json_token = json::encode(&token).unwrap();
189+
match fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)) {
190+
Ok(mut f) => {
191+
match f.write(json_token.as_bytes()) {
192+
Ok(_) => None,
193+
Err(io_err) => Some(io_err),
194+
}
195+
},
196+
Err(io_err) => Some(io_err)
197+
}
198+
}
185199
}
186200
}
187201

0 commit comments

Comments
 (0)