# Symfony Bundle

The JWT Framework Symfony Bundle provides seamless integration of the JWT Framework into your Symfony applications. It leverages Symfony's dependency injection container to automatically configure and wire all services, making it easy to work with JSON Web Tokens in your Symfony projects.

## Why Use the Symfony Bundle?

The bundle offers several advantages for Symfony developers:

### 🎯 **Zero Configuration**

* Auto-discovery of algorithms and services
* Automatic service registration
* Sensible defaults out of the box

### 🔧 **Configuration-Driven**

* YAML-based configuration for all components
* Type-safe configuration validation
* Environment variable support

### 📊 **Developer Tools**

* Symfony Profiler integration
* Debug toolbar with token inspection
* Data collectors for performance monitoring

### 🔄 **Event System**

* Token lifecycle events
* Hook into token creation and validation
* Perfect for logging and auditing

### 🏭 **Factory Services**

* Pre-configured factories for common operations
* Easy creation of builders, loaders, and validators
* Support for multiple configurations

## Installation

{% hint style="info" %}
The bundle supports Symfony 7.0 and Symfony 8.0.
{% endhint %}

### With Symfony Flex (Recommended)

The bundle is automatically detected and installed when using Symfony Flex:

```bash
composer require web-token/jwt-framework
```

{% hint style="info" %}
As the recipes are third party recipes not officially supported by Symfony, you will be asked whether to execute the recipe or not. When applied, the recipes will display a message: `Web Token Framework is ready.`
{% endhint %}

After installation, the bundle is automatically registered and ready to use!

### Without Symfony Flex

If you're not using Symfony Flex, you need to register the bundle manually:

{% code title="config/bundles.php" %}

```php
<?php

return [
    // ...
    Jose\Bundle\JoseFramework\JoseFrameworkBundle::class => ['all' => true],
];
```

{% endcode %}

## Quick Start Example

After installation, you can configure a simple JWS service:

{% code title="config/packages/jose.yaml" %}

```yaml
jose:
    # Configure the algorithm manager
    jws:
        builders:
            my_jws_builder:
                signature_algorithms: ['HS256']

        verifiers:
            my_jws_verifier:
                signature_algorithms: ['HS256']
```

{% endcode %}

Then use it in your services:

```php
use Jose\Component\Signature\JWSBuilder;
use Jose\Component\Signature\JWSVerifier;

class TokenService
{
    public function __construct(
        private JWSBuilder $jwsBuilder,
        private JWSVerifier $jwsVerifier
    ) {}

    public function createToken(array $claims): string
    {
        // Your token creation logic
    }
}
```

## Bundle Features

The bundle provides comprehensive support for all JWT Framework components. Explore the documentation based on your needs:

### Core Features

* [**Algorithm Management**](https://web-token.spomky-labs.com/the-symfony-bundle/algorithm-management) - Configure signature and encryption algorithms
* [**Key and Key Set Management**](https://web-token.spomky-labs.com/the-symfony-bundle/key-and-key-set-management) - Manage cryptographic keys via configuration
* [**Header and Claim Checkers**](https://web-token.spomky-labs.com/the-symfony-bundle/header-and-claim-checker-management) - Validate token headers and claims

### Token Operations

* [**Signed Tokens (JWS)**](https://web-token.spomky-labs.com/the-symfony-bundle/signed-tokens) - Create and verify signed tokens
  * [JWS Serializers](https://web-token.spomky-labs.com/the-symfony-bundle/signed-tokens/jws-serializers)
  * [JWS Creation](https://web-token.spomky-labs.com/the-symfony-bundle/signed-tokens/jws-creation)
  * [JWS Verification](https://web-token.spomky-labs.com/the-symfony-bundle/signed-tokens/jws-verification)
* [**Encrypted Tokens (JWE)**](https://web-token.spomky-labs.com/the-symfony-bundle/encrypted-tokens) - Create and decrypt encrypted tokens
  * [JWE Serializers](https://web-token.spomky-labs.com/the-symfony-bundle/encrypted-tokens/jwe-serializers)
  * [JWE Creation](https://web-token.spomky-labs.com/the-symfony-bundle/encrypted-tokens/jwe-creation)
  * [JWE Decryption](https://web-token.spomky-labs.com/the-symfony-bundle/encrypted-tokens/jwe-decryption)

### Advanced Features

* [**Configuration Helper**](https://web-token.spomky-labs.com/the-symfony-bundle/configuration-helper) - Programmatic configuration
* [**Events**](https://web-token.spomky-labs.com/the-symfony-bundle/events) - Token lifecycle events and listeners

## Service Auto-wiring

All services created through the bundle configuration are automatically available for auto-wiring. You can inject them by type or by name:

```php
use Jose\Component\Signature\JWSBuilderFactory;
use Jose\Component\Signature\JWSVerifierFactory;

class MyService
{
    public function __construct(
        JWSBuilderFactory $jwsBuilderFactory,
        JWSVerifierFactory $jwsVerifierFactory
    ) {
        // Services are automatically injected
    }
}
```

## Configuration Reference

For a complete configuration reference, run:

```bash
php bin/console config:dump-reference jose
```

## Next Steps

* **New to the bundle?** Start with [Algorithm Management](https://web-token.spomky-labs.com/the-symfony-bundle/algorithm-management)
* **Need to sign tokens?** Check [Signed Tokens](https://web-token.spomky-labs.com/the-symfony-bundle/signed-tokens)
* **Need to encrypt tokens?** Check [Encrypted Tokens](https://web-token.spomky-labs.com/the-symfony-bundle/encrypted-tokens)
* **Advanced configuration?** See [Configuration Helper](https://web-token.spomky-labs.com/the-symfony-bundle/configuration-helper)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://web-token.spomky-labs.com/the-symfony-bundle/symfony-bundle.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
