mariovalney / laravel-keycloak-web-guard

Simple Keycloak Guard to Laravel Web Routes - https://packagist.org/packages/vizir/laravel-keycloak-web-guard
146 stars 80 forks source link

Redirect-Problem with HTTPS after logging in #57

Closed philiplb closed 2 years ago

philiplb commented 2 years ago

Hi, I have a problem here with the redirection to the guarded page after logging in: So the Keycloak login page is called, I log in there, Keycloak redirects to https://.../callback. All fine and good so far. But this callback URL is then redirecting to the HTTP homepage which is wrong, I need it to redirect to the HTTPS URL.

My attempts so far:

Is there anything else I can do here?

philiplb commented 2 years ago

I resolved it :) Root cause was that the application is behind a load balancer and so setting the trusted proxies middleware solved it:

<?php

namespace App\Http\Middleware;

use Illuminate\Http\Middleware\TrustProxies as Middleware;
use Illuminate\Http\Request;

class TrustProxies extends Middleware
{
    /**
     * The trusted proxies for this application.
     *
     * @var array|string|null
     */
    protected $proxies = '*';

    /**
     * The headers that should be used to detect proxies.
     *
     * @var int
     */
    protected $headers =
        Request::HEADER_X_FORWARDED_FOR |
        Request::HEADER_X_FORWARDED_HOST |
        Request::HEADER_X_FORWARDED_PORT |
        Request::HEADER_X_FORWARDED_PROTO |
        Request::HEADER_X_FORWARDED_AWS_ELB;
}