Skip to content

Header and claim checker management

Checker manager factory services

The Symfony Bundle provides Header and Claim Checker Manager Factory services.

<?php

use Jose\Component\Checker\HeaderCheckerManagerFactory;
use Jose\Component\Checker\ClaimCheckerManagerFactory;

$headerCheckerManagerFactory = $container->get(HeaderCheckerManagerFactory::class);
$headerCheckerManager = $headerCheckerManagerFactory->create([...]);

$claimCheckerManagerFactory = $container->get(ClaimCheckerManagerFactory::class);
$claimCheckerManager = $claimCheckerManagerFactory->create([...]);

Checker manager services

You can create Header and Claim Checker Managers using the bundle configuration.

jose:
    checkers:
        claims:
            checker1:
                is_public: true
                claims: [...]
        headers:
            checker1:
                is_public: true
                headers: [...]

With the previous configuration, the bundle will create public Header and Claim Checker Managers named jose.header_checker.checker1 and jose.claim_checker.checker1 with selected checkers.

Explicit typing

Since 4.3, a header checker manager can declare the media types accepted for the typ header parameter (see Explicit Typing). The bundle registers a TypeChecker service with the alias typ.<name> and adds it to the manager.

jose:
    checkers:
        headers:
            access_token:
                headers: ['alg']
                typ: ['at+jwt'] # A single string is accepted too

The alias typ.access_token can be reused in any other manager or loader, e.g. in the header_checkers option of a JWS loader.

Remember that the checker only rejects a wrong typ: to reject tokens without any, list typ in the mandatory header parameters when calling check().

Custom header or claim checker

Some claim or header checkers are provided by this framework, but it is important to create custom checkers that fit your application requirements.

In the following example, we will assume that the class exist and implement either Jose\Component\Checker\HeaderChecker or Jose\Component\Checker\ClaimChecker.

services
    Acme\Checker\CustomHeaderChecker:
        public: false
        tags:
            - { name: 'jose.checker.header', alias: 'foo' }
    Acme\Checker\CustomClaimChecker:
        public: false
        tags:
            - { name: 'jose.checker.claim', alias: 'bar' }

These checkers will be loaded by the factories and you will be able to create a header or a claim checker manager using the aliases foo or bar.

Custom tags

You can add custom tags and attributes to the header and claim checker managers.

jose:
    checkers:
        claims:
            checker1:
                claims: [...]
                tags:
                    tag_name1: ~
                    tag_name2: {attribute1: 'foo'}