laravel-keycloak-web-guard icon indicating copy to clipboard operation
laravel-keycloak-web-guard copied to clipboard

Auth driver [keycloak-web] for guard [web] is not defined.

Open lknite opened this issue 1 year ago • 1 comments

alpine-nginx 3.14 laravel 7 php7

followed instructions, added to guard and providers section

image

lknite avatar Sep 17 '22 23:09 lknite

Hi!

Did you followed all instructions to install package? Would you please clear cache and options?

mariovalney avatar Sep 19 '22 13:09 mariovalney

Hello. My servers went off due to a power failure. I need to get them back up and running before I can pick back up on this ticket.

I followed all instructions as far as I know. How do I clear the cache and options? Is that something in laravel or do you mean to clear the cache in the browser? What do you mean by 'options'?

lknite avatar Sep 20 '22 01:09 lknite

I mean Laravel cache:

Clear Cache: php artisan cache:clear

Clear Route Cache: php artisan route:cache

Clear View Cache: php artisan view:clear

Clear Config Cache: php artisan config:cache

mariovalney avatar Sep 20 '22 12:09 mariovalney

I am working to clear out the laravel cache according to your instructions. While I do I wanted to note that I am working with the docker image from the linuxserver project 'docker-heimdall', modifying that one to install 'php7-phar', 'composer', and 'vizir/laravel-keycloak-web-guard'. Maybe this will indicate its not needed to clear the laravel cache?

FROM ghcr.io/linuxserver/baseimage-alpine-nginx:3.14

# set version label
ARG BUILD_DATE
ARG VERSION
ARG HEIMDALL_RELEASE
LABEL build_version="Linuxserver.io version:- ${VERSION} Build-date:- ${BUILD_DATE}"
LABEL maintainer="aptalca"

# environment settings
ENV S6_BEHAVIOUR_IF_STAGE2_FAILS=2

