Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Token get expired even though the thread is started #21

Open
anton-pytel opened this issue Jul 30, 2021 · 0 comments · May be fixed by #22
Open

Token get expired even though the thread is started #21

anton-pytel opened this issue Jul 30, 2021 · 0 comments · May be fixed by #22

Comments

@anton-pytel
Copy link

anton-pytel commented Jul 30, 2021

The problem is that thread function

 def run(self):
        self.stopped = False
        while not self.stopped:
            try:
                check_time = time()
                if check_time >= self.token_info["refreshToken"] and self.logged_in:
                    if self.username and self.password:
                        self.login(self.username, self.password)
                    else:
                        logger.error("No username or password provided!")
                sleep(1)
            except Exception as e:
                logger.exception(e)
                break
            except KeyboardInterrupt:
                break

checks the self.token_info["refreshToken"], but self.token_info attribute is not updated in the login method:

    def login(self, username, password):
        """Authorization on the host and saving the toke information"""
        if self.username is None and self.password is None:
            self.username = username
            self.password = password
            self.logged_in = True

        token_json = post(self.base_url + "/api/auth/login", json={"username": username, "password": password}).json()
        token = None
        if isinstance(token_json, dict) and token_json.get("token") is not None:
            token = token_json["token"]
        self.configuration.api_key_prefix["X-Authorization"] = "Bearer"
        self.configuration.api_key["X-Authorization"] = token

        self.api_client = ApiClient(self.configuration)
        self.__load_controllers()

I presume that token_json variable here and following lines - was meant to be self.token_info and all would be working fine.

Update:

it will not work, it is also needed to parse the token expiration from the token.

@anton-pytel anton-pytel linked a pull request Jul 30, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant