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
46 changes: 0 additions & 46 deletions .codeclimate.yml

This file was deleted.

5 changes: 4 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Drupal editor configuration normalization
# @see http://editorconfig.org/

# This is the top-most .editorconfig file; do not search in parent directories.
root = true

Expand All @@ -8,4 +11,4 @@ indent_style = space
indent_size = 4
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
insert_final_newline = true
27 changes: 27 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Run CI test

on:
pull_request:
push:
branches:
- master
- develop
- 1.x
- 2.x
- 3.x
- release/**
- hotfix/**
tags:
workflow_dispatch:

jobs:
grumphp:
uses: district09/php_package_dg-api-client/.github/workflows/grumphp.yml@develop
permissions:
contents: write
issues: write
pull-requests: write
with:
php-versions: "['8.3', '8.4']"
tasks: ''
coverage-report: true
104 changes: 104 additions & 0 deletions .github/workflows/grumphp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: Run GrumPHP

on:
workflow_call:
inputs:
php-versions:
description: The PHP versions to run on
required: false
type: string
default: "['8.3', '8.4']"
operating-systems:
description: The operating systems to run on
required: false
type: string
default: "['ubuntu-latest']"
composer-versions:
description: The composer versions to run on
required: false
type: string
default: "['composer:v2']"
tasks:
description: The grumphp tasks to run
required: false
type: string
default: ''
coverage-report:
description: Should the coverage report, when available, be added to the Pull Request as a comment
required: false
type: boolean
default: false
before-install:
description: Script to run before running composer install
required: false
type: string
default: ''
before-test:
description: Script to run before running the test
required: false
type: string
default: ''
simpletest_db:
description: Drupal test database connection string
required: false
type: string
default: 'sqlite://localhost/:memory:'
secrets:
GH_TOKEN:
required: false
jobs:
grumphp:
strategy:
matrix:
operating-system: ${{ fromJson(inputs.operating-systems) }}
php-versions: ${{ fromJson(inputs.php-versions) }}
composer-versions: ${{ fromJson(inputs.composer-versions) }}
fail-fast: false
runs-on: ${{ matrix.operating-system }}
name: PHP ${{ matrix.php-versions }} with ${{ matrix.composer-versions }} on ${{ matrix.operating-system }}
env:
SIMPLETEST_DB: ${{ inputs.simpletest_db }}
steps:
- name: Checkout
uses: actions/checkout@master
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
tools: ${{ matrix.composer-versions }}
extensions: xdebug, mbstring, posix, :redis
- name: Get composer cache directory
id: composercache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composercache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- name: Set Github secret for composer
if: env.GH_TOKEN
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
run: |
composer config --global github-oauth.github.com ${{ secrets.GH_TOKEN }}
- name: Run before install commands
if: ${{ inputs.before-install != '' }}
run: ${{ inputs.before-install }}
- name: Install dependencies
run: |
composer install --no-progress --no-suggest --no-scripts
- name: Run before test commands
if: ${{ inputs.before-test != '' }}
run: ${{ inputs.before-test }}
- name: Run the tests
run: php vendor/bin/grumphp run --no-interaction --tasks='${{ inputs.tasks }}'

# Add comment to PR with the code coverage report.
- name: Coverage Report as Comment (Clover)
if: ${{ github.event_name == 'pull_request' && inputs.coverage-report && hashFiles('build/logs/clover.xml') != '' }}
uses: lucassabreu/comment-coverage-clover@main
with:
file: build/logs/clover.xml
with-chart: false
table-below-coverage: 99.99
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# PHPUnit build artifacts.
/build
.phpunit.cache
.phpunit.result.cache

# Never commit vendors!
Expand Down
28 changes: 0 additions & 28 deletions .travis.yml

This file was deleted.

11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

All Notable changes to `digipolisgent/api-client` package.

## [4.0.0]

_Use version 4 of this module to switch over to OAuth authentication.
Key/secret authentication is dropped from the client.
The client and configuration objects have changed parameters._

### Added

* ZALENZOEK-689: Add OAuth2 API authentication.

## [3.0.1]

### Fixed
Expand Down Expand Up @@ -82,6 +92,7 @@ This includes:
* Interfaces to create services in client packages.

[Unreleased]: https://github.com/digipolisgent/php_package_dg-api-client/compare/master...develop
[4.0.0]: https://github.com/digipolisgent/php_package_dg-api-client/compare/3.0.1...4.0.0
[3.0.1]: https://github.com/digipolisgent/php_package_dg-api-client/compare/3.0.0...3.0.1
[3.0.0]: https://github.com/digipolisgent/php_package_dg-api-client/compare/2.1.0...3.0.0
[2.1.0]: https://github.com/digipolisgent/php_package_dg-api-client/compare/2.0.0...2.1.0
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# DigipolsigGent API Client
# District09 API Client

This package provides interfaces and abstract implementations to create an API client.

Expand Down
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@
{
"name": "Jelle Sebreghts",
"email": "sebreghts.jelle@district09.gent"
},
{
"name": "Lennart Van Vaerenbergh",
"email": "lennart.vanvaerenbergh@district09.gent"
}
],
"homepage": "https://github.com/digipolisgent/php_package_api-client",
"require": {
"php": "^7.4 || ^8.0",
"ext-json": "*",
"guzzlehttp/guzzle": "^6.5 || ^7.0",
"jumbojett/openid-connect-php": "^1",
"psr/http-message": "^1.0",
"psr/simple-cache": "^1.0"
},
Expand Down
36 changes: 36 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheDirectory=".phpunit.cache"
executionOrder="depends,defects"
requireCoverageMetadata="false"
beStrictAboutOutputDuringTests="true"
displayDetailsOnPhpunitDeprecations="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerWarnings="true"
failOnPhpunitDeprecation="true"
failOnRisky="true"
failOnWarning="false"
failOnNotice="false"
>
<source ignoreIndirectDeprecations="true">
<include>
<directory>src</directory>
</include>
</source>

<testsuites>
<testsuite name="Coretalents/Portal">
<directory>tests</directory>
</testsuite>
</testsuites>

<coverage>
<report>
<clover outputFile="build/logs/clover.xml"/>
<html outputDirectory="build/coverage"/>
</report>
</coverage>
</phpunit>
43 changes: 37 additions & 6 deletions src/Client/AbstractClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,20 @@
use DigipolisGent\API\Client\Exception\HandlerNotFound;
use DigipolisGent\API\Client\Handler\HandlerInterface;
use DigipolisGent\API\Client\Response\ResponseInterface;
use DigipolisGent\API\Client\Token\OidcTokenProvider;
use DigipolisGent\API\Client\Token\TokenProviderInterface;
use DigipolisGent\API\Logger\LoggableInterface;
use DigipolisGent\API\Logger\LoggableTrait;
use DigipolisGent\API\Logger\RequestLog;
use GuzzleHttp\ClientInterface as GuzzleClientInterface;
use GuzzleHttp\Exception\ClientException;
use Psr\Http\Message\RequestInterface;
use Psr\SimpleCache\CacheInterface;

/**
* Abstract implementation of the service client.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
abstract class AbstractClient implements ClientInterface, LoggableInterface
{
Expand All @@ -43,16 +48,37 @@ abstract class AbstractClient implements ClientInterface, LoggableInterface
*/
protected ConfigurationInterface $configuration;

