JWT Authenticator for symfony

Overview

HalloVerdenJwtAuthenticatorBundle

This bundle provides a JWT authenticator for Symfony applications. It's using PHP JWT Framework for parsing and validating the JWT.

Installation

Make sure Composer is installed globally, as explained in the installation chapter of the Composer documentation.

Applications that use Symfony Flex

Open a command console, enter your project directory and execute:

$ composer require halloverden/symfony-jwt-authenticator-bundle

Applications that don't use Symfony Flex

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

$ composer require halloverden/symfony-jwt-authenticator-bundle

Step 2: Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles in the config/bundles.php file of your project:

// config/bundles.php

return [
    // ...
    HalloVerden\JwtAuthenticatorBundle\HalloVerdenJwtAuthenticatorBundle::class => ['all' => true],
];

Configuration

Security config

The authenticator is enabled and configured in the security config.

example config:

# config/packages/security.yaml
security:

  # ...
  firewalls:
    main:
      hallo_verden_jwt:
        jwt_name:
          key_set: 'my_key_set'
          jws_loader: 'hallo_verden_default'
          claim_checker: 'hallo_verden_default'
          mandatory_claims: []
          user_identifier_claim: 'sub'
          token_extractor: 'hallo_verden.token_extractor.bearer'
          failure_handler: ~
        some_other_jwt:
          key_set: 'my_ket_set'

For each key in hallo_verden_jwt an authenticator is created.

Key set (key_set)

You need to provide a key set.

See PHP JWT Framework for how to provide a key set.

JWS Loader (jws_loader)

There is a default JWS loader provided (hallo_verden_default), this loader is using the jws_compact serializer and supports RS256 and HS256 signature algorithms.

See PHP JWT Framework for how to create your own loader.

Claim checker (claim_cheker)

There is a default claim checker provided (hallo_verden_default), this checker checks the exp, iat and nbf claims.

See PHP JWT Framework for how to create your own checker.

Mandatory claims (mandatory_claims)

Here you specify the claims that need to be mandatory in your JWT. The user_identifier_claim is automatically added as a mandatory claim.

User identifier claim (user_identifier_claim)

This claim is sent to the user provider for retrieving the user.

Token extractor (token_extractor)

The default extractor hallo_verden.token_extractor.bearer get the bearer token from the authorization header. You can create your own extractor by implementing the TokenExtractorInterface and set the service id to this option.

Failure handler (failure_handler)

By default, the following response is sent on failure:

{
  "error": "INVALID_TOKEN"
}

You can modify this by creating a service implementing the AuthenticationFailureHandlerInterface and set the service id to this option.

You might also like...
A PHP boilerplate based on Slim Framework, for start projects with Eloquent ORM, Validation, Auth (JWT), Repositories and Transformers ready

A PHP boilerplate based on Slim Framework, for start projects with Eloquent ORM, Validation, Auth (JWT), Repositories and Transformers ready.

Single file PHP that can serve as a JWT based authentication provider to the PHP-CRUD-API project

Single file PHP that can serve as a JWT based authentication provider to the PHP-CRUD-API project

JSON Web Token (JWT) for webman plugin
JSON Web Token (JWT) for webman plugin

JSON Web Token (JWT) for webman plugin Json web token (JWT), 是为了在网络应用环境间传递声明而执行的一种基于JSON的开放标准((RFC 7519).该token被设计为紧凑且安全的,特别适用于分布式站点的单点登录(SSO)场景。

Sistema de Administrativo - Cliente e Vendedor - Autenticação JWT e Relacionamentos  BD
Sistema de Administrativo - Cliente e Vendedor - Autenticação JWT e Relacionamentos BD

Hi there, My name is ATTILA SAMUELL TABORY, I love technology 👋 Sistema Administrativo Laravel e Vue JS - JWT e Relacionamentos BD Sistema Administra

Aplicação criada com Slim Framework com objetivo de criar autenticação com JWT e aprender sobre o framework Slim

Slim JWT App Essa aplicação tem como foco o aprendizado do Framework Slim e também a utilização de JWT. Como rodar a Aplicação A aplicação está config

OAuth client integration for Symfony. Supports both OAuth1.0a and OAuth2.

HWIOAuthBundle The HWIOAuthBundle adds support for authenticating users via OAuth1.0a or OAuth2 in Symfony. Note: this bundle adds easy way to impleme

example of LexikJWTAuthenticationBundle with Symfony 4.4

Install Dependency composer install Generate the SSL keys: php bin/console lexik:jwt:generate-keypair Create database php bin/console doctrine:datab

Implements a Refresh Token system over Json Web Tokens in Symfony

JWTRefreshTokenBundle The purpose of this bundle is manage refresh tokens with JWT (Json Web Tokens) in an easy way. This bundles uses LexikJWTAuthent

Symfony bundle to publish status updates on Facebook, LinkedIn and Twitter.

Upgrading? Check the upgrade guide. What's this? This is a Symfony bundle written in PHP 7.1 that wraps martin-georgiev/social-post - an easy way for

Comments
  • Feature/set raw token on jwt

    Feature/set raw token on jwt

    Sometimes we need to get the raw token, before the authentication token i created (e.g. when creating the user). We already have access to the Jwt object, so putting it there is very handy.

    enhancement 
    opened by tomme87 0
Owner
Hallo Verden
Hallo Verden
PHP class to generate and verify Google Authenticator 2-factor authentication

Google Authenticator PHP class Copyright (c) 2012-2016, http://www.phpgangsta.de Author: Michael Kliewe, @PHPGangsta and contributors Licensed under t

Michael Kliewe 2.1k Jan 2, 2023
JWT auth for Laravel and Lumen

JWT Artisan Token auth for Laravel and Lumen web artisans JWT is a great solution for authenticating API requests between various services. This packa

⑅ Generation Tux ⑅ 141 Dec 21, 2022
Laravel Auth guard for FusionAuth JWT

Laravel FusionAuth JWT Implement an Auth guard for FusionAuth JWTs in Laravel. It ships with also a middleware to check against the user role. Install

Theraloss 7 Feb 21, 2022
Security Defense for Firebase's PHP-JWT Library

PHP-JWT-Guard Protect your code from being impacted by issue 351 in firebase/php-jwt. Installation First, install this library with Composer: composer

Paragon Initiative Enterprises 8 Nov 27, 2022
Simple JWT Auth support for Laravel PHP Framework

Laravel JWT Simple JWT Auth for Laravel PHP Framework using Firebase JWT under the hood. Installation Standard Composer package installation: composer

Ricardo Čerljenko 34 Nov 21, 2022
Probando JWT en Laravel

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

SelsiusRC28 1 Nov 2, 2021
Rest API - JWT - Symfony5

Symfony5 JWT - REST API Example Symfony5 JWT - REST API Example Built With PHP Symfony 5 PostgreSQL Getting Started This is an example of how you may

Salih Gencer 1 Dec 24, 2021
PSR-7 and PSR-15 JWT Authentication Middleware

PSR-7 and PSR-15 JWT Authentication Middleware This middleware implements JSON Web Token Authentication. It was originally developed for Slim but can

Mika Tuupola 782 Dec 18, 2022
PHP package for JWT

PHP-JWT A simple library to encode and decode JSON Web Tokens (JWT) in PHP, conforming to RFC 7519. Installation Use composer to manage your dependenc

Firebase 8.6k Jan 7, 2023
Laravel JWT-Authentication API starter kit for rapid backend prototyping.

Laravel JWT API A Laravel JWT API starter kit. Features Laravel 8 Login, register, email verification and password reset Authentication with JWT Socia

Oybek Odilov 3 Nov 6, 2022