Skip to content

Commit 5feb1fe

Browse files
Merge pull request #409 from Esri/guil8553/6089-challenge-error
Guil8553/6089 challenge error
2 parents 593a857 + 930ec8b commit 5feb1fe

File tree

4 files changed

+97
-40
lines changed

4 files changed

+97
-40
lines changed

uitools/cpp/Esri/ArcGISRuntime/Toolkit/AuthenticationController.cpp

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace Toolkit
3333
AuthenticationView.
3434
3535
This controller is a thin wrapper around the AuthenticationManager. As
36-
AuthenticationManager challenges are queued, the controller holds onto a
36+
AuthenticationManager challenges are queued, the controller holds onto a
3737
"current" challenge, which is the challenge the user is presented with, which
3838
will be discarded once the user chooses an action to perform on the challenge.
3939
*/
@@ -55,7 +55,7 @@ AuthenticationController::AuthenticationController(QObject* parent) :
5555
return;
5656

5757
// Auth manager normally only emits a challenge after previous one has
58-
// been processed. But if it starts hammering us here we will clean up the
58+
// been processed. But if it starts hammering us here we will clean up the
5959
// unprocessed challenges.
6060
if (m_currentChallenge)
6161
{
@@ -115,7 +115,7 @@ QUrl AuthenticationController::currentChallengeUrl() const
115115
}
116116

117117
/*!
118-
\brief Returns the authorization hostname of the current
118+
\brief Returns the authorization hostname of the current
119119
AuthenticationChallenge.
120120
*/
121121
QString AuthenticationController::currentAuthenticatingHost() const
@@ -134,16 +134,16 @@ QString AuthenticationController::currentAuthenticatingHost() const
134134
\li \c Unknown
135135
\li \c 0
136136
\row
137-
\li \c UsernamePassword
137+
\li \c UsernamePassword
138138
\li \c 1
139139
\row
140-
\li \c OAuth
140+
\li \c OAuth
141141
\li \c 2
142142
\row
143-
\li \c ClientCertificate
143+
\li \c ClientCertificate
144144
\li \c 3
145145
\row
146-
\li \c SslHandshake
146+
\li \c SslHandshake
147147
\li \c 4
148148
\endtable
149149
@@ -191,7 +191,7 @@ void AuthenticationController::setDeleteChallengeOnProcessed(bool deleteFlag)
191191
192192
Defaults to \c true.
193193
194-
\sa setDeleteChallengeOnProcessed
194+
\sa setDeleteChallengeOnProcessed
195195
*/
196196
bool AuthenticationController::deleteChallengeOnProcessed() const
197197
{
@@ -200,7 +200,7 @@ bool AuthenticationController::deleteChallengeOnProcessed() const
200200

201201
/*!
202202
\brief Calls \c continueWithUsernamePassword on the current challenge.
203-
203+
204204
\list
205205
\li \a username Username string.
206206
\li \a password Password string.
@@ -218,7 +218,7 @@ void AuthenticationController::continueWithUsernamePassword(const QString& usern
218218

219219
/*!
220220
\brief Calls \c continueWithOAuthAuthorizationCode on the current challenge.
221-
221+
222222
\list
223223
\li \a oAuthAuthorizationCode Authorization code.
224224
\endlist
@@ -235,7 +235,7 @@ void AuthenticationController::continueWithOAuthAuthorizationCode(const QString&
235235

236236
/*!
237237
\brief Calls \c continueWithClientCertificate on the current challenge.
238-
238+
239239
\list
240240
\li \a clientCertificateIndex The index is the index of the certificate
241241
as seen in \l clientCertificateInfos.
@@ -253,7 +253,7 @@ void AuthenticationController::continueWithClientCertificate(int clientCertifica
253253

254254
/*!
255255
\brief Calls \c continueWithSslHandshake on the current challenge.
256-
256+
257257
\list
258258
\li \a trust When true, trusts the misconfigured resource.
259259
\li \a remember Remember the user's preferences this session.
@@ -282,6 +282,20 @@ void AuthenticationController::cancel()
282282
c->cancel();
283283
}
284284

285+
/*!
286+
\brief Calls \c cancelWithError on the current challenge, with the \a title
287+
and the \a html content from the web view.
288+
*/
289+
void AuthenticationController::cancelWithError(const QString& title, const QString& html)
290+
{
291+
if (!m_currentChallenge)
292+
return;
293+
294+
auto c = m_currentChallenge;
295+
cleanup();
296+
c->cancelWithError(title, html);
297+
}
298+
285299
/*!
286300
\internal
287301
\brief Clears the reference to the current challenge. Also deletes the current
@@ -292,7 +306,7 @@ void AuthenticationController::cleanup()
292306
// This controller has the option of
293307
// "owning" the challenge and may delete
294308
// it after use.
295-
if (m_deleteChallengeOnProcessed)
309+
if (m_deleteChallengeOnProcessed)
296310
m_currentChallenge->deleteLater();
297311

298312
m_currentChallenge = nullptr;
@@ -338,7 +352,7 @@ void AuthenticationController::cleanup()
338352

339353
/*!
340354
\property Esri::ArcGISRuntime::Toolkit::AuthenticationController::clientCertificateInfos
341-
\brief List of strings representing the certificates held by the AuthenticationManager.
355+
\brief List of strings representing the certificates held by the AuthenticationManager.
342356
*/
343357

344358
} // Toolkit

