Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.yml]
indent_size = 2
66 changes: 23 additions & 43 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,47 +1,27 @@
name: build
on:
pull_request:
paths-ignore:
- 'docs/**'
- 'README.md'
- 'CHANGELOG.md'
- '.gitignore'
- '.gitattributes'

on: [push, pull_request]
push:
paths-ignore:
- 'docs/**'
- 'README.md'
- 'CHANGELOG.md'
- '.gitignore'
- '.gitattributes'

env:
DEFAULT_COMPOSER_FLAGS: "--prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi"
name: build

jobs:
phpunit:
name: PHP ${{ matrix.php }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
php: ['5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0']

steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache composer dependencies
uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install dependencies
run: composer update $DEFAULT_COMPOSER_FLAGS
- name: Run unit tests with coverage
run: vendor/bin/phpunit --verbose --coverage-clover=coverage.clover --colors=always
if: matrix.php == '7.1'
- name: Run unit tests without coverage
run: vendor/bin/phpunit --verbose --colors=always
if: matrix.php != '7.1'
- name: Upload code coverage
run: |
wget https://scrutinizer-ci.com/ocular.phar
php ocular.phar code-coverage:upload --format=php-clover coverage.clover
if: matrix.php == '7.1'
continue-on-error: true # if is fork
phpunit:
uses: yiisoft/actions/.github/workflows/phpunit.yml@master
with:
os: >-
['ubuntu-latest']
php: >-
['8.1', '8.2', '8.3', '8.4']
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ Documentation is at [docs/guide/README.md](https://github.com/yiisoft/yii2-authc
[![Total Downloads](https://poser.pugx.org/yiisoft/yii2-authclient/downloads.png)](https://packagist.org/packages/yiisoft/yii2-authclient)
[![Build Status](https://github.com/yiisoft/yii2-authclient/workflows/build/badge.svg)](https://github.com/yiisoft/yii2-authclient/actions)

Requirements
------------

- PHP 8.1 or higher.

Installation
------------

Expand All @@ -25,13 +30,13 @@ The preferred way to install this extension is through [composer](https://getcom
Either run

```
composer require --prefer-dist yiisoft/yii2-authclient
composer require --prefer-dist yiisoft/yii2-authclient:^22.x-dev
```

or add

```json
"yiisoft/yii2-authclient": "~2.2.0"
"yiisoft/yii2-authclient": "^22.x-dev"
```

to the `require` section of your composer.json.
39 changes: 12 additions & 27 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
{
"name": "yiisoft/yii2-authclient",
"description": "External authentication via OAuth and OpenID for the Yii framework",
"keywords": ["yii2", "OAuth", "OpenID", "OpenID Connect", "auth", "api"],
"keywords": [
"yii2",
"OAuth",
"OpenID",
"OpenID Connect",
"auth",
"api"
],
"type": "yii2-extension",
"license": "BSD-3-Clause",
"support": {
Expand All @@ -18,13 +25,12 @@
}
],
"require": {
"yiisoft/yii2": "~2.0.13",
"yiisoft/yii2-httpclient": "~2.0.5",
"paragonie/random_compat": ">=1"
"php": ">=8.1",
"yiisoft/yii2": "22.0.x-dev",
"yiisoft/yii2-httpclient": "22.x-dev"
},
"require-dev": {
"cweagans/composer-patches": "^1.7",
"phpunit/phpunit": "4.8.34"
"phpunit/phpunit": "^9.6"
},
"suggest": {
"web-token/jwt-checker": "required for JWS, JWT or JWK related flows like OpenIDConnect",
Expand All @@ -34,35 +40,14 @@
"web-token/jwt-signature-algorithm-ecdsa": "required for JWS, JWT or JWK related flows like OpenIDConnect",
"web-token/jwt-signature-algorithm-rsa": "required for JWS, JWT or JWK related flows like OpenIDConnect"
},
"repositories": [
{
"type": "composer",
"url": "https://asset-packagist.org"
}
],
"autoload": {
"psr-4": { "yii\\authclient\\": "src" }
},
"autoload-dev": {
"psr-4": { "yiiunit\\extensions\\authclient\\": "tests" }
},
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
},
"patches": {
"phpunit/phpunit-mock-objects": {
"Fix PHP 7 and 8 compatibility": "https://yiisoft.github.io/phpunit-patches/phpunit_mock_objects.patch"
},
"phpunit/phpunit": {
"Fix PHP 7 compatibility": "https://yiisoft.github.io/phpunit-patches/phpunit_php7.patch",
"Fix PHP 8 compatibility": "https://yiisoft.github.io/phpunit-patches/phpunit_php8.patch"
}
}
},
"config": {
"allow-plugins": {
"cweagans/composer-patches": true,
"yiisoft/yii2-composer": true
}
}
Expand Down
32 changes: 20 additions & 12 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<phpunit bootstrap="./tests/bootstrap.php"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnFailure="false">
<testsuites>
<testsuite name="Test Suite">
<directory>./tests</directory>
</testsuite>
</testsuites>
<phpunit
bootstrap="./tests/bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnFailure="false"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
>
<testsuites>
<testsuite name="Yii2-Authclient">
<directory>./tests</directory>
</testsuite>
</testsuites>
<coverage>
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
</phpunit>
6 changes: 3 additions & 3 deletions src/InvalidResponseException.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ class InvalidResponseException extends Exception
/**
* Constructor.
* @param \yii\httpclient\Response $response response body
* @param string $message error message
* @param string|null $message error message
* @param int $code error code
* @param \Exception $previous The previous exception used for the exception chaining.
* @param \Exception|null $previous The previous exception used for the exception chaining.
*/
public function __construct($response, $message = null, $code = 0, \Exception $previous = null)
public function __construct($response, $message = null, $code = 0, \Exception|null $previous = null)
{
$this->response = $response;
parent::__construct($message, $code, $previous);
Expand Down
22 changes: 11 additions & 11 deletions src/OAuth1.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace yii\authclient;

use Yii;
use yii\base\InvalidParamException;
use yii\base\InvalidArgumentException;
use yii\httpclient\Request;
use yii\web\HttpException;

Expand Down Expand Up @@ -112,17 +112,17 @@

/**
* Composes user authorization URL.
* @param OAuthToken $requestToken OAuth request token.
* @param OAuthToken|null $requestToken OAuth request token.
* @param array $params additional request params.
* @return string authorize URL
* @throws InvalidParamException on failure.
*/
public function buildAuthUrl(OAuthToken $requestToken = null, array $params = [])
public function buildAuthUrl(OAuthToken|null $requestToken = null, array $params = [])
{
if (!is_object($requestToken)) {
$requestToken = $this->getState('requestToken');
if (!is_object($requestToken)) {
throw new InvalidParamException('Request token is required to build authorize URL!');
throw new InvalidArgumentException('Request token is required to build authorize URL!');

Check warning on line 125 in src/OAuth1.php

View check run for this annotation

Codecov / codecov/patch

src/OAuth1.php#L125

Added line #L125 was not covered by tests
}
}
$params['oauth_token'] = $requestToken->getToken();
Expand All @@ -132,15 +132,15 @@

/**
* Fetches OAuth access token.
* @param string $oauthToken OAuth token returned with redirection back to client.
* @param OAuthToken $requestToken OAuth request token.
* @param string $oauthVerifier OAuth verifier.
* @param string|null $oauthToken OAuth token returned with redirection back to client.
* @param OAuthToken|null $requestToken OAuth request token.
* @param string|null $oauthVerifier OAuth verifier.
* @param array $params additional request params.
* @return OAuthToken OAuth access token.
* @throws InvalidParamException on failure.
* @throws InvalidArgumentException on failure.
* @throws HttpException in case oauth token miss-matches request token.
*/
public function fetchAccessToken($oauthToken = null, OAuthToken $requestToken = null, $oauthVerifier = null, array $params = [])
public function fetchAccessToken($oauthToken = null, OAuthToken|null $requestToken = null, $oauthVerifier = null, array $params = [])

Check warning on line 143 in src/OAuth1.php

View check run for this annotation

Codecov / codecov/patch

src/OAuth1.php#L143

Added line #L143 was not covered by tests
{
$incomingRequest = Yii::$app->getRequest();

Expand All @@ -151,7 +151,7 @@
if (!is_object($requestToken)) {
$requestToken = $this->getState('requestToken');
if (!is_object($requestToken)) {
throw new InvalidParamException('Request token is required to fetch access token!');
throw new InvalidArgumentException('Request token is required to fetch access token!');

Check warning on line 154 in src/OAuth1.php

View check run for this annotation

Codecov / codecov/patch

src/OAuth1.php#L154

Added line #L154 was not covered by tests
}
}

Expand Down Expand Up @@ -372,7 +372,7 @@
$signatureKeyParts[] = '';
}

$signatureKeyParts = array_map('rawurlencode', $signatureKeyParts);
$signatureKeyParts = array_map('rawurlencode', array_filter($signatureKeyParts));

return implode('&', $signatureKeyParts);
}
Expand Down
2 changes: 1 addition & 1 deletion src/clients/Facebook.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@
* @return string client auth code.
* @since 2.1.3
*/
public function fetchClientAuthCode(OAuthToken $token = null, $params = [])
public function fetchClientAuthCode(OAuthToken|null $token = null, $params = [])

Check warning on line 197 in src/clients/Facebook.php

View check run for this annotation

Codecov / codecov/patch

src/clients/Facebook.php#L197

Added line #L197 was not covered by tests
{
if ($token === null) {
$token = $this->getAccessToken();
Expand Down
4 changes: 2 additions & 2 deletions tests/AuthActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class AuthActionTest extends TestCase
{
protected function setUp()
protected function setUp(): void
{
$config = [
'components' => [
Expand Down Expand Up @@ -65,7 +65,7 @@ public function testRedirect()
$url = 'http://test.url';
$response = $action->redirect($url, true);

$this->assertContains($url, $response->content);
$this->assertStringContainsString($url, $response->content);
}

public function testGetClientId()
Expand Down
6 changes: 3 additions & 3 deletions tests/BaseClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class BaseClientTest extends TestCase
{
protected function setUp()
protected function setUp(): void
{
$this->mockApplication();
}
Expand All @@ -19,7 +19,7 @@ protected function setUp()
protected function createClient()
{
$oauthClient = $this->getMockBuilder(BaseClient::className())
->setMethods(['initUserAttributes'])
->onlyMethods(['initUserAttributes'])
->getMock();
return $oauthClient;
}
Expand Down Expand Up @@ -227,4 +227,4 @@ public function testSetupStateStorage()
$stateStorage = $client->getStateStorage();
$this->assertTrue($stateStorage instanceof SessionStateStorage, 'Unable to get default http client.');
}
}
}
7 changes: 4 additions & 3 deletions tests/BaseOAuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class BaseOAuthTest extends TestCase
{
use OAuthDefaultReturnUrlTestTrait;

protected function setUp()
protected function setUp(): void
{
parent::setUp();

Expand All @@ -28,7 +28,8 @@ protected function setUp()
protected function createClient()
{
$oauthClient = $this->getMockBuilder(BaseOAuth::className())
->setMethods(['composeRequestCurlOptions', 'refreshAccessToken', 'applyAccessTokenToRequest', 'initUserAttributes'])
->addMethods(['composeRequestCurlOptions'])
->onlyMethods(['refreshAccessToken', 'applyAccessTokenToRequest', 'initUserAttributes'])
->getMock();
return $oauthClient;
}
Expand Down Expand Up @@ -241,7 +242,7 @@ public function testSendRequest($responseStatusCode, $expectedException)
$response->addHeaders(['http-code' => $responseStatusCode]);
$response->setData('success');

$request = $this->getMock(Request::className());
$request = $this->createMock(Request::className());
$request
->expects($this->any())
->method('send')
Expand Down
Loading