Best way to test/debug javascript mappers/policies in Keycloak
Asked Answered
T

2

5

I am new to Keycloak and have been trying to setup javascript based authz policies and client mappers. I was wondering what is the best way to debug such mappers or policies.

Right now, if there are any errors within the script I can only find out it in the server logs, but is there a way where we can use something like alert or console.log; in both cases the server logs mentions:

Caused by: <eval>:18 ReferenceError: "alert" is not defined
Caused by: <eval>:18 ReferenceError: "console" is not defined 

It will be really helpful if when the script runs , if i can atleast log the values of properties or attributes to check whats going on

Tetzel answered 11/1, 2018 at 3:56 Comment(1)
Found the answer to this, keycloak uses Nashorn engine for js and we can use print() to print/logs the values in keycloak consoleTetzel
A
8

You can use

print("something");

you will see it in server logs

Avon answered 15/1, 2019 at 10:22 Comment(1)
I wish there is a way to debug like regular java scripts, I need to inspect objects. When I pass headers in auth requests they are empty.Tepid
V
2

You can start KeyCloak with Debug-Option, e.g. with the following script

#!/bin/bash
echo "Starting KeyCloak"
sh ./keycloak-4.7.0.Final/bin/standalone.sh --debug 6666

I used this to debug my java-mappers and java-provider. Perhaps it can also help for javascript.

Vena answered 18/1, 2019 at 14:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.