/**
* The OIDC token provider.
*
* @var \DigipolisGent\API\Client\Token\TokenProviderInterface
*/
protected TokenProviderInterface $tokenProvider;

/**
* Client constructor.
*
* @param \GuzzleHttp\ClientInterface $guzzle
* The Guzzle HTTP client.
* @param \DigipolisGent\API\Client\Configuration\ConfigurationInterface $configuration
* The client configuration object.
* @param \Psr\SimpleCache\CacheInterface $cache
* Cache used for auth Bearer tokens. Not that this is not for API responses.
*/
public function __construct(GuzzleClientInterface $guzzle, ConfigurationInterface $configuration)
{
public function __construct(
GuzzleClientInterface $guzzle,
ConfigurationInterface $configuration,
CacheInterface $cache,
) {
$this->guzzle = $guzzle;
$this->configuration = $configuration;
$this->tokenProvider = new OidcTokenProvider(
$configuration->getAuthUri(),
$configuration->getClientId(),
$configuration->getClientSecret(),
$configuration->getScope(),
$cache,
);
}

/**
Expand Down Expand Up @@ -90,10 +116,15 @@ public function send(RequestInterface $request): ResponseInterface
*/
protected function injectHeaders(RequestInterface $request): RequestInterface
{
return $request->withHeader(
'Content-Length',
(string) strlen((string) $request->getBody())
);
return $request
->withHeader(
'Content-Length',
(string) strlen((string) $request->getBody())
)
->withHeader(
'Authorization',
'Bearer ' . $this->tokenProvider->getAccessToken()
);
}

/**
Expand Down
Loading