Beispiel #1
0
 def check_token(self):
     # If the identity hasn't been loaded, load it
     if not self.identity.has_refresh():
         self.identity = IdentityManager.load()
     # If refresh is needed perform a refresh
     if self.identity.refresh and self.identity.is_expired():
         self.identity = IdentityManager.load()
         # if no one else has updated the token refresh it
         if self.identity.is_expired():
             self.refresh_token()
 def check_token(self):
     # If the identity hasn't been loaded, load it
     if not self.identity.has_refresh():
         self.identity = IdentityManager.load()
     # If refresh is needed perform a refresh
     if self.identity.refresh and self.identity.is_expired():
         self.identity = IdentityManager.load()
         # if no one else has updated the token refresh it
         if self.identity.is_expired():
             self.refresh_token()
Beispiel #3
0
    def refresh_token(self):
        LOG.debug('Refreshing token')
        if identity_lock.acquire(blocking=False):
            try:
                data = self.send({
                    "path": "auth/token",
                    "headers": {
                        "Authorization": "Bearer " + self.identity.refresh,
                        "Device": self.identity.uuid
                    }
                })
                IdentityManager.save(data, lock=False)
                LOG.debug('Saved credentials')
            except HTTPError as e:
                if e.response.status_code == 401:
                    LOG.error('Could not refresh token, invalid refresh code.')
                else:
                    raise

            finally:
                identity_lock.release()
        else:  # Someone is updating the identity wait for release
            with identity_lock:
                LOG.debug('Refresh is already in progress, waiting until done')
                time.sleep(1.2)
                os.sync()
                self.identity = IdentityManager.load(lock=False)
                LOG.debug('new credentials loaded')
Beispiel #4
0
    def refresh_token(self):
        LOG.debug('Refreshing token')
        if identity_lock.acquire(blocking=False):
            try:
                data = self.send({
                    "path": "auth/token",
                    "headers": {
                        "Authorization": "Bearer " + self.identity.refresh
                    }
                })
                IdentityManager.save(data, lock=False)
                LOG.debug('Saved credentials')
            except HTTPError as e:
                if e.response.status_code == 401:
                    LOG.error('Could not refresh token, invalid refresh code.')
                else:
                    raise

            finally:
                identity_lock.release()
        else:  # Someone is updating the identity wait for release
            with identity_lock:
                LOG.debug('Refresh is already in progress, waiting until done')
                time.sleep(1.2)
                os.sync()
                self.identity = IdentityManager.load(lock=False)
                LOG.debug('new credentials loaded')
Beispiel #5
0
def has_been_paired():
    """ Determine if this device has ever been paired with a web backend

    Returns:
        bool: True if ever paired with backend (not factory reset)
    """
    # This forces a load from the identity file in case the pairing state
    # has recently changed
    id = IdentityManager.load()
    return id.uuid is not None and id.uuid != ""
def has_been_paired():
    """ Determine if this device has ever been paired with a web backend

    Returns:
        bool: True if ever paired with backend (not factory reset)
    """
    # This forces a load from the identity file in case the pairing state
    # has recently changed
    id = IdentityManager.load()
    return id.uuid is not None and id.uuid != ""
Beispiel #7
0
 def check_token(self):
     if self.identity.refresh and self.identity.is_expired():
         self.identity = IdentityManager.load()
         if self.identity.is_expired():
             data = self.send({
                 "path": "auth/token",
                 "headers": {
                     "Authorization": "Bearer " + self.identity.refresh
                 }
             })
             IdentityManager.save(data)
 def refresh_token(self):
     LOG.debug('Refreshing token')
     if identity_lock.acquire(blocking=False):
         try:
             data = self.send({
                 "path": "auth/token",
                 "headers": {
                     "Authorization": "Bearer " + self.identity.refresh
                 }
             })
             IdentityManager.save(data, lock=False)
             LOG.debug('Saved credentials')
         finally:
             identity_lock.release()
     else:  # Someone is updating the identity wait for release
         with identity_lock:
             LOG.debug('Refresh is already in progress, waiting until done')
             time.sleep(1.2)
             os.sync()
             self.identity = IdentityManager.load(lock=False)
             LOG.debug('new credentials loaded')
Beispiel #9
0
 def refresh_token(self):
     LOG.debug('Refreshing token')
     if identity_lock.acquire(blocking=False):
         try:
             data = self.send({
                 "path": "auth/token",
                 "headers": {
                     "Authorization": "Bearer " + self.identity.refresh
                 }
             })
             IdentityManager.save(data, lock=False)
             LOG.debug('Saved credentials')
         finally:
             identity_lock.release()
     else:  # Someone is updating the identity wait for release
         with identity_lock:
             LOG.debug('Refresh is already in progress, waiting until done')
             time.sleep(1.2)
             os.sync()
             self.identity = IdentityManager.load(lock=False)
             LOG.debug('new credentials loaded')
Beispiel #10
0
 def check_token(self):
     if self.identity.refresh and self.identity.is_expired():
         self.identity = IdentityManager.load()
         if self.identity.is_expired():
             self.refresh_token()
 def check_token(self):
     if self.identity.refresh and self.identity.is_expired():
         self.identity = IdentityManager.load()
         if self.identity.is_expired():
             self.refresh_token()