Skip to content

Commit

Permalink
Support new auth_dialog appkey workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
fieldOfView committed Mar 18, 2022
1 parent 7aea357 commit d5c800d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
25 changes: 25 additions & 0 deletions DiscoverOctoPrintAction.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,11 +553,36 @@ def _onRequestFinished(self, reply: QNetworkReply) -> None:
self._onRequestFailed(reply)
return

json_data = None

if reply.operation() == QNetworkAccessManager.PostOperation:
if (
"/plugin/appkeys/request" in reply.url().toString()
): # Initial AppKey request
if http_status_code == 201 or http_status_code == 202:
try:
json_data = json.loads(bytes(reply.readAll()).decode("utf-8"))
except json.decoder.JSONDecodeError:
Logger.log(
"w", "Received invalid JSON from octoprint instance."
)

if json_data:
app_token = json_data["app_token"] # unused; app_token is included in location header
auth_dialog_url = json_data["auth_dialog"]
else:
(
instance,
base_url,
basic_auth_username,
basic_auth_password,
) = self._getInstanceInfo(self._appkey_instance_id)

auth_dialog_url = base_url

if auth_dialog_url:
self.openWebPage(auth_dialog_url)

Logger.log("w", "Start polling for AppKeys decision")
if not self._appkey_request:
return
Expand Down
1 change: 0 additions & 1 deletion qml/DiscoverOctoPrintAction.qml
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,6 @@ Cura.MachineAction
onClicked:
{
manager.requestApiKey(base.selectedInstance.getId());
manager.openWebPage(base.selectedInstance.baseURL);
}
}

Expand Down

0 comments on commit d5c800d

Please sign in to comment.