Closed zRich closed 1 month ago
Why it does not work: You have a call like r_session.start(r_session.start())
. The lua-resty-session
is not designed to handle calls like that. openidc.access_token()
accepts session options to start the session, not a session instance.
For the described scenario you just need to check whether the access_token
is valid, either with openidc.bearer_jwt_verify()
or directly with lua-resty-jwt
library.
Why it does not work: You have a call like
r_session.start(r_session.start())
. Thelua-resty-session
is not designed to handle calls like that.openidc.access_token()
accepts session options to start the session, not a session instance.For the described scenario you just need to check whether the
access_token
is valid, either withopenidc.bearer_jwt_verify()
or directly withlua-resty-jwt
library.
Thanks for your reply @oldium
I use session to save other data, so I pass a session instance.
I changed my solution temporary. I authenticate user through username/password with keycloak rest api to get access_token, then use lua-resty-openidc to verify access_token.
Environment
1.8.0
Keycloak 25.0.3
PostgreSQL
1.25
Use Case
I have two separate applications running with OpenResty:
keycloak.js
for authentication with Keycloak 25.0.3.The Next.js application successfully authenticates users via
keycloak.js
and retrievesaccess_token
,refresh_token
, andid_token
from Keycloak.Question
How can I authenticate users in the first application if they already have valid
access_token
andrefresh_token
obtained via the Next.js application?My Current Approach
keycloak.js
retrieves theaccess_token
andrefresh_token
, these tokens are sent to OpenResty.access_token
,refresh_token
, and setaccess_token_expiration
to0
(essentially faking the token expiration).openidc.access_token
to refresh the tokens using the storedrefresh_token
.Here’s the relevant code:
In
openidc.access_token
, I use the following logic:Problem
Before calling
local session = r_session.start(session_opts)
, thesession_opts
object contains all the expected values (access_token
,refresh_token
, andaccess_token_expiration
). However, after this line, these values are missing in the session.I'm not sure why the session data gets lost after calling
r_session.start(session_opts)
. Is there something wrong with the session handling, or am I missing a step in sharing the tokens across applications?Any help or guidance on how to properly manage authentication sharing between applications would be greatly appreciated!