actually update the auth header

This commit is contained in:
Sebastian Hugentobler 2017-05-05 16:22:59 +02:00
parent e484084e4c
commit 2d83acbfe8

View File

@ -95,14 +95,15 @@ impl<'a> Gog<'a> {
/// will get an url which you have to open in a browser. There you have to
/// login and copy the code parameter from the next page into the prompt.
pub fn login(&mut self) -> Result<(), GogError> {
let token = self.refresh_token_from_file()?;
let auth_header = format!("Authorization: Bearer {token}", token = token.access_token);
self.http_client.add_header(auth_header.as_str())?;
self.refresh_token_from_file()?;
Ok(())
}
fn update_auth_header(&mut self, token: &Token) -> Result<(), GogError> {
let auth_header = format!("Authorization: Bearer {token}", token = token.access_token);
Ok(self.http_client.add_header(auth_header.as_str())?)
}
fn refresh_token_from_file(&mut self) -> Result<Token, GogError> {
let config = ConfigFiles::new();
let mut token: Token = match config.load("token.json") {
@ -117,6 +118,8 @@ impl<'a> Gog<'a> {
token = self.refresh_token(token.refresh_token.as_str())?;
}
self.update_auth_header(&token)?;
config.save("token.json", &token)?;
Ok(token)