OIDC Relying Party flow setup issues #11939
Replies: 1 comment
-
Hey @plamenlakov 👋, I'm here to help you with your OIDC Relying Party flow setup. Let's solve this together! To set up the OIDC Relying Party flow using http-only session cookies in APISIX, you can follow these steps to ensure proper redirection to the OIDC provider login page and back to your frontend application, while allowing dynamic specification of the redirect URI for multiple frontend applications:
Here is a sample configuration snippet: local conf = {
client_id = "your_client_id",
client_secret = "your_client_secret",
discovery = "https://your-oidc-provider/.well-known/openid-configuration",
scope = "openid",
ssl_verify = false,
session = {
secret = "your_session_secret",
cookie = {
lifetime = 3600 -- Set cookie lifetime in seconds
}
},
redirect_uri = nil, -- Allow dynamic redirect URI
unauth_action = "auth", -- Redirect to OIDC provider if not authenticated
}
function _M.rewrite(plugin_conf, ctx)
local conf = core.table.clone(plugin_conf)
conf.timeout = conf.timeout * 1000
local unauth_action = conf.unauth_action
if unauth_action ~= "auth" then
unauth_action = "deny"
end
response, err, _, session = openidc.authenticate(conf, nil, unauth_action, conf.session)
if err then
if session then
session:close()
end
if err == "unauthorized request" then
if conf.unauth_action == "pass" then
return nil
end
return 401
end
core.log.error("OIDC authentication failed: ", err)
return 500
end
if response then
add_access_token_header(ctx, conf, response.access_token)
if response.id_token and conf.set_id_token_header then
local token = core.json.encode(response.id_token)
core.request.set_header(ctx, "X-ID-Token", ngx.encode_base64(token))
end
end
end This configuration ensures that the OIDC Relying Party flow is set up with http-only session cookies, proper redirection, and dynamic redirect URI handling. Additionally, ensure that the To continue talking to Dosu, mention @dosu. Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other |
Beta Was this translation helpful? Give feedback.
-
Hello,
I've successfully implemented the openid-connect plugin to protect my backend services via Keycloak an an OIDC identity provider. However this was done using the token introspection flow, meaning that the bearer token would be stored somewhere in the front-end. Obviously this is not ideal since it makes the token accessible client-side. I'd like to make use of the http-only session cookie same as how the Relying Party flow is being handled but I'm having a bit of trouble setting it up considering backend & frontend are two separate services.
My current APISIX configuration looks like this, but I find it hard on handling this flow on the front-end. How do I redirect to the OIDC provider login page without pointing to an existing RESTful API endpoint (my upstream) and then redirect back to my frontend application? Possibly also being able to specify the redirect uri after successful authentication dynamically, since I want to be flexible in terms of the amount of front-end applications that can communicate with the OIDC authenticated gateway.
My current APISIX config is like this:
Also I'd appreciate your help @dosu ;)
Beta Was this translation helpful? Give feedback.
All reactions