# Usage

{% hint style="warning" %}
Your RSA public key **must be accessible** in the filesystem.
{% endhint %}

### The KeyConfiguration

Use the `KeyConfiguration` to let JWKs know what your public key looks like.

```php
$keyConfig = new KeyConfiguration(
    'MY_KEY_ID',
    'RSA256',
    'Use'
);
```

By default:

* `KeyId` will be **automatically generated per request**
* `Algorithm` will be `RSA256` (can be changed in `jwks.php` configuration file)
* `Use` will be `null`

### Create a Key from Raw Content

<pre class="language-php"><code class="lang-php">use ShipSaasLaravelJwks\Entities\Key;

<strong>$key = Key::fromRaw($content, $keyConfig);
</strong></code></pre>

### Create a Key using the file path

```php
use ShipSaasLaravelJwks\Entities\Key;

$key = Key::fromFilePath('/var/www/html/key.pub', $keyConfig); 
```

Please use the **exact** file path.

### Resolve JWK

#### To PHP array

```php
$jwk = $key->toJWK();
$jwk = $key->toArray();
```

#### To String (JSON)

```php
$jwkString = (string) $key;
$jwkString = $key->__toString(); // php magic method
```

### Create a KeySet

KeySet contains 1 or multiple keys

<pre class="language-php"><code class="lang-php">use ShipSaasLaravelJwks\Entities\Key;
use ShipSaasLaravelJwks\Entities\KeySet;

$key1 = Key::fromFilePath(...);
$key2 = Key::fromRawContent(...);

$keySet = new KeySet();
$keySet->add($key1);
$keySet->add($key2);

# Resolve
$jwks = $keySet->toArray();
<strong>$jwksString = (string) $keySet;
</strong></code></pre>

### Default JWKs endpoint

We also ship a default endpoint that prepares the configured keys and returns the JWKs content.

Endpoint: `auth/jwks`

{% hint style="info" %}
You can turn this endpoint on/off from the jwks.php configuration
{% endhint %}
