Skip to content
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

Prevent ftl errors in Keycloak log #65

Merged
merged 14 commits into from Dec 12, 2021
Merged

Prevent ftl errors in Keycloak log #65

merged 14 commits into from Dec 12, 2021

Conversation

garronej
Copy link
Collaborator

@garronej garronej commented Dec 9, 2021

Follow-up of #63

This PR publishes beta releases.

It won't make it into main until this is achieved.

If you want to contribute, thank you and submit your PRs to the branch doge_ftl_errors rather than to main.

@garronej garronej changed the title Doge ftl errors 4.2.14-beta.0 Dec 9, 2021
@garronej garronej changed the title 4.2.14-beta.0 Prevent ftl errors in Keycloak log Dec 9, 2021
@garronej garronej mentioned this pull request Dec 9, 2021
@marziman
Copy link

marziman commented Dec 9, 2021

Thanks @garronej you are awesome mate!
In case someone tries to avoid the error logs in Keycloackify v2, he shall follow the guide below from @garronej .

@garronej
Copy link
Collaborator Author

garronej commented Dec 10, 2021

Hi @marziman,

There is almost no breaking changes between v2 and v4.

You need to install the peer dependencies required: yarn add keycloakify @emotion/react tss-react powerhooks
Install powerhooks and update tss-react to the current version. You are locked on v0.X.X.

There is also useKcMessages that is a bit different.

And finally if you have some missing pages in your KcApp.tsx that are new and you don't have, add them.

If you want up to date examples you have the two template repos and the code of the login of our platform.

@keycloakify keycloakify deleted a comment from marziman Dec 10, 2021
@keycloakify keycloakify deleted a comment from marziman Dec 10, 2021
@Ann2827
Copy link
Collaborator

Ann2827 commented Dec 12, 2021

@garronej Hi! In the meantime, I tried to sort through the object only by known keys. It works. But it looks like over engineering. ftl template Some types are missing in the search. But I'll probably stop developing this idea.

@garronej
Copy link
Collaborator Author

Hello @Ann2827 thanks for your effort.
I rewrote the whole thing yesterday. It now works fast and without logging errors, it prints out well-formatted JS and it's much better FreeMarker code overall🍾
image

The big breakthrough was the realization that using foo.bar?? we can test if a property is dereferencable without throwing if it isn't.
I only tested with login.ftl but there are still some properties that throw when dereferenced.
Namely url. loginUpdatePasswordUrl, url. loginUpdateProfileUrl, url.loginUsernameReminderUrl and url.loginUpdateTotpUrl.
I did what I suggested about them, I implemented a blacklist so that these properties can be skipped. I allowed myself to do that because it's never used in the base theme but I suspect it won’t throw in all conditions, sometimes these value might be needed.
I would like to avoid logging error as much as possible but I'd rather log inconsequential error that potentially preventing some use case from being implemented. I am going to see with the Keycloak team about that.

@garronej
Copy link
Collaborator Author

@Ann2827 A new beta have been released if you want to try it out.

@Ann2827
Copy link
Collaborator

Ann2827 commented Dec 12, 2021

@garronej

I will definitely try the new version tomorrow.
On register.ftl template, you may encounter a problem with auth.attemptedUsername . And this is already bad. If keys: loginUpdatePasswordUrl , loginUpdateProfileUrl , loginUsernameReminderUrl and loginUpdateTotpUrl are not used anywhere, then key attemptedUsername is used on login-reset-password.ftl template. But if you try to get the value by key auth.attemptedUsername on login.ftl and login-reset-password.ftl templates (I didn't check the other templates), then you won't get an error.

On login-update-profile template, you may encounter a problem with updateProfileCtx object. And for saml-post-form.ftl template it will be an error to get the value by key url.loginAction.

Perhaps Keycloak will be able to return only those values that Freemarker templates will be able to read without errors? For example null. FreeMarker can check foo.bar?? or foo.bar!"" if the value cannot be obtained. But FreeMarker can't read extended_hash+string.

@garronej
Copy link
Collaborator Author

garronej commented Dec 12, 2021

@Ann2827 Thank you for your investigation! I added special cases for the cases you mentioned.
I will create special cases like this whenever a new ftl error is reported to me.

I will merge this now a publish a new release.

I have updated the readme to encourage users to report errors that they would spot:

image

@garronej garronej merged commit ad5de21 into main Dec 12, 2021
@garronej garronej deleted the doge_ftl_errors branch December 12, 2021 19:45
@garronej
Copy link
Collaborator Author

4.2.14 is out.

gitbook-com bot pushed a commit that referenced this pull request Jun 17, 2022
garronej added a commit that referenced this pull request Aug 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants