Download the PHP package wg-hyve/keycloak-laravel-guard without Composer

On this page you can find all versions of the php package wg-hyve/keycloak-laravel-guard. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package keycloak-laravel-guard

Keycloak Laravel Implementation

This Keycloak lib does not load users from database. Keycloak user UUIDs are usually stored in the sub claim.

Installation

Configuration

Add your keycloak to your guards and use it in your routes as middleware. That's it for a normal usage.

config/auth.php

routes/api.php

Extended usage

The KeycloakGuard comes with some methods to keep it easy.

Example usage in requests

Other Methods

getTokenFromRequest

Get raw Token from request

token(): ?stdClass

Get encoded Token from request

hasRole(array|string $roles): bool

Proofs if the role or one of the roles is in your client or global roles

scopes(): array

Delivers all scopes

hasScope(string|array $scope): bool

Proofs if the scope or one of the scopes is in your JWT

getRoles(): array

Delivers all roles from your client. Client is delivered in azp claim.

roles(bool $useGlobal = true): array

Delivers all roles (global & client)

User

Saving users in a local database is disabled per default. Execute following steps to enable it. Make sure you read the instructions for the environment variables in your .env.

Configuration

Enable KEYCLOAK_PROVIDE_LOCAL_USER in your environment.

The guard will save user objects from JWTs.

Migrations

Publish und execute migrations.

Make adjustments and migrate.

User Model

Update your user model in config/auth.php. You can also extend it and add your own user model.

You are free to use your user model to extend and define custom relations. Make sure it is compatible with the migration above.

Usage

Receive the User instance with user()

Environment Variables

Local Public key of your Keycloak instance. You can find it in https://your-keycloak.dev.com/auth/realms/your_realm/

Should be azp or client_id depending on your Keycloak configuration

true or false, auto check if role given with is in your token

role to auto check

URL to load public key. Usually https://your-keycloak.dev.com/auth/realms/your_realm/

Cache duration for downloaded public key of your realm.

You want to set the time offset in seconds if you get Cannot handle token prior to (time) error. Use this if your app and Keycloak timings differ.

Enable local user processing. The guard will try to store the user in a local database. Default is false.

The user UUID in your JWT. Default is sub claim.

The email claim in your JWT. Default is email.

The firstname claim in your JWT. Default is given_name.

The lastname claim in your JWT. Default is family_name.

Testing

Commands

Docker

Test in docker with coverage after you extended to lib. Don't install xdebug locally 🐌

Create a new source JSON file

Source files are stored in tests/Data Generated tokens are stored in tests/Data/tokens


All versions of keycloak-laravel-guard with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
laravel/framework Version ^10.10|^11.0
firebase/php-jwt Version ^6.10
sinema/json-api-error-laravel Version ^0.4.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package wg-hyve/keycloak-laravel-guard contains the following files

Loading the files please wait ....