Skip to content

Commit 6b38a21

Browse files
fix: KeyDumpSigner for PHP < 8
1 parent d5048c7 commit 6b38a21

File tree

6 files changed

+86
-41
lines changed

6 files changed

+86
-41
lines changed
Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,48 @@
1-
name: 'CI'
1+
name: CI
22

33
on:
44
pull_request:
55
push:
66
branches:
7-
- 'main'
7+
- main
88

99
env:
1010
COMPOSER_ROOT_VERSION: '1.99.99'
1111

1212
jobs:
1313
lint:
14-
name: 'Lint'
15-
runs-on: 'ubuntu-latest'
14+
name: Lint
15+
runs-on: ubuntu-latest
1616
steps:
17-
- uses: 'actions/checkout@v2'
18-
- uses: 'shivammathur/setup-php@v2'
17+
- uses: actions/checkout@v4
18+
- uses: shivammathur/setup-php@v2
1919
with:
2020
php-version: '7.4'
21-
coverage: 'none'
22-
ini-values: 'memory_limit=-1'
23-
tools: 'composer:v2'
24-
- uses: 'ramsey/composer-install@v1'
21+
coverage: none
22+
ini-values: memory_limit=-1
23+
tools: composer:v2
24+
- uses: ramsey/composer-install@v3
2525
- name: 'Lint the PHP source code'
26-
run: './vendor/bin/parallel-lint src test'
26+
run: ./vendor/bin/parallel-lint src test
2727

2828
coding-standards:
29-
name: 'Coding Standards'
30-
runs-on: 'ubuntu-latest'
29+
name: Coding Standards
30+
runs-on: ubuntu-latest
3131
steps:
32-
- uses: 'actions/checkout@v2'
33-
- uses: 'shivammathur/setup-php@v2'
32+
- uses: actions/checkout@v4
33+
- uses: shivammathur/setup-php@v2
3434
with:
3535
php-version: '7.4'
36-
coverage: 'none'
37-
ini-values: 'memory_limit=-1'
38-
tools: 'composer:v2'
39-
- uses: 'ramsey/composer-install@v1'
40-
- name: 'Check coding standards'
41-
run: './vendor/bin/phpcs src --standard=psr2 -sp --colors'
36+
coverage: none
37+
ini-values: memory_limit=-1
38+
tools: composer:v2
39+
- uses: ramsey/composer-install@v3
40+
- name: Check coding standards
41+
run: ./vendor/bin/phpcs src --standard=psr2 -sp --colors
4242

4343
unit-tests:
44-
name: 'Unit Tests'
45-
runs-on: 'ubuntu-latest'
44+
name: Unit Tests
45+
runs-on: ubuntu-latest
4646
continue-on-error: ${{ matrix.experimental }}
4747
strategy:
4848
fail-fast: false
@@ -55,30 +55,32 @@ jobs:
5555
- '7.3'
5656
- '7.4'
5757
- '8.0'
58+
- '8.1'
59+
- '8.2'
60+
- '8.4'
5861
dependencies:
59-
- 'lowest'
60-
- 'highest'
62+
- lowest
63+
- highest
6164
experimental:
6265
- false
6366
include:
64-
- php-version: '8.1'
65-
experimental: true
66-
composer-options: '--ignore-platform-reqs'
67+
- php-version: '8.3'
68+
experimental: false
6769
steps:
68-
- uses: 'actions/checkout@v2'
69-
- uses: 'shivammathur/setup-php@v2'
70+
- uses: actions/checkout@v4
71+
- uses: shivammathur/setup-php@v2
7072
with:
7173
php-version: '${{ matrix.php-version }}'
72-
coverage: 'pcov'
73-
ini-values: 'memory_limit=-1'
74-
tools: 'composer:v2'
75-
- name: 'Prepare for tests'
76-
run: 'mkdir -p build/logs'
77-
- uses: 'ramsey/composer-install@v1'
74+
coverage: pcov
75+
ini-values: memory_limit=-1
76+
tools: composer:v2
77+
- name: Prepare for tests
78+
run: mkdir -p build/logs
79+
- uses: ramsey/composer-install@v3
7880
with:
7981
dependency-versions: '${{ matrix.dependencies }}'
8082
composer-options: '${{ matrix.composer-options }}'
81-
- name: 'Run unit tests'
82-
run: './vendor/bin/phpunit --colors=always --coverage-clover build/logs/clover.xml'
83-
- name: 'Publish coverage report to Codecov'
84-
uses: 'codecov/codecov-action@v1'
83+
- name: Run unit tests
84+
run: ./vendor/bin/phpunit --colors=always --coverage-clover build/logs/clover.xml
85+
- name: Publish coverage report to Codecov
86+
uses: codecov/codecov-action@v4

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
"phpunit/phpunit": "^5.7 || ^6.0 || ^9.3",
2929
"mockery/mockery": "^1.3",
3030
"php-parallel-lint/php-parallel-lint": "^1.3",
31-
"squizlabs/php_codesniffer": "^2.3 || ^3.0"
31+
"squizlabs/php_codesniffer": "^2.3 || ^3.0",
32+
"composer/semver": "^3.0"
3233
},
3334
"autoload": {
3435
"psr-4": {

phpunit.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<testsuites>
1818
<testsuite name="Package Test Suite">
1919
<directory suffix=".php">./test/</directory>
20+
<exclude>./test/ext/</exclude>
2021
</testsuite>
2122
</testsuites>
2223
</phpunit>

test/ext/KeyDumpSigner5.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace League\OAuth2\Client\Test;
4+
5+
use Lcobucci\JWT\Signature;
6+
use Lcobucci\JWT\Signer;
7+
8+
final class KeyDumpSigner implements Signer
9+
{
10+
public function getAlgorithmId()
11+
{
12+
return 'keydump';
13+
}
14+
15+
public function modifyHeader(array &$headers)
16+
{
17+
$headers['alg'] = $this->getAlgorithmId();
18+
}
19+
20+
public function verify($expected, $payload, $key)
21+
{
22+
return $expected === $key->contents();
23+
}
24+
25+
public function sign($payload, $key)
26+
{
27+
return new Signature($key->contents());
28+
}
29+
}
File renamed without changes.

test/src/KeyDumpSignerLoader.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace League\OAuth2\Client\Test;
4+
5+
use Composer\InstalledVersions;
6+
use Composer\Semver\VersionParser;
7+
8+
if (!InstalledVersions::satisfies(new VersionParser(), 'lcobucci/jwt', '^1 || ^2 || ^3')) {
9+
require_once __DIR__ . '/../ext/KeyDumpSigner8.php';
10+
} else {
11+
require_once __DIR__ . '/../ext/KeyDumpSigner5.php';
12+
}

0 commit comments

Comments
 (0)