Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
93e696c
fix(recaptcha): treat a missing or empty token as invalid instead of …
ajibarra Aug 28, 2026
0cb5608
89 - Allow string url for verify action
ajibarra Mar 14, 2025
0304d2f
Add keycloak support
robitmoh Apr 30, 2024
6461d9d
Change role mapping
robitmoh May 24, 2024
2784106
Fix variables types
robitmoh Jul 19, 2024
362daa3
Typo error
robitmoh Jul 19, 2024
dd7d92c
Add keycloak support to Social auth
robitmoh Apr 1, 2025
5517927
Add composer example
robitmoh Apr 1, 2025
3e0de3a
Add Event listener
robitmoh Apr 1, 2025
334483d
Namespace corrections
robitmoh Apr 1, 2025
efe6c8a
Fix: Remove dependency on CakeDC\Users\Plugin class
robitmoh Apr 14, 2025
481a81e
Add 'validated' field mapping and enhance constructor to support cust…
robitmoh Oct 27, 2025
05f9334
add openid connect service
steinkel Sep 7, 2023
a09bf0f
fix cs
steinkel Sep 7, 2023
1269929
#openid-connect-linkedin add linkedin connect mapper
steinkel Sep 7, 2023
05e60c3
fix cs
steinkel Sep 7, 2023
d5afa91
#openid-connect-linkedin update docs
steinkel Sep 7, 2023
4d859da
fix cs
steinkel Sep 7, 2023
dc64e62
#openid-connect-linkedin add firebase requirement for OIDC
steinkel Sep 7, 2023
f8cb404
feat: tests for OpenID. WIP
arodu Sep 14, 2023
73d90f1
test: add test
arodu Sep 30, 2023
2546a37
#openid-connect-linkedin ignore
steinkel Apr 22, 2025
aa7e7b8
Add OTPRule and className rule config in Rbac permissions
skie Sep 5, 2024
6bf9262
fix: review fixes for the integrated pull requests, curate composer d…
arusinowski Oct 30, 2026
8bfb492
fix: address code review findings, add missing tests
arusinowski Nov 6, 2026
99dab39
ci: make static analysis blocking, test lowest dependencies, update a…
arusinowski Nov 6, 2026
ab2c02e
refactor: deprecate Plugin in favor of AuthPlugin
arusinowski Nov 6, 2026
1cfc3f7
fix(test): BaseTestTrait data provider attribute, CSV parsing
arusinowski Nov 6, 2026
1d2ac37
11.1: deprecations, review fixes, stricter static analysis, docs
arusinowski Nov 7, 2026
737019d
fix(rbac): throw for malformed allowed and bypassAuth rule configs
arodu Nov 13, 2026
b432b4d
fix(social): keep rolesMap for provider aliases using the Keycloak ma…
arodu Nov 13, 2026
c780827
fix(openid): reject dot segments in jwks_uri paths
arodu Nov 13, 2026
1f4a379
fix(social): require a boolean true for validated email claims
arodu Nov 13, 2026
6170a22
fix(auth): only join a flat list of one time token characters
arodu Nov 13, 2026
8426479
test(openid): cover a cached key set without the token kid
arodu Nov 13, 2026
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
104 changes: 44 additions & 60 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,61 +5,58 @@ on:
push:
pull_request:

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
testsuite:
# Pull requests from branches of this repository are already tested by the push event
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
php-version: ['8.2', '8.3', '8.4', '8.5']
db-type: [sqlite, mysql, pgsql]
prefer-lowest: ['']
dependencies: [highest]
include:
- php-version: '8.2'
db-type: sqlite
dependencies: lowest

name: PHP ${{ matrix.php-version }}, ${{ matrix.db-type }}, ${{ matrix.dependencies }} dependencies

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
with:
persist-credentials: false

- name: Setup MySQL latest
- name: Setup MySQL
if: matrix.db-type == 'mysql'
run: |
sudo service mysql start
mysql -h 127.0.0.1 -u root -proot -e 'CREATE DATABASE cakephp;'


- name: Setup PostgreSQL latest
- name: Setup PostgreSQL
if: matrix.db-type == 'pgsql'
run: docker run --rm --name=postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=cakephp -p 5432:5432 -d postgres

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, intl, apcu, memcached, redis, pdo_${{ matrix.db-type }}, ${{ matrix.db-type }}
ini-values: apc.enable_cli = 1
coverage: pcov

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Get date part for cache key
id: key-date
run: echo "::set-output name=date::$(date +'%Y-%m')"