RUN \
 echo "**** install runtime packages ****" && \
 apk add --no-cache --upgrade \
        curl \
        php7-ctype \
        php7-curl \
        php7-pdo_pgsql \
        php7-pdo_sqlite \
        php7-pdo_mysql \
        php7-tokenizer \
        php7-zip \
        php7-phar && \
 echo "**** link /vendor to heimdall vendor folder ****" && \
 mkdir /var/www/localhost/heimdall && \
 mkdir /var/www/localhost/heimdall/vendor && \
 ln -s /var/www/localhost/heimdall/vendor /vendor && \
 echo "**** install composer ****" && \
 curl -s https://getcomposer.org/installer | php && \
 echo "**** install oidc plugin ****" && \
 php /composer.phar require vizir/laravel-keycloak-web-guard --update-with-dependencies --with-all-dependencies && \
 echo "**** install heimdall ****" && \
 mkdir -p \
        /heimdall && \
 if [ -z ${HEIMDALL_RELEASE+x} ]; then \
        HEIMDALL_RELEASE=$(curl -sX GET "https://api.github.com/repos/linuxserver/Heimdall/releases/latest" \
        | awk '/tag_name/{print $4;exit}' FS='[""]'); \
 fi && \
 curl -o \
 /heimdall/heimdall.tar.gz -L \
        "https://github.com/linuxserver/Heimdall/archive/${HEIMDALL_RELEASE}.tar.gz" && \
 echo "**** cleanup ****" && \
 rm -rf \
        /tmp/*

# add local files
COPY root/ /

Testing with the following values in the .env file:

#KEYCLOAK_BASE_URL=https://keycloak.vc-prod.k.home.net/auth/realms/home
KEYCLOAK_BASE_URL=https://keycloak.vc-prod.k.home.net/auth
KEYCLOAK_REALM=home
KEYCLOAK_REALM_PUBLIC_KEY=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAi1E6yZ2KwEzglEeQ0jtGkiYvD78DTDzsTSQ96v12OdD/R3FmuuUex9imK1KnwmlAU2IvoIQ1Rn0d9sf2hMer0STk/K3Xd2HKhTgxl7eo8ro6CG2BBnVyee6ReHApYFKZYQIDAQAB
KEYCLOAK_CLIENT_ID=k.vc-prod.heimdall
KEYCLOAK_CLIENT_SECRET=<client_secret>
#KEYCLOAK_CACHE_OPENID=

What I do to test this is start up the docker container, the .env values are still there when I restart the container but the auth.php are not. If I browse to heimdall everything works and I'm logged in as admin. I exec into the container and modify the auth.php file according to instructions: image

Now when I browse to heimdall I get the error seen in the original posting.

lknite avatar Sep 25 '22 18:09 lknite

Here's what I get when I try to clear (afterwards heimdall is still showing the same error):

root@heimdall-56b46fffd9-4rtd7:/var/www/localhost/heimdall# php artisan cache:clear
Failed to clear cache. Make sure you have the appropriate permissions.
root@heimdall-56b46fffd9-4rtd7:/var/www/localhost/heimdall# php artisan route:cache
Route cache cleared!

In Route.php line 1150:

  Unable to prepare route [single/{appid}] for serialization. Uses Closure.


root@heimdall-56b46fffd9-4rtd7:/var/www/localhost/heimdall# php artisan view:clear
Compiled views cleared!
root@heimdall-56b46fffd9-4rtd7:/var/www/localhost/heimdall# php artisan config:cache
Configuration cache cleared!
Configuration cached successfully!

also, here is the plugin which looks to be successfully installed to me:

# find /vendor/vizir/laravel-keycloak-web-guard/
/vendor/vizir/laravel-keycloak-web-guard/
/vendor/vizir/laravel-keycloak-web-guard/.github
/vendor/vizir/laravel-keycloak-web-guard/.github/stale.yml
/vendor/vizir/laravel-keycloak-web-guard/.gitignore
/vendor/vizir/laravel-keycloak-web-guard/CHANGELOG.md
/vendor/vizir/laravel-keycloak-web-guard/README.md
/vendor/vizir/laravel-keycloak-web-guard/composer.json
/vendor/vizir/laravel-keycloak-web-guard/composer.lock
/vendor/vizir/laravel-keycloak-web-guard/config
/vendor/vizir/laravel-keycloak-web-guard/config/keycloak-web.php
/vendor/vizir/laravel-keycloak-web-guard/src
/vendor/vizir/laravel-keycloak-web-guard/src/Auth
/vendor/vizir/laravel-keycloak-web-guard/src/Auth/Guard
/vendor/vizir/laravel-keycloak-web-guard/src/Auth/Guard/KeycloakWebGuard.php
/vendor/vizir/laravel-keycloak-web-guard/src/Auth/KeycloakAccessToken.php
/vendor/vizir/laravel-keycloak-web-guard/src/Auth/KeycloakWebUserProvider.php
/vendor/vizir/laravel-keycloak-web-guard/src/Controllers
/vendor/vizir/laravel-keycloak-web-guard/src/Controllers/AuthController.php
/vendor/vizir/laravel-keycloak-web-guard/src/Exceptions
/vendor/vizir/laravel-keycloak-web-guard/src/Exceptions/KeycloakCallbackException.php
/vendor/vizir/laravel-keycloak-web-guard/src/Exceptions/KeycloakCanException.php
/vendor/vizir/laravel-keycloak-web-guard/src/Facades
/vendor/vizir/laravel-keycloak-web-guard/src/Facades/KeycloakWeb.php
/vendor/vizir/laravel-keycloak-web-guard/src/KeycloakWebGuardServiceProvider.php
/vendor/vizir/laravel-keycloak-web-guard/src/Middleware
/vendor/vizir/laravel-keycloak-web-guard/src/Middleware/KeycloakAuthenticated.php
/vendor/vizir/laravel-keycloak-web-guard/src/Middleware/KeycloakCan.php
/vendor/vizir/laravel-keycloak-web-guard/src/Models
/vendor/vizir/laravel-keycloak-web-guard/src/Models/KeycloakUser.php
/vendor/vizir/laravel-keycloak-web-guard/src/Services
/vendor/vizir/laravel-keycloak-web-guard/src/Services/KeycloakService.php

lknite avatar Sep 25 '22 18:09 lknite

After working with this a bit and starting over with a clean environment I see the normal heimdall screen at first, then after editing auth.php to 'keycloak-web' and 'keycloak-users' and 'Vizir\KeycloakWebGuard\Models\KeycloakUser::class' now I'm just getting 500, seems the error isn't being caught now, logs show a similar message:

==> /config/log/nginx/error.log <==
2022/09/25 17:10:28 [error] 189#189: *113 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught InvalidArgumentException: Auth driver [keycloak-web] for guard [web] is not defined. in /var/www/localhost/heimdall/vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php:97
Stack trace:
#0 /var/www/localhost/heimdall/vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php(68): Illuminate\Auth\AuthManager->resolve()
#1 /var/www/localhost/heimdall/vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php(307): Illuminate\Auth\AuthManager->guard()
#2 /var/www/localhost/heimdall/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(261): Illuminate\Auth\AuthManager->__call()
#3 /var/www/localhost/heimdall/app/Providers/AppServiceProvider.php(72): Illuminate\Support\Facades\Facade::__callStatic()
#4 /var/www/localhost/heimdall/vendor/laravel/framework/src/Illuminate/View/Concerns/ManagesEvents.php(162): App\Providers\AppServiceProvider->App\Providers\{closure}()
#5 /var/www/localhost/heimdall/vendor/laravel/framework/src/Illuminate/Eve...PHP message: PHP Fatal error:  Uncaught InvalidArgumentException: Auth driver [keycloak-web] for guard [web] is not defined. in /var/www/localhost/heimdall/vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php:97
Stack trace:
#0 /var/www/localhost/heimdall/vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php(68): Illuminate\Auth\AuthManager->resolve()
#1 /var/www/localhost/heimdall/vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php(307): Illuminate\Auth\AuthManager->guard()
#2 /var/www/localhost/heimdall/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(261): Illuminate\Auth\AuthManager->__call()
#3 /var/www/localhost/heimdall/app/Providers/AppServiceProvider.php(72): Illuminate\Support\Facades\Facade::__callStatic()
#4 /var/www/localhost/heimdall/vendor/laravel/framework/src/Illuminate/View/Concerns/ManagesEvents.php(162): App\Providers\AppServiceProvider->App\Providers\{closure}()
#5 /var/www/localhost/heimd

==> /config/log/nginx/access.log <==
172.27.172.220 - - [25/Sep/2022:17:10:28 -0600] "GET / HTTP/1.1" 500 5 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36"

Notes:

  • The 'vendor' folders are the same folder. 'ln -s /var/www/localhost/heimdall/vendor /vendor'

lknite avatar Sep 25 '22 23:09 lknite

working out of repo https://github.com/lknite/docker-heimdall

  • you can see how i'm installing the plugin in the Dockerfile
  • i'm running a couple of your cache clearings commands in root/etc/cont-init.d/60-config-keycloak, the other two seem to error

is there a way to list what auth drivers are installed maybe? so i can verify things are installed correctly ... other troubleshooting ideas?

lknite avatar Sep 26 '22 03:09 lknite

I'm available to work on this today and tomorrow.

lknite avatar Oct 01 '22 18:10 lknite

snippit from pipeline building docker image (this all look correct?):

**** install oidc plugin ****
[91mInfo from https://repo.packagist.org/: #StandWithUkraine
[0m[91mUsing version ^3.0 for vizir/laravel-keycloak-web-guard
[0m[91m./composer.json has been created
[0m[91mRunning composer update vizir/laravel-keycloak-web-guard --with-all-dependencies
[0m[91mLoading composer repositories with package information
[0m[91mUpdating dependencies
[0m[91mLock file operations: 9 installs, 0 updates, 0 removals
  - Locking guzzlehttp/guzzle (7.5.0)
[0m[91m  - Locking guzzlehttp/promises (1.5.2)
  - Locking guzzlehttp/psr7 (2.4.1)
  - Locking psr/http-client (1.0.1)
  - Locking psr/http-factory (1.0.1)
  - Locking psr/http-message (1.0.1)
  - Locking ralouphie/getallheaders (3.0.3)
  - Locking symfony/deprecation-contracts (v2.5.2)
  - Locking vizir/laravel-keycloak-web-guard (v3.0.1)
[0m[91mWriting lock file
[0m[91mInstalling dependencies from lock file (including require-dev)
[0m[91mPackage operations: 9 installs, 0 updates, 0 removals
[0m[91m  - Downloading guzzlehttp/promises (1.5.2)
[0m[91m  - Downloading ralouphie/getallheaders (3.0.3)
[0m[91m  - Downloading psr/http-message (1.0.1)
[0m[91m  - Downloading psr/http-factory (1.0.1)
[0m[91m  - Downloading guzzlehttp/psr7 (2.4.1)
[0m[91m  - Downloading psr/http-client (1.0.1)
[0m[91m  - Downloading symfony/deprecation-contracts (v2.5.2)
[0m[91m  - Downloading guzzlehttp/guzzle (7.5.0)
[0m[91m  - Downloading vizir/laravel-keycloak-web-guard (v3.0.1)
[0m[91m 0/9 [>---------------------------]   0%[0m[91m
 4/9 [============>---------------]  44%[0m[91m
 8/9 [========================>---]  88%[0m[91m
 9/9 [============================] 100%
  - Installing guzzlehttp/promises (1.5.2): Extracting archive
  - Installing ralouphie/getallheaders (3.0.3): Extracting archive
[0m[91m  - Installing psr/http-message (1.0.1): Extracting archive
[0m[91m  - Installing psr/http-factory (1.0.1): Extracting archive
[0m[91m  - Installing guzzlehttp/psr7 (2.4.1): Extracting archive
  - Installing psr/http-client (1.0.1): Extracting archive
[0m[91m  - Installing symfony/deprecation-contracts (v2.5.2): Extracting archive
[0m[91m  - Installing guzzlehttp/guzzle (7.5.0): Extracting archive
[0m[91m  - Installing vizir/laravel-keycloak-web-guard (v3.0.1): Extracting archive
[0m[91m 0/9 [>---------------------------]   0%[0m[91m
 9/9 [============================] 100%
[0m[91m3 package suggestions were added by new dependencies, use `composer suggest` to see details.
[0m[91mGenerating autoload files
[0m[91m4 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
[0m[91mNo security vulnerability advisories found

lknite avatar Oct 01 '22 19:10 lknite

I was running 'composer' in the wrong folder. Needed to change to the folder just below the existing vendor directory in the project I was in. Closing as the project has released with php8 and I'm starting over with my implementation.

lknite avatar Dec 11 '22 05:12 lknite