mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-12 16:39:00 +08:00
Gracefully handle binding erorr for local OAUTH2 Server
CURA-7346 (cherry picked from commit 849e012756595e266be66d60c32beebbbe61beac)
This commit is contained in:
parent
4f55c8d832
commit
cf6ad0736a
@ -7,19 +7,17 @@ from typing import Optional, TYPE_CHECKING
|
|||||||
from urllib.parse import urlencode
|
from urllib.parse import urlencode
|
||||||
|
|
||||||
import requests.exceptions
|
import requests.exceptions
|
||||||
|
|
||||||
from PyQt5.QtCore import QUrl
|
from PyQt5.QtCore import QUrl
|
||||||
from PyQt5.QtGui import QDesktopServices
|
from PyQt5.QtGui import QDesktopServices
|
||||||
|
|
||||||
from UM.Logger import Logger
|
from UM.Logger import Logger
|
||||||
from UM.Message import Message
|
from UM.Message import Message
|
||||||
from UM.Signal import Signal
|
from UM.Signal import Signal
|
||||||
|
from UM.i18n import i18nCatalog
|
||||||
from cura.OAuth2.LocalAuthorizationServer import LocalAuthorizationServer
|
|
||||||
from cura.OAuth2.AuthorizationHelpers import AuthorizationHelpers, TOKEN_TIMESTAMP_FORMAT
|
from cura.OAuth2.AuthorizationHelpers import AuthorizationHelpers, TOKEN_TIMESTAMP_FORMAT
|
||||||
|
from cura.OAuth2.LocalAuthorizationServer import LocalAuthorizationServer
|
||||||
from cura.OAuth2.Models import AuthenticationResponse
|
from cura.OAuth2.Models import AuthenticationResponse
|
||||||
|
|
||||||
from UM.i18n import i18nCatalog
|
|
||||||
i18n_catalog = i18nCatalog("cura")
|
i18n_catalog = i18nCatalog("cura")
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
@ -166,11 +164,18 @@ class AuthorizationService:
|
|||||||
"code_challenge_method": "S512"
|
"code_challenge_method": "S512"
|
||||||
})
|
})
|
||||||
|
|
||||||
|
# Start a local web server to receive the callback URL on.
|
||||||
|
try:
|
||||||
|
self._server.start(verification_code, state)
|
||||||
|
except OSError:
|
||||||
|
Logger.logException("w", "Unable to create authorization request server")
|
||||||
|
Message(i18n_catalog.i18nc("@info", "Unable to start local OAUTH2 server. Check if another login atempt is still active."),
|
||||||
|
title=i18n_catalog.i18nc("@info:title", "Warning")).show()
|
||||||
|
return
|
||||||
|
|
||||||
# Open the authorization page in a new browser window.
|
# Open the authorization page in a new browser window.
|
||||||
QDesktopServices.openUrl(QUrl("{}?{}".format(self._auth_url, query_string)))
|
QDesktopServices.openUrl(QUrl("{}?{}".format(self._auth_url, query_string)))
|
||||||
|
|
||||||
# Start a local web server to receive the callback URL on.
|
|
||||||
self._server.start(verification_code, state)
|
|
||||||
|
|
||||||
## Callback method for the authentication flow.
|
## Callback method for the authentication flow.
|
||||||
def _onAuthStateChanged(self, auth_response: AuthenticationResponse) -> None:
|
def _onAuthStateChanged(self, auth_response: AuthenticationResponse) -> None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user