feat(auth): add keycloak and auth Logic #44#355
Conversation
peggimann
left a comment
There was a problem hiding this comment.
As for the backend part, i reckon the approach definitely is the right one. The architecture and design is clean. There are some questions raised however. In my opinion it is not a promising pattern to have the user identifier (email) as optional. Currently our LDAP system uses preffered_username as unique identifier for an user so the token must contain it otherwise you should not authorize the user. Further the email must exist too if not you should not authorize this user too. I propose to use preffered_username as the key to identify a user as this is guaranteed to be unique and matches the ldap, if you dont like that take the email as you did, however do not make it optional as this forces you to handle cases you can't handle properly in the app. The idea is neat to have a backup authorization but in general a user either fulfills the requirements to be authorized and authenticated (e.g. have an email) or he wont be authorized (401) and for sure not authenticated (403).
|
You have 3 libraries to handle the auth flow, why? |
Frontend Test Results 1 files ± 0 45 suites +3 36s ⏱️ +11s Results for commit 6931a98. ± Comparison against base commit 8fa3018. This pull request removes 1 and adds 19 tests. Note that renamed tests count towards both.♻️ This comment has been updated with latest results. |
@kcinay055679 I've gone with |
The whole thing is sadly a bit more complicated. I initially wanted to us something else rather than the email but I've decided on the email for the reason that this is an information that can be synced over from PTime via API. Otherwise the The reason why the email is optional, is that members can exist in this system before they ever do in our LDAP. Hence they have (not yet) an email assigned to them. The flow looks roughly like this:
I am aware that all of this is not the ideal solution from a technical standpoint but the best I could think up for both technical and business reasons. Nonetheless, I do not want to make this a hill for me to die on, so maybe we brainstorm together over a coffee? ☕
|
40478a4 to
1a0987d
Compare
c2eb331 to
0f6ec0e
Compare
17cde20 to
edc2b4a
Compare
d0e297f to
47ebfc9
Compare
TODOUse
|
66b30b4 to
874f32e
Compare
9e5837e to
b53d5e4
Compare
84a9a87 to
f3b1f71
Compare
Backend Test Results721 tests +31 721 ✅ +31 1m 2s ⏱️ +9s Results for commit 44d832b. ± Comparison against base commit f8c4373. This pull request removes 7 and adds 38 tests. Note that renamed tests count towards both.♻️ This comment has been updated with latest results. |
f063ad1 to
44d832b
Compare
# Conflicts: # docker/docker-compose.yml
This reverts commit e8f9669.
44d832b to
24a6695
Compare
Authentication
It looks way worse than it is, most of the files are just renaming, tests and moving of some dependencies.
To make the reviewing a bit easier, here is an overview of what changed and why.
Backend
Configuration
Configurations are defined as records and immutable, making them relatively safe to pass around.
The following can be configured:
Some of the configuration can be accessed through the
/configurationendpoint, this is basically the things which are necessary for the frontend to function.Annotations
There are 5 new annotations used for authorization:
IsAdmin: only accessible by people with the roles defined in the configurationIsOwner: only accessible if the user that access the resource is the owner of the resourceIsAdminOrOwner: either or of the two aboveIsAuthenticated: the user must only be authenticatedThe owner is identified by their email address. If no email is defined in either the JWT or the database, access is denied.
Email
An email property was added to the member so an owner can be identified. If there is a better way to do this, I am very open for ideas :D
Frontend
keycloak-angular
The integration with keycloak was done with the keycloak-angular library, which is configured in the
app.config.ts.Guard
The guard checks wether a user:
The roles are loaded from the backend, aswell as which id is connected to the users email address for the redirect.
Testing
Manual
Simply start the application and login as either:
gl:glmember:memberThe member should only have access to his own details page, the admin should be able to do everything.
E2E
E2E test have been changed to include a login, aswell as new ones that check wether the permission and redirects work.