<p>I am setting up gatekeeper/louketo as a reverse proxy for a browser app. I have the proxy deployed as a sidecar in a kubernetes pod, with keycloak elsewhere in the same cluster (but accessed by a public URL). Gatekeeper is behind an nginx ingress, which does tls termination.</p>
<p>[I have tried both the most current louketo version and also the fork oneconcern/keycloak-gatekeeper. Some differences, but the issue is the same, so I think its a problem in my configuration.]</p>
<p>Gatekeeper, no matter how I set up the config, reads the discovery url of my realm, but then doesn't redirect on login there. Rather it redirects to my upstream app, using the <code>/oauth/authorize</code> path. I can manually force my app to redirect again to keycloak, but on return from keycloak, gatekeeper doesn't recognize the cookie, and catches me in a redirect loop.</p>
<p>It would seem I am making some simple config error, but I've been working on this for two days, and am at my wit's ends. (Even hacked in extra debugging into the go code, but haven't studied it enough to really know what it is doing.)</p>
<p>My config (best guess of many different variants tried):</p>
<pre><code>        - --config=/var/secrets/auth-proxy-keycloak-config.yaml
        - --discovery-url=https://auth.my-domain.com/auth/realms/my-realm
        - --listen=:4000
        - --upstream-url=http://127.0.0.1:3000
        - --redirection-url=https://dev.my-domain.com/
        - --enable-refresh-tokens=true
        - --enable-default-deny=true
        - --resources=uri=/*|roles=developer
        - --resources=uri=/about|white-listed=true
        - --resources=uri=/oauth/*|white-listed=true
</code></pre>
<p>The ingress serves <code>https://dev.my-domain.com</code> and routes to port 4000, which is the auth proxy sidecar. It is setup with a lets-encrypt certificate, and terminates tls. I don't use tls in the proxy (should I?). Upstream app at port 3000. Keycloak is at auth.my-domain.com. In <code>auth-proxy-keycloak-config.yaml</code> I have encryption key, and client_id. The keycloak client is setup for public access and standard flow (hence no client_secret needed, I presume). I have fiddled with the various uri settings, and also put in web origins &quot;*&quot; for CORS for testing.</p>
<p>When I try a protected url in the browser, I see:</p>
<pre><code>no session found in request, redirecting for authorization  {&quot;error&quot;: &quot;authentication session not found&quot;}
</code></pre>
<p>in the proxy logs, and it redirects me to /oauth/authorize, not to <code>https://auth.my-domain.com/auth/realms/my-realm/protocol/openid-connect/auth</code> where I think it should redirect me.</p>
<p><strong>UPDATE</strong> -- as @jan-garaj noted in comment to answer, <code>/oauth/*</code> shouldn't have been whitelisted. (I got that from a possibly mistaken interpretation of someone else's answer.) I then had to make the cookie not http-only, and finally hit on this issue - <a href="https://stackoverflow.com/questions/53550321/keycloak-gatekeeper-aud-claim-and-client-id-do-not-match">Keycloak-gatekeeper: &#39;aud&#39; claim and &#39;client_id&#39; do not match</a> ... after that it works!</p>

<p>From the Louketo-proxy doc:</p>
<blockquote>
<p>/oauth/authorize is authentication endpoint which will generate the OpenID redirect to the provider</p>
</blockquote>
<p>So that redirect is correct. It is louketo-proxy endpoint. It is not request for your app, it will be processed by louketo-proxy. It will generate another redirect to your IDP, where user needs to login.</p>
<p>Off topic:</p>
<ul>
<li>you really need confidential client and client secret for authorization code flow</li>
<li>web origins &quot;*&quot; for CORS is correct only for http protocol, explicit origin specification is needed for https</li>
</ul>
