mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-31 02:27:13 +02:00
Remove local PIO Account session from PIO Remote when token is broken
This commit is contained in:
@ -13,7 +13,7 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
from twisted.cred import credentials # pylint: disable=import-error
|
from twisted.cred import credentials # pylint: disable=import-error
|
||||||
from twisted.internet import protocol, reactor # pylint: disable=import-error
|
from twisted.internet import defer, protocol, reactor # pylint: disable=import-error
|
||||||
from twisted.spread import pb # pylint: disable=import-error
|
from twisted.spread import pb # pylint: disable=import-error
|
||||||
|
|
||||||
from platformio.app import get_host_id
|
from platformio.app import get_host_id
|
||||||
@ -35,17 +35,27 @@ class RemoteClientFactory(pb.PBClientFactory, protocol.ReconnectingClientFactory
|
|||||||
self.remote_client.log.info("Successfully connected")
|
self.remote_client.log.info("Successfully connected")
|
||||||
self.remote_client.log.info("Authenticating")
|
self.remote_client.log.info("Authenticating")
|
||||||
|
|
||||||
|
auth_token = None
|
||||||
|
try:
|
||||||
|
auth_token = AccountClient().fetch_authentication_token()
|
||||||
|
except Exception as e: # pylint:disable=broad-except
|
||||||
|
d = defer.Deferred()
|
||||||
|
d.addErrback(self.clientAuthorizationFailed)
|
||||||
|
d.errback(pb.Error(e))
|
||||||
|
return d
|
||||||
|
|
||||||
d = self.login(
|
d = self.login(
|
||||||
credentials.UsernamePassword(
|
credentials.UsernamePassword(auth_token.encode(), get_host_id().encode(),),
|
||||||
AccountClient().fetch_authentication_token().encode(),
|
|
||||||
get_host_id().encode(),
|
|
||||||
),
|
|
||||||
client=self.remote_client,
|
client=self.remote_client,
|
||||||
)
|
)
|
||||||
d.addCallback(self.remote_client.cb_client_authorization_made)
|
d.addCallback(self.remote_client.cb_client_authorization_made)
|
||||||
d.addErrback(self.remote_client.cb_client_authorization_failed)
|
d.addErrback(self.clientAuthorizationFailed)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
def clientAuthorizationFailed(self, err):
|
||||||
|
AccountClient.delete_local_session()
|
||||||
|
self.remote_client.cb_client_authorization_failed(err)
|
||||||
|
|
||||||
def clientConnectionFailed(self, connector, reason):
|
def clientConnectionFailed(self, connector, reason):
|
||||||
self.remote_client.log.warn(
|
self.remote_client.log.warn(
|
||||||
"Could not connect to PIO Remote Cloud. Reconnecting..."
|
"Could not connect to PIO Remote Cloud. Reconnecting..."
|
||||||
|
Reference in New Issue
Block a user