Calculate token expiration

        return expiration if the token need to set expiration or refresh,
        otherwise return None.

        Args:
            token (dict): a decoded token

def calculate_expiration(self, token):
        """
        Calculate token expiration

        return expiration if the token need to set expiration or refresh,
        otherwise return None.

        Args:
            token (dict): a decoded token
        """
        if not token:
            return None
        now = datetime.utcnow()
        time_to_live = self.config["expiration"]
        if "exp" not in token:
            return now + timedelta(seconds=time_to_live)
        elif self.config["refresh"]:
            exp = datetime.utcfromtimestamp(token["exp"])
            # 0.5: reduce refresh frequent
            if exp - now < timedelta(seconds=0.5 * time_to_live):
                return now + timedelta(seconds=time_to_live)
        return None