- name: Cache composer dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}-${{ matrix.prefer-lowest }}
extensions: mbstring, intl, pdo_${{ matrix.db-type }}
coverage: none

- name: Composer install
run: |
if ${{ matrix.prefer-lowest == 'prefer-lowest' }}; then
composer update --prefer-lowest --prefer-stable
else
composer update
fi
uses: ramsey/composer-install@v3
with:
dependency-versions: ${{ matrix.dependencies }}
composer-options: --prefer-stable

- name: Setup problem matchers for PHPUnit
if: matrix.php-version == '8.2' && matrix.db-type == 'mysql'
Expand All @@ -70,58 +67,45 @@ jobs:
if [[ ${{ matrix.db-type }} == 'sqlite' ]]; then export DB_URL='sqlite:///:memory:'; fi
if [[ ${{ matrix.db-type }} == 'mysql' ]]; then export DB_URL='mysql://root:root@127.0.0.1/cakephp?encoding=utf8'; fi
if [[ ${{ matrix.db-type }} == 'pgsql' ]]; then export DB_URL='postgres://postgres:postgres@127.0.0.1/postgres'; fi
if [[ ${{ matrix.php-version }} == '8.2' ]]; then
export CODECOVERAGE=1 && vendor/bin/phpunit --coverage-clover=coverage.xml
else
vendor/bin/phpunit
fi

- name: Submit code coverage
if: matrix.php-version == '8.2'
uses: codecov/codecov-action@v1
vendor/bin/phpunit

# Codecov is disabled: uploads need a CODECOV_TOKEN secret. To enable it, set `coverage: pcov`
# for PHP 8.2, run `vendor/bin/phpunit --coverage-clover=coverage.xml` and uncomment this step.
# - name: Submit code coverage
# if: matrix.php-version == '8.2' && matrix.db-type == 'sqlite' && matrix.dependencies == 'highest'
# uses: codecov/codecov-action@v5
# with:
# token: ${{ secrets.CODECOV_TOKEN }}
# files: coverage.xml
# fail_ci_if_error: true

cs-stan:
name: Coding Standard & Static Analysis
runs-on: ubuntu-22.04
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
runs-on: ubuntu-24.04

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v5
with:
persist-credentials: false

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
extensions: mbstring, intl, apcu, memcached, redis
tools: cs2pr
extensions: mbstring, intl
coverage: none

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Get date part for cache key
id: key-date
run: echo "::set-output name=date::$(date +'%Y-%m')"

- name: Cache composer dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}-${{ matrix.prefer-lowest }}

- name: composer install
run: composer stan-setup
- name: Composer install
uses: ramsey/composer-install@v3

- name: Run PHP CodeSniffer
run: composer cs-check
continue-on-error: true

- name: Run psalm
if: success() || failure()
run: composer psalm
continue-on-error: true

- name: Run phpstan
if: success() || failure()
run: composer stan
continue-on-error: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/.idea
composer.lock
.php_cs.cache
.phpunit.result.cache
145 changes: 143 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,152 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [11.1.0] - Unreleased
### Upgrade notes
No public API was removed, the changes below are compatible for applications using the plugin as
documented. Check these behavior changes when upgrading:

- Requires CakePHP `^5.4`.
- Azure social login: `validated` is only `true` with the `email_verified` or `xms_edov` claim. With
CakeDC/Users, Azure users without these claims are no longer treated as having a verified email.
- The `LinkedIn`, `Instagram`, `Pinterest` and `Tumblr` mappers raise a deprecation warning. Test
suites that fail on deprecations fail until the provider is changed or the warning is ignored with
`Error.ignoredDeprecationPaths`.
- `BaseTestTrait`: the `provider()` method of the test class must be static, and the test user is
stored at `Auth.Authenticators.Session.sessionKey` (`Auth` by default) instead of `Auth.User`.
Applications whose session authenticator reads `Auth.User` set that config key to `Auth.User`.
- The default `resetOneTimePasswordAuthenticator` permission allows users with integer ids to reset
their own one time password authenticator, the old closure always denied them.
- Code calling `TwoFactorProcessorInterface::getUrlByType()` must handle a string url.
- An `allowed` or `bypassAuth` array with a `className` that is not a `Rule` throws an
`InvalidArgumentException`, it allowed every logged in user before.
- Configuration errors throw `InvalidArgumentException` (or `JsonException` for rule options that can
not be encoded) instead of a `TypeError`. Requests without a social `provider` param get a 404
instead of a 500.
- The Rbac match reason (debug log and `Auth.Rbac.checked` event) says `result = true` or
`result = false` instead of `1` or an empty string.

### Security
- The `Azure` social mapper trusted any `upn` as a validated email (the "nOAuth" pattern). `validated`
is now only `true` with the `email_verified` or `xms_edov` claim.
- An Rbac `allowed` or `bypassAuth` rule config whose `className` is missing or is not a `Rule`
allowed every logged in user. It now throws an `InvalidArgumentException`.
- The OpenID Connect service validates the id token signature and its `iss`, `aud`, `azp` and `nonce`
claims, only loads the key set from a `jwks_uri` on the scheme, host and port of `openid.baseUrl`
and a path below it without `.` or `..` segments (raw or percent-encoded), and the
`LinkedInOpenIDConnect` mapper reads `validated` from `email_verified`.
- A partial Keycloak `mapFields` config dropped the `roles` field, so the `rolesMap` check let users
without a mapped role log in. The configured fields are now merged over the mapper fields.
- The `Tumblr` mapper is deprecated: its user id is a crc32 of the nickname, so two users can get the
same id.

## [10.1.2] - 2025-09-26
### Added
- Keycloak social login mapper `CakeDC\Auth\Social\Mapper\Keycloak`, with realm roles mapped by the
`rolesMap` provider config (case-sensitive, no default map), and a disabled `keycloak` provider in
`config/auth.php` with a commented example roles map.
- `CakeDC\Auth\Social\Service\OpenIDConnectService` and the `LinkedInOpenIDConnect` mapper and
provider. The id token `iss`, `aud`, `azp` and `nonce` claims are validated, the discovery document and the
key set can be cached with `openid.cache` (the key set is fetched again when a token uses an unknown
key id). The LinkedIn mapper reads `validated` from `email_verified`. Requires `firebase/php-jwt`.
- `CakeDC\Auth\Rbac\Rules\OTPRule`, used by the default `resetOneTimePasswordAuthenticator` permission.
- Rbac permission values can be a rule config array `['className' => Rule::class, 'options' => []]`.
Arrays with a `className` key that is not a `Rule` class keep the previous matching behavior, except
for `allowed` and `bypassAuth`: there such an array throws an `InvalidArgumentException` instead of
allowing every logged in user. In `bypassAuth`, a rule config (like a `Rule`) is only evaluated for
logged in users, only `true` or a callable opens a permission to anonymous requests. The array form requires this version, older versions treat it as
allowed for every logged in user, so do not copy the new `config/permissions.php` to older apps.
- The 2FA verify url (`TwoFactorProcessorInterface::getUrlByType()`) can be a string url. The return
type is now `array|string|null`; custom callers of `getUrlByType()` must handle strings.

### Changed
- Requires CakePHP `^5.4` (PHP `>=8.2` unchanged).
- `cakephp/authentication` `^3.3` moved from require-dev/suggest to `require`, the authenticators,
identifiers, 2FA and social login depend on it.
- Dev dependencies curated: no more `@stable` constraints, minimum versions raised to the ones the
test suite passes with on PHP 8.2 (`--prefer-lowest`) up to 8.5. PHPUnit `^11.5 || ^12.5`,
PHPStan `^2.3`, Psalm `^6.20` (`psalm/phar` in require-dev, `stan-setup` script removed),
`robthree/twofactorauth` `^3.0.1`, `endroid/qr-code` `^6.0`.
- Removed the unused `yubico/u2flib-server` dev dependency (U2F is deprecated).
- `suggest` lists the optional packages needed by each feature.
- Static analysis: PHPStan level 8 (was 6), with stale path ignores reported. Psalm level 2 set
explicitly, without unused code detection and `ClassMustBeFinal` (plugin classes are extension
points) and without the blanket `info` downgrades, baseline reduced from 143 to 36 entries. PHPCS
warnings fail `composer cs-check` (no more `-n`).
- Invalid class names fail with an `InvalidArgumentException` instead of a `TypeError`: a
`FormAuthenticator` `baseClassName` that is not an authenticator, a two factor processor class that
does not implement `TwoFactorProcessorInterface`, a social provider `className` of the wrong type.
- The default `resetOneTimePasswordAuthenticator` permission uses `OTPRule` instead of a closure. It
compares the user id as string, so users with integer ids can now reset their own one time password
authenticator. The old closure compared a string with an integer and always denied them. Other users
are still denied.

### Deprecated
- The `LinkedIn` (LinkedIn retired the API, use `linkedInOpenIDConnect`), `Instagram` (Basic Display
API shut down), `Pinterest` (API v1 fields) and `Tumblr` (crc32 user id) social mappers emit a
deprecation warning and will be removed in 12.0.
- `CakeDC\Auth\Plugin` extends `CakeDC\Auth\AuthPlugin` and is deprecated, load the plugin with
`AuthPlugin` (or by its name `CakeDC/Auth`).

### Fixed
- The `LinkedInOpenIDConnect` and `Keycloak` mappers only treat a JSON boolean `true` as a validated
email. A string claim like `"false"` was cast to `true` before.
- `ReCaptchaTrait::validateReCaptchaFromRequest()` treats a missing or empty
`g-recaptcha-response` as an invalid captcha (returns `false`) instead of passing `null` to the
non-nullable `validateReCaptcha(string ...)`, which raised a `TypeError` (HTTP 500). A tokenless
request — e.g. a programmatic JSON client — now fails the reCaptcha check cleanly.
- The `/auth/{provider}` social login route connected by the plugin used the CakePHP 4 `:provider`
placeholder and never matched on CakePHP 5.
- The `Auth.Authorization.checked` event of `SuperuserPolicy` had a null `role` for entity identities.
- `TwoFactorMiddleware` raised a `TypeError` when the request had no authentication result, it now
passes the request on.
- `ServiceFactory::createFromRequest()` raised a `TypeError` without a `provider` route param, it now
throws a `NotFoundException`.
- The provider `openid` settings (`url`, `baseUrl`, `issuer`, `nonce`, `cache`) reach the
`OpenIDConnectService` built by `ServiceFactory`, `ProviderConfig` dropped them before.
- `RuleRegistry` throws a `JsonException` for rule options that can not be encoded, `md5()` raised a
`TypeError` before.
- The Rbac match reason logged `result = 1` or `result = ` (empty), it now logs `true` or `false`.
- `BaseTestTrait` stored the logged in user under `Auth.User`, so with the `Auth` session key of
cakephp/authentication the identity had no `role` and `RbacPolicy` checked the default role. The
user is now stored at `Auth.Authenticators.Session.sessionKey` (`Auth` by default).
- `BaseTestTrait::testPermissions()` uses a `#[DataProvider]` attribute (PHPUnit 12 ignores the docblock
annotation), returns `void` instead of failing with a missing `array` return, skips empty CSV lines,
and a row without the `Response Contains` column no longer raises a `TypeError`: as for an empty
column, the response body must then be empty. The `method` and `Ajax?` columns are case-insensitive,
`POST` ran a GET request before. The `provider()` method of the test class must be static.
- A partial `OAuth.providers.keycloak.mapFields` replaced the whole Keycloak field map, losing `id`,
`roles` and `validated`, so the `rolesMap` check let every user in. The configured fields are now
merged over the mapper fields.
- The Keycloak `rolesMap` was only read from `OAuth.providers.keycloak`, so a provider alias with
`mapper => Keycloak::class` ignored its own roles map. `ProviderConfig` now keeps the provider
`rolesMap` and `MapUser` passes it to the mapper.
- `OneTimeTokenAuthenticator` treats a token array that is not a flat list of strings as a missing
token, instead of joining it with an "Array to string conversion" warning.

## [11.0.0] - 2026-08-22
### Changed
- Requires CakePHP `^5.3` and PHP `>=8.2`.
- PHPUnit `^10.5 || ^11.1 || ^12.5` and PHPStan 2 for development, tests updated and PHPUnit notices
and deprecations fixed.
- Identifiers are configured per authenticator (`identifier` option) instead of with
`AuthenticationService::loadIdentifier()`, see the Authentication documentation.

### Added
- `CakeDC\Auth\AuthPlugin` plugin class, as expected by CakePHP 5.3. `CakeDC\Auth\Plugin` is kept.
- `Auth.Rbac.checked` and `Auth.Authorization.checked` events from `Rbac` and `SuperuserPolicy`,
enabled with `CakeDC/Auth.emitEvents`.
- `U2FProcessor` two factor processor, deprecated: use Webauthn instead.

## [10.1.4] - 2025-09-26
- Github social login

## [10.1.3] - 2025-03-07
- Callbacks can be used for `bypassAuth` in permissions.
- Fixed deprecations in tests.

## [10.1.2] - 2025-03-06
- Two factor authentication errors keep the previous exception.

## [10.0.0] - 2024-02-09
- Two factor processors introduced. Prvided way to add new two factor processors on client level. CakePHP 5.0 version.

Expand Down
Loading
Loading