Getting token from server using javascript/node

Hi,

i am struggling to understand how I am supposed to get token from a server only app.
When in the browser I am pretty much clear - with keycloak-js all is fine.

Now when I need to connect from the server side, I don’t see how to do it.
keycloakjs seems to require a ‘window’ - so can’t really use it there.

And the keycloak-connect for nodejs seem to be focused on protecting routes in Express more than anything else…

So shall I write something from scratch using the OpenID Connect endpoints? I am pretty sure there is a much simpler alternative.

Any idea?

As I understand your question, you are using keycloak in your backend for authentication and authorization.

You can use expose-token=true in your deployment configuration.

Then you can use this endpoint to get the token from server /k_query_bearer_token.

From KC documentation

expose-token

If true , an authenticated browser client (via a JavaScript HTTP invocation) can obtain the signed access token via the URL root/k_query_bearer_token . This is OPTIONAL . The default value is false .

thanks for the input

Just to update, for now I have fixed the problem using Grant Password.