Merge branch '7-access-token-expired' into 'master'
actually update the auth header Closes #7 See merge request !9
This commit is contained in:
commit
d624df24ef
13
src/gog.rs
13
src/gog.rs
@ -95,14 +95,15 @@ impl<'a> Gog<'a> {
|
|||||||
/// will get an url which you have to open in a browser. There you have to
|
/// 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.
|
/// login and copy the code parameter from the next page into the prompt.
|
||||||
pub fn login(&mut self) -> Result<(), GogError> {
|
pub fn login(&mut self) -> Result<(), GogError> {
|
||||||
let token = self.refresh_token_from_file()?;
|
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())?;
|
|
||||||
|
|
||||||
Ok(())
|
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> {
|
fn refresh_token_from_file(&mut self) -> Result<Token, GogError> {
|
||||||
let config = ConfigFiles::new();
|
let config = ConfigFiles::new();
|
||||||
let mut token: Token = match config.load("token.json") {
|
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())?;
|
token = self.refresh_token(token.refresh_token.as_str())?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.update_auth_header(&token)?;
|
||||||
|
|
||||||
config.save("token.json", &token)?;
|
config.save("token.json", &token)?;
|
||||||
|
|
||||||
Ok(token)
|
Ok(token)
|
||||||
|
Loading…
Reference in New Issue
Block a user