uitools/cpp/Esri/ArcGISRuntime/Toolkit/AuthenticationController.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ class AuthenticationController : public QObject
7777

7878
Q_INVOKABLE void cancel();
7979

80+
Q_INVOKABLE void cancelWithError(const QString& title, const QString& html);
81+
8082
signals:
8183
void currentChallengeChanged();
8284

uitools/import/Esri/ArcGISRuntime/Toolkit/Controller/AuthenticationController.qml

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ import Esri.ArcGISRuntime 100.8
2323
\since Esri.ArcGISRutime 100.10
2424
\ingroup ArcGISQtToolkitUiQmlControllers
2525
\brief In MVC architecture, this is the controller for the corresponding
26-
AuthenticationView.
27-
26+
AuthenticationView.
27+
2828
This controller is a thin wrapper around the AuthenticationManager. As
29-
AuthenticationManager challenges are queued, the controller holds onto a
29+
AuthenticationManager challenges are queued, the controller holds onto a
3030
"current" challenge, which is the challenge the user is presented with, which
3131
will be discarded once the user chooses an action to perform on the challenge.
3232
*/
@@ -39,14 +39,14 @@ QtObject {
3939
\brief The authorization url of the current AuthenticationChallenge.
4040
*/
4141
property url currentChallengeUrl: internal.currentChallenge ? internal.currentChallenge.authorizationUrl : "";
42-
42+
4343
/*!
4444
\qmlproperty string currentAuthenticatingHost
4545
\brief Returns the authorization hostname of the current
4646
AuthenticationChallenge.
4747
*/
4848
property string currentAuthenticatingHost: internal.currentChallenge ? internal.currentChallenge.authenticatingHost.toString() : "";
49-
49+
5050
/*!
5151
\qmlproperty int currentChallengeType
5252
\brief The type of the current challenge as an int.
@@ -59,27 +59,27 @@ QtObject {
5959
\li \c Unknown
6060
\li \c 0
6161
\row
62-
\li \c UsernamePassword
62+
\li \c UsernamePassword
6363
\li \c 1
6464
\row
65-
\li \c OAuth
65+
\li \c OAuth
6666
\li \c 2
6767
\row
68-
\li \c ClientCertificate
68+
\li \c ClientCertificate
6969
\li \c 3
7070
\row
71-
\li \c SslHandshake
71+
\li \c SslHandshake
7272
\li \c 4
7373
\endtable
7474
*/
7575
property int currentChallengeType: internal.currentChallenge ? internal.currentChallenge.authenticationChallengeType : Enums.AuthenticationChallengeTypeUnknown;
76-
76+
7777
/*!
7878
\qmlproperty int currentChallengeFailureCount
7979
\brief The failure count of the current AuthenticationChallenge.
8080
*/
8181
property int currentChallengeFailureCount: internal.currentChallenge ? internal.currentChallenge.failureCount : 0;
82-
82+
8383
/*!
8484
\qmlproperty list<string> clientCertificateInfos
8585
\brief The list of ClientCertificateInfo strings currently held by the
@@ -103,52 +103,59 @@ QtObject {
103103
function addClientCertificate(...args) {
104104
return AuthenticationManager.addClientCertificate(...args);
105105
}
106-
106+
107107
function continueWithUsernamePassword(...args) {
108108
if (internal.currentChallenge) {
109109
internal.currentChallenge.continueWithUsernamePassword(...args);
110110
internal.currentChallenge = null;
111111
}
112112
}
113-
113+
114114
function continueWithOAuthAuthorizationCode(...args) {
115115
if (internal.currentChallenge) {
116116
internal.currentChallenge.continueWithOAuthAuthorizationCode(...args);
117117
internal.currentChallenge = null;
118118
}
119119
}
120-
120+
121121
function continueWithClientCertificate(...args) {
122122
if (internal.currentChallenge) {
123123
internal.currentChallenge.continueWithClientCertificate(...args);
124124
internal.currentChallenge = null;
125125
}
126126
}
127-
127+
128128
function continueWithSslHandshake(...args) {
129129
if (internal.currentChallenge) {
130130
internal.currentChallenge.continueWithSslHandshake(...args);
131131
internal.currentChallenge = null;
132132
}
133133
}
134-
134+
135135
function cancel(...args) {
136136
if (internal.currentChallenge) {
137137
internal.currentChallenge.cancel(...args);
138138
internal.currentChallenge = null;
139139
}
140140
}
141-
141+
142+
function cancelWithError(...args) {
143+
if (internal.currentChallenge) {
144+
internal.currentChallenge.cancelWithError(...args);
145+
internal.currentChallenge = null;
146+
}
147+
}
148+
142149
property QtObject internal: QtObject {
143150
property AuthenticationChallenge currentChallenge: null;
144-
151+
145152
property Connections managerConnection: Connections {
146153
target: AuthenticationManager
147154
ignoreUnknownSignals: false
148155
function onAuthenticationChallenge(challenge) {
149156
if (internal.challenge)
150157
internal.challenge.cancel();
151-
158+
152159
internal.currentChallenge = challenge;
153160
}
154161
function onClientCertificatePasswordRequired(certificate) {

uitools/import/Esri/ArcGISRuntime/Toolkit/OAuth2View.qml

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Dialog {
3434
text: `<h2>${webView.title}</h2>`
3535
horizontalAlignment: Text.AlignHCenter
3636
}
37-
37+
3838
footer: DialogButtonBox {
3939
standardButtons: +DialogButtonBox.Close
4040
onRejected: controller.cancel();
@@ -49,23 +49,57 @@ Dialog {
4949
centerIn: parent
5050
fill: parent
5151
}
52-
52+
5353
url: controller.currentChallengeUrl
5454

5555
onLoadingChanged: {
5656
if (loadRequest.status === WebView.LoadSucceededStatus) {
5757
forceActiveFocus();
58+
} else if (loadRequest.status === WebView.LoadFailedStatus) {
59+
controller.cancelWithError("Failed to load");
5860
}
5961
}
6062

6163
onTitleChanged: {
62-
if (title.indexOf("SUCCESS code=") > -1) {
63-
var authCode = title.replace("SUCCESS code=", "");
64+
// If the title contains "SUCCESS", get the authorization code from the title and continue authenticationChallenge.
65+
if (isSuccess()) {
66+
const authCode = title.replace("SUCCESS code=", "");
6467
controller.continueWithOAuthAuthorizationCode(authCode);
65-
} else if (title.indexOf("Denied error=") > -1) {
66-
controller.cancel();
68+
return;
69+
} else if (isInvalidRequest()) {
70+
// If the title contains "Denied error=invalid_request", get the HTML content.
71+
readHtmlContent();
72+
return;
73+
}
74+
75+
// If there is an error, cancel with error.
76+
if (isError()) {
77+
controller.cancelWithError(title, html);
6778
}
6879
}
80+
81+
// Property to get HTML content when necessary.
82+
property string html: ""
83+
onHtmlChanged: {
84+
controller.cancelWithError(title, html);
85+
}
86+
87+
// Helper functions
88+
function isSuccess() {
89+
return title.indexOf("SUCCESS code=") > -1;
90+
}
91+
92+
function isInvalidRequest() {
93+
return (title.indexOf("Denied error=invalid_request") > -1);
94+
}
95+
96+
function isError() {
97+
return (title.indexOf("Denied error=") > -1) || (title.indexOf("Error: ") > -1);
98+
}
99+
100+
function readHtmlContent() {
101+
const js = "document.documentElement.outerHTML";
102+
webview.runJavaScript(js, function(result) { html = result; });
103+
}
69104
}
70105
}
71-

0 commit comments

Comments
 (0)