Skip to content

Commit 583e8bd

Browse files
NFC-82 Add error view and style for auth errors
Signed-off-by: Sander Kondratjev <[email protected]>
1 parent cbe57f7 commit 583e8bd

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

example/src/main/java/eu/webeid/example/web/rest/SigningController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public ResponseEntity<MobileInitRequest> mobileInit(WebEidAuthentication authent
7878

7979
@GetMapping("mobile/certificate")
8080
public ModelAndView mobileCertificateResponse() {
81-
return new ModelAndView("mobile-callback");
81+
return new ModelAndView("webeid-callback");
8282
}
8383

8484
@SuppressWarnings("javax.annotation.Tainted")
@@ -89,7 +89,7 @@ public ResponseEntity<MobileInitRequest> mobileCertificate(@RequestBody Certific
8989

9090
@GetMapping("mobile/signature")
9191
public ModelAndView mobileSignatureResponse() {
92-
return new ModelAndView("mobile-callback");
92+
return new ModelAndView("webeid-callback");
9393
}
9494

9595
@PostMapping("mobile/signature")

example/src/main/resources/templates/mobile-callback.html renamed to example/src/main/resources/templates/webeid-callback.html

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,26 @@
77
<meta id="csrftoken" name="csrftoken" th:content="${_csrf.token}"/>
88
<meta id="csrfheadername" name="csrfheadername" th:content="${_csrf.headerName}"/>
99
<title>Completing signing…</title>
10+
<link rel="stylesheet" href="/css/bootstrap.min.css"/>
1011
<link rel="stylesheet" href="/css/main.css"/>
1112
</head>
1213

1314
<body class="loading-page">
1415
<h2>Completing signing…</h2>
1516
<div class="spinner"></div>
1617

17-
<script>
18+
<div id="error-message" class="alert alert-danger" style="display: none;" role="alert">
19+
<div class="message"></div>
20+
<pre class="details"></pre>
21+
</div>
22+
23+
<p class="text-center p-4" style="display: none;" id="error-actions">
24+
<button id="back-button" class="btn btn-primary">Back</button>
25+
</p>
26+
27+
<script type="module">
28+
import { showErrorMessage } from '/js/errors.js';
29+
1830
(async () => {
1931
try {
2032
const fragment = window.location.hash.slice(1);
@@ -26,6 +38,24 @@ <h2>Completing signing…</h2>
2638
const decoded = atob(fragment);
2739
const payload = JSON.parse(decoded);
2840

41+
if (payload.error) {
42+
console.error("WebEID mobile error:", payload);
43+
44+
showErrorMessage({
45+
code: payload.code ?? "UNKNOWN_ERROR",
46+
message: payload.message ?? "Signing failed",
47+
});
48+
49+
const actions = document.getElementById("error-actions");
50+
const goBackButton = document.getElementById("back-button");
51+
actions.style.display = "block";
52+
goBackButton.addEventListener("click", () => {
53+
window.location.replace("/welcome?error=webeid-callback");
54+
});
55+
56+
return;
57+
}
58+
2959
const csrfHeaderName = document.querySelector('#csrfheadername').content;
3060
const csrfToken = document.querySelector('#csrftoken').content;
3161
const path = window.location.pathname;
@@ -71,7 +101,7 @@ <h2>Completing signing…</h2>
71101

72102
} catch (error) {
73103
console.error("Mobile callback failed", error);
74-
window.location.replace("/welcome?error=mobile-callback");
104+
window.location.replace("/welcome?error=webeid-callback");
75105
}
76106
})();
77107
</script>

example/src/main/resources/templates/webeid-login.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
<head>
44
<meta charset="utf-8">
55
<title>Signing you in…</title>
6+
<link rel="stylesheet" href="/css/bootstrap.min.css"/>
7+
<link rel="stylesheet" href="/css/main.css"/>
68
</head>
79
<body>
810
<div id="error-message" class="alert alert-danger" style="display: none;" role="alert">

0 commit comments

Comments
 (0)