• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Clinical-Genomics / cg / 14885929166

07 May 2025 02:28PM UTC coverage: 85.535%. First build
14885929166

Pull #4162

github

web-flow
Merge 12604ca8a into f9a5f13cd
Pull Request #4162: feat(keycloak authentication)

230 of 370 new or added lines in 16 files covered. (62.16%)

26798 of 31330 relevant lines covered (85.53%)

0.86 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

28.13
/cg/server/endpoints/authentication/auth_error_handler.py
1
from functools import wraps
1✔
2
from flask import flash, redirect, url_for
1✔
3
from keycloak import KeycloakAuthenticationError, KeycloakConnectionError, KeycloakGetError
1✔
4
from pydantic import ValidationError
1✔
5

6
from cg.services.authentication.exc import TokenIntrospectionError, UserNotFoundError, UserRoleError
1✔
7

8

9
def handle_auth_errors(func):
1✔
10
    @wraps(func)
1✔
11
    def wrapper(*args, **kwargs):
1✔
12
        """Catch all authentication related errors and provide a sensible error message.
13
        Redirects the user to the auth.logout endpoint and clears the session.
14
        """
NEW
15
        try:
×
NEW
16
            return func(*args, **kwargs)
×
17

NEW
18
        except KeycloakConnectionError as error:
×
NEW
19
            flash(f"Cannot establish connection with Keycloak. Contact sys-dev: {error}")
×
20
            # If no connection to keycloak can be established return to admin view
NEW
21
            return redirect(url_for("admin.index"))
×
22

NEW
23
        except KeycloakGetError as error:
×
NEW
24
            flash(f"Wrong information send to Keycloak. Contact sys-dev: {error}")
×
25
            # If no connection to keycloak can be established return to admin view
NEW
26
            return redirect(url_for("admin.index"))
×
27

NEW
28
        except TokenIntrospectionError as error:
×
NEW
29
            flash(
×
30
                f"Cannot parse token introspection. Contact sys-dev. If realm_access is missing the user has no assigned roles! Reason: {error}"
31
            )
NEW
32
            return redirect(url_for("admin.index"))
×
33

NEW
34
        except (KeycloakAuthenticationError, UserRoleError) as error:
×
NEW
35
            flash(f"Unauthorised: {error}")
×
NEW
36
            return redirect(url_for("admin.index"))
×
37

NEW
38
        except UserNotFoundError as error:
×
NEW
39
            flash(f"Forbidden access: {error}")
×
NEW
40
            return redirect(url_for("admin.index"))
×
41

NEW
42
        except ValidationError as error:
×
NEW
43
            flash(f"Parsing of authentication models failed. Contact sys-dev: {error}")
×
NEW
44
            return redirect(url_for("admin.index"))
×
45

NEW
46
        except Exception as error:
×
NEW
47
            flash(f"An unexpected error occured. Contact sys-dev: {error}")
×
NEW
48
            return redirect(url_for("admin.index"))
×
49

50
    return wrapper
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc