| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Facile\OpenIDClient; |
| 6 |
|
| 7 |
use Facile\OpenIDClient\Exception\RuntimeException; |
| 8 |
|
| 9 |
use function base64_decode; |
| 10 |
use function str_pad; |
| 11 |
use function strlen; |
| 12 |
use function strtr; |
| 13 |
|
| 14 |
function base64url_decode(string $data): string |
| 15 |
{ |
| 16 |
$decoded = base64_decode(str_pad(strtr($data, '-_', '+/'), strlen($data) % 4, '='), true); |
| 17 |
|
| 18 |
if (false === $decoded) { |
| 19 |
throw new RuntimeException('Unable to base64url_decode'); |
| 20 |
} |
| 21 |
|
| 22 |
return $decoded; |
| 23 |
} |