-
Notifications
You must be signed in to change notification settings - Fork 3
feat(keycloak authentication) #4162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
… into feat-keycloak
|
self.keycloak_client: KeycloakClient = keycloak_client | ||
self.keycloak_backend_user = config["trailblazer"]["keycloak_backend_user"] | ||
self.keycloak_backend_user_password = config["trailblazer"][ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keycloak_backend_user: str | ||
keycloak_backend_user_password: str |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove and use client_secret_key instead
def check_role(roles: list[str]) -> None: | ||
"""Check the user roles. | ||
Currently set to a single permissable role, expand if needed. | ||
Args: | ||
roles (list[str]): The user roles received from the RealmAccess. | ||
Raises: | ||
UserRoleError: if required role not present | ||
""" | ||
if not "cg-employee" in roles: | ||
raise UserRoleError("The user does not have the required role to access this service.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good implementation. Will depend on how our user groups are set-up. Likely to change in some degree
if code: | ||
token = keycloak_client.get_token_by_authorisation_code(code) | ||
parsed_token = TokenResponseModel(**token) | ||
LOG.info(f"access_token: {parsed_token.access_token}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove logging the access token
|
||
LOG = logging.getLogger(__name__) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unsure why the logging is needed
keycloak_backend_user: str = "user" | ||
keycloak_backend_user_password: str = "password" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure these are needed
if not logged_in(): | ||
return redirect(url_for("admin.index")) | ||
|
||
|
||
def logged_in(): | ||
user = db.get_user_by_email(email=session.get("user_email")) | ||
return google.authorized and user and user.is_admin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For phase one we could keep the database check and start relying on roles in phase 2
Description
Implements keycloak as authirsation and verification provider for CG
Added
AuthenticationService
Handles logic pertaining to authentication and token verification of users
UserService
handles fetching of users from the database - introduced to reduce coupling of database to endpoints
New endpoints:
auth/login
auth/callback
auth/logout
New config settings in the Flask AppConfig to initiate the authentication service
Changed
Moved app.route("/") to its own blueprint to cleanup the _register_blueprint() function. Increased code clarity
Removed google oauth flow from front end
Fixed
closes: #4159
How to prepare for test
us
paxa
How to test
Expected test outcome
Review
Thanks for filling in who performed the code review and the test!
This version is a
Implementation Plan