# How to log information in adminAuth's verify function

**URL:** <https://discourse.nodered.org/t/how-to-log-information-in-adminauths-verify-function/61238>\
**Category:** General\
**Tags:** security\
**Created:** [13 April 2022 12:47 UTC](https://discourse.nodered.org/t/how-to-log-information-in-adminauths-verify-function/61238 "2022-04-13T12:47:47Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![trf](https://avatars.discourse-cdn.com/v4/letter/t/a3d4f5/32.png) [@trf](https://discourse.nodered.org/u/trf)\
**Post date:** [13 April 2022 12:47 UTC](https://discourse.nodered.org/t/how-to-log-information-in-adminauths-verify-function/61238/1 "2022-04-13T12:47:47Z")

</div>

Good day, I've successfully implemented oauth authentication against a `keycloak` server using `@exlinc/keycloak-passport`. I am now trying to use information (roles) from the keycloak server to determine what access/permissions is granted as suggested in [this question](https://discourse.nodered.org/t/implicit-list-of-users-in-adminauth/9813) . In order to do so I need to understand what information is present on the profile and accessToken returned by the keycloak server, so Im trying to log this information to the console but am not seeing anything when viewing the log.

Im running node-red version 2.1.4 using the nodered/node-red docker image, and viewing the logs using `docker logs container_name`

What is the correct way to log info in this context, and where should I be looking to see the log output?

Thanks in advance for any help.

```auto
adminAuth: {
        type: "strategy",
        strategy: {
            name: "Keycloak",
            label: 'Sign in',
            icon: "",
            strategy: require("@exlinc/keycloak-passport"),
            options: {
                host: "https://mykeycloak",
                realm: "myrealm",
                clientID: "nodered",
                clientSecret: "XXXXXXXXXXXXXXXXXXXXXXXXXXXX",
                callbackURL: "https://mynodered/auth/strategy/callback",
                authorizationURL: "https://mykeycloak/auth/realms/myrealm/protocol/openid-connect/auth",
                tokenURL: "https://mykeycloak/auth/realms/myrealm/protocol/openid-connect/token",
                userInfoURL: "https://mykeycloak/auth/realms/myrealm/protocol/openid-connect/userinfo"
            },
            verify: function (accessToken, refreshToken, profile, done) {
            	console.log("Test logging");	// not working or not sure where output is logged to
            	console.log(profile); // not working or not sure where output is logged to
                done(null, profile);
            }
        },
        users: [
            { username: "user1@example.com", permissions: ["*"] },
            { username: "user2@example.com", permissions: ["*"] }
        ]
    },

```

---

<div class="post-metadata">

**Author:** ![trf](https://avatars.discourse-cdn.com/v4/letter/t/a3d4f5/32.png) [@trf](https://discourse.nodered.org/u/trf)\
**Post date:** [13 April 2022 13:07 UTC](https://discourse.nodered.org/t/how-to-log-information-in-adminauths-verify-function/61238/2 "2022-04-13T13:07:02Z")

</div>

To add a little more detail, I've enable logging at the debug level in settings.js, and when viewing the logs I see:

 ![logs](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/f/dfcee73ff0c51dc6ad7c1e1c7ec817be1203eb55.png)

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [13 April 2022 13:20 UTC](https://discourse.nodered.org/t/how-to-log-information-in-adminauths-verify-function/61238/3 "2022-04-13T13:20:28Z")

</div>

Is that verify function running under node-red though or under the keycloak server? Maybe check the keycloak logs if it has any. (I've not used it).

---

<div class="post-metadata">

**Author:** ![trf](https://avatars.discourse-cdn.com/v4/letter/t/a3d4f5/32.png) [@trf](https://discourse.nodered.org/u/trf)\
**Post date:** [13 April 2022 15:55 UTC](https://discourse.nodered.org/t/how-to-log-information-in-adminauths-verify-function/61238/4 "2022-04-13T15:55:22Z")

</div>

@TotallyInformation thanks for the reply, I have had a look at the logs on keycloaks side, nothing there unfortunately. I think the verify function is running on node-reds side because I think it is part of the either node-red authentication or passportjs strategy implementation.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [13 April 2022 19:08 UTC](https://discourse.nodered.org/t/how-to-log-information-in-adminauths-verify-function/61238/5 "2022-04-13T19:08:13Z")

</div>

Can you see Node-RED making the call to Keycloak in its logs? If not, I'm guessing it isn't even getting that far.

I've not had time to play with Keycloak yet. It is on my list of things to do but I'll be using it with NGINX most likely as I'll want to know how to secure all endpoints not just Node-RED admin. Ultimately, I want to do a write-up on how to use it with uibuilder.

---

<div class="post-metadata">

**Author:** ![trf](https://avatars.discourse-cdn.com/v4/letter/t/a3d4f5/32.png) [@trf](https://discourse.nodered.org/u/trf)\
**Post date:** [13 April 2022 19:47 UTC](https://discourse.nodered.org/t/how-to-log-information-in-adminauths-verify-function/61238/6 "2022-04-13T19:47:39Z")

</div>

Yeah Im sure Node-RED is making the call to Keycloak, the authentication works fine, Im redirected to Keycloak, login, redirected back, and and logged into Node-RED. Im looking now to assign permissions to the user based on role info from keycloak.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [13 April 2022 19:51 UTC](https://discourse.nodered.org/t/how-to-log-information-in-adminauths-verify-function/61238/7 "2022-04-13T19:51:24Z")

</div>

Sorry, beyond me then. You could try simply throwing an error at the start of the function. At least that would tell you whether it was even being called but I suspect it isn't.

---

<div class="post-metadata">

**Author:** ![trf](https://avatars.discourse-cdn.com/v4/letter/t/a3d4f5/32.png) [@trf](https://discourse.nodered.org/u/trf)\
**Post date:** [13 April 2022 20:14 UTC](https://discourse.nodered.org/t/how-to-log-information-in-adminauths-verify-function/61238/8 "2022-04-13T20:14:48Z")

</div>

Ah yeah thanks, thats a good idea, that should come out somewhere.I'll give that a go.

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [13 April 2022 21:46 UTC](https://discourse.nodered.org/t/how-to-log-information-in-adminauths-verify-function/61238/9 "2022-04-13T21:46:48Z")

</div>

A console.log inside the verify function will get written to the standard output of the Node-RED process. So wherever you are saving that output will contain anything you're logging that way.

---

<div class="post-metadata">

**Author:** ![trf](https://avatars.discourse-cdn.com/v4/letter/t/a3d4f5/32.png) [@trf](https://discourse.nodered.org/u/trf)\
**Post date:** [14 April 2022 06:57 UTC](https://discourse.nodered.org/t/how-to-log-information-in-adminauths-verify-function/61238/10 "2022-04-14T06:57:40Z")

</div>

Thank you all for the help, after understanding that the logging was correct and should be showing I realised the verify function wasnt being called, which was because I had it as a property of adminAuth.strategy (which I had seen a few time for example in [this question](https://discourse.nodered.org/t/help-with-adminauth-config-for-openid-based-authentication/6058/7)) instead of a property of adminAuth.strategy.options. After moving it to the correct place the function is called and the profile object logged.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [28 April 2022 06:58 UTC](https://discourse.nodered.org/t/how-to-log-information-in-adminauths-verify-function/61238/11 "2022-04-28T06:58:14Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
