keycloak-express-middleware 6.0.0 → 6.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -398,10 +398,14 @@ a login or error page.
|
|
|
398
398
|
import responseinterceptor from 'responseinterceptor';
|
|
399
399
|
import keycloakMiddleware from 'keycloak-express-middleware';
|
|
400
400
|
|
|
401
|
+
|
|
401
402
|
function tmpInterceptor(req, respond) {
|
|
403
|
+
// Handling Unauthorized Access (401/403) Gracefully
|
|
402
404
|
respond(200, '<h1>Access Denied</h1><p>You are not authorized to view this page.</p>');
|
|
403
405
|
}
|
|
404
406
|
|
|
407
|
+
// if protectMiddleware('role') return a 403 with keycloak blank page then
|
|
408
|
+
// interceptByStatusCode Handle Unauthorized Access (401/403) Gracefully
|
|
405
409
|
app.get(
|
|
406
410
|
'/test403',
|
|
407
411
|
responseinterceptor.interceptByStatusCode(403, tmpInterceptor),
|
|
@@ -433,6 +437,17 @@ app.get('/access-denied', (req, res) => {
|
|
|
433
437
|
res.render('access-denied');
|
|
434
438
|
});
|
|
435
439
|
|
|
440
|
+
app.get('/access-denied', (req, res) => {
|
|
441
|
+
res.render('access-denied-help');
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
app.get('/access-denied', (req, res) => {
|
|
445
|
+
res.render('access-denied-default');
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
// if protectMiddleware('role') return a 403 with keycloak blank page then
|
|
449
|
+
// interceptByStatusCode Handle Unauthorized Access (401/403) Gracefully
|
|
450
|
+
// by user redirection with tmpInterceptorDinamic logic
|
|
436
451
|
app.get(
|
|
437
452
|
'/test403redirectDynamic',
|
|
438
453
|
responseinterceptor.interceptByStatusCodeRedirectTo(403, tmpInterceptorDinamic),
|
|
@@ -446,6 +461,9 @@ app.get(
|
|
|
446
461
|
### Example 3 — Static Redirect to a Route
|
|
447
462
|
|
|
448
463
|
```js
|
|
464
|
+
// if protectMiddleware('role') return a 403 with keycloak blank page then
|
|
465
|
+
// interceptByStatusCode Handle Unauthorized Access (401/403) Gracefully
|
|
466
|
+
// by user redirection
|
|
449
467
|
app.get(
|
|
450
468
|
'/test403redirectStatic',
|
|
451
469
|
responseinterceptor.interceptByStatusCodeRedirectTo(403, '/access-denied'),
|
|
@@ -466,6 +484,8 @@ app.get(
|
|
|
466
484
|
|
|
467
485
|
|
|
468
486
|
---
|
|
487
|
+
|
|
488
|
+
|
|
469
489
|
## 🧩 Configuration
|
|
470
490
|
In your Express application:
|
|
471
491
|
```js
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "keycloak-express-middleware",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.1",
|
|
4
4
|
"description": "Adapter API to integrate Node.js (Express) applications with Keycloak. Provides middleware for authentication, authorization, token validation, and route protection via OpenID Connect.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|