-
Notifications
You must be signed in to change notification settings - Fork 0
(feat) rewrite #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ictbeheer
wants to merge
2
commits into
main
Choose a base branch
from
feat/rewrite
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,98 @@ | ||
| # OWC IDP UserData | ||
|
|
||
| This repository contains interfaces for userdata objects to be used by IDP plugins (e.g. DigiD, eHerkenning) | ||
| This package provides common `UserData` and `Session` classes for identity provider (IDP) plugins such as DigiD, eHerkenning, and eIDAS. | ||
|
|
||
| ## Installation | ||
|
|
||
| Install via Composer: | ||
|
|
||
| ```bash | ||
| composer require owc/idp-userdata | ||
| ``` | ||
|
|
||
| ### Example: Providing User Data via IDP-Specific Filters | ||
|
|
||
| To provide user data to the session classes, use the IDP-specific WordPress filters in your plugin or theme: | ||
|
|
||
| ```php | ||
| use OWC\IdpUserData\DigiDUserData; | ||
|
|
||
| add_filter('owc_digid_is_logged_in', function (bool $isLoggedIn): bool { | ||
| // Your logic to determine if the user is logged in with DigiD | ||
| return true; | ||
| }); | ||
|
|
||
| add_filter('owc_digid_userdata', function (?DigiDUserData $userData): ?DigiDUserData { | ||
| return new DigiDUserData([ | ||
| 'bsn' => '123456789', | ||
| ]); | ||
| }); | ||
| ``` | ||
|
|
||
| ### Example: Providing User Data via Generic Filter (with switch) | ||
|
|
||
| You can also use the generic filters and handle multiple IDPs with a switch statement: | ||
|
|
||
| ```php | ||
|
|
||
| use OWC\IdpUserData\DigiDUserData; | ||
| use OWC\IdpUserData\eHerkenningUserData; | ||
| use OWC\IdpUserData\eIDASUserData; | ||
| use OWC\IdpUserData\IdpSession; | ||
| use OWC\IdpUserData\Idp; | ||
| use OWC\IdpUserData\UserData; | ||
|
|
||
|
|
||
| add_filter('owc_idp_is_logged_in', function (bool $isLoggedIn, string $idp): bool { | ||
| switch ($idp) { | ||
| case Idp::DIGID: | ||
| // Your logic for DigiD | ||
| return true; | ||
| case Idp::EHERKENNING: | ||
| // Your logic for eHerkenning | ||
| return false; | ||
| case Idp::EIDAS: | ||
| // Your logic for eIDAS | ||
| return false; | ||
| default: | ||
| return $isLoggedIn; | ||
| } | ||
| }, 10, 2); | ||
|
|
||
| add_filter('owc_idp_userdata', function (?UserData $userData, string $idp): ?UserData { | ||
| switch ($idp) { | ||
| case Idp::DIGID: | ||
| return new DigiDUserData([ | ||
| 'bsn' => '123456789', | ||
| ]); | ||
| case Idp::EHERKENNING: | ||
| return new eHerkenningUserData([ | ||
| 'kvk' => '987654321', | ||
| 'rsin' => '123456789', | ||
| 'vestigingsnummer' => '001', | ||
| 'bsn' => null, | ||
| ]); | ||
| case Idp::EIDAS: | ||
| return new eIDASUserData([ | ||
| 'bsn' => '555555555', | ||
| ]); | ||
| default: | ||
| return $userData; | ||
| } | ||
| }, 10, 2); | ||
| ``` | ||
|
|
||
| ### Example: Getting User Data | ||
|
|
||
| ```php | ||
| use OWC\IdpUserData\DigiDSession; | ||
| use OWC\IdpUserData\DigiDUserData; | ||
|
|
||
| if (DigiDSession::isLoggedIn()) { | ||
| $userData = DigiDSession::getUserData(); | ||
| if ($userData instanceof DigiDUserData) { | ||
| $bsn = $userData->getBsn(); | ||
| // ... | ||
| } | ||
| } | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <?php | ||
|
|
||
| namespace OWC\IdpUserData; | ||
|
|
||
| class DigiDUserData extends UserData | ||
| { | ||
| protected string $bsn; | ||
|
|
||
| public function getBsn(): string | ||
| { | ||
| return $this->bsn; | ||
| } | ||
|
|
||
| } |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <?php | ||
|
|
||
| namespace OWC\IdpUserData; | ||
|
|
||
| // TODO: Convert to enums if PHP 8.1+ is supported | ||
| class Idp { | ||
| public const DIGID = 'digid'; | ||
| public const EHERKENNING = 'eherkenning'; | ||
| public const EIDAS = 'eidas'; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| <?php | ||
|
|
||
| namespace OWC\IdpUserData; | ||
|
|
||
| abstract class UserData | ||
| { | ||
| protected array $data; | ||
|
|
||
| public function __construct(array $data) { | ||
| $classVars = get_class_vars(static::class); | ||
|
|
||
| $data = wp_parse_args($data, $classVars); | ||
| $data = wp_array_slice_assoc($data, array_keys($classVars)); | ||
|
|
||
| foreach ($data as $key => $value) { | ||
| $this->$key = $value; | ||
| } | ||
| } | ||
| } |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| <?php | ||
|
|
||
| namespace OWC\IdpUserData; | ||
|
|
||
| class eHerkenningUserdata extends UserData | ||
| { | ||
| protected string $kvk; | ||
|
|
||
| protected ?string $rsin = null; | ||
|
|
||
| protected ?string $vestigingsnummer = null; | ||
|
|
||
| protected ?string $bsn = null; | ||
|
|
||
| public function getKvk(): string | ||
| { | ||
| return $this->kvk; | ||
| } | ||
|
|
||
| public function getBsn(): ?string | ||
| { | ||
| return $this->bsn; | ||
| } | ||
|
|
||
| public function getRsin(): ?string { | ||
| return $this->rsin; | ||
| } | ||
|
|
||
| public function getVestigingsnummer(): ?string { | ||
| return $this->vestigingsnummer; | ||
| } | ||
| } |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace OWC\IdpUserData; | ||
|
|
||
| class eIDASUserData extends UserData | ||
| { | ||
| protected string $bsn; | ||
|
|
||
| public function getBsn(): string { | ||
| return $this->bsn; | ||
| } | ||
| } |
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!