diff --git a/.gitignore b/.gitignore index dc838281..aa54f070 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ /vendor/ ###< symfony/framework-bundle ### /book/ +.docker/ ###> phpunit/phpunit ### /phpunit.xml diff --git a/docs/img/githubapp1.png b/docs/img/githubapp1.png index e0bc511c..32b35f14 100644 Binary files a/docs/img/githubapp1.png and b/docs/img/githubapp1.png differ diff --git a/docs/img/githubapp4.png b/docs/img/githubapp4.png new file mode 100644 index 00000000..91da3638 Binary files /dev/null and b/docs/img/githubapp4.png differ diff --git a/docs/oauth2.md b/docs/oauth2.md index d5f3a07a..44cbce4c 100644 --- a/docs/oauth2.md +++ b/docs/oauth2.md @@ -12,7 +12,7 @@ Table of content ## Base configuration reference -To enable OAuth2 integrations you need to add following configuration +To enable OAuth2 integrations, you need to add the following configuration ```yml packeton: integrations: @@ -162,9 +162,9 @@ https://example.com/oauth2/{alias}/check A group webhooks needed for synchronization a new package. They are triggered by events that occur across all projects in the group. -This feature enabled only for Premium / EE / Gold paid plan, but it can be replaced with GitLab Packagist Integration +This feature is enabled only for Premium / EE / Gold paid plan, but it can be replaced with GitLab Packagist Integration -You must manually setup this integration. +You must manually set up this integration. [![Gitlab](img/gitlab.png)](img/gitlab.png) diff --git a/docs/oauth2/github-oauth.md b/docs/oauth2/github-oauth.md index 72578c92..34b4fcf2 100644 --- a/docs/oauth2/github-oauth.md +++ b/docs/oauth2/github-oauth.md @@ -6,7 +6,7 @@ Use the packeton host as "Callback URL / Redirect URL". For example `https://pac [![Groups](../img/github-oauth2.png)](../img/github-oauth2.png) -Use obtained `clinent_id`, `client_secret` to create configuration in yaml. For docker installation you may use `config.yaml` file in docker volume. +Use obtained `client_id`, `client_secret` to create configuration in yaml. For docker installation you may use `config.yaml` file in docker volume. ```yaml packeton: @@ -19,8 +19,8 @@ packeton: client_secret: 'xxx' ``` -Now go to Packeton integration page and click Install Integration. You will see list of available integrations and its Redirect Urls +Now go to Packeton integration page and click Install Integration. You will see a list of available integrations and its Redirect Urls -Click to Connect to set up oauth2 credentials +Click to `Connect` to set up oauth2 credentials. [![Groups](../img/github-connect.png)](../img/github-connect.png) diff --git a/docs/oauth2/githubapp.md b/docs/oauth2/githubapp.md index bb809700..c792d22b 100644 --- a/docs/oauth2/githubapp.md +++ b/docs/oauth2/githubapp.md @@ -1,25 +1,27 @@ # GitHub App Integration -GitHub App Integration is alternative of GitHub OAuth2. To create GitHub go to -Settings / Developer settings / GitHub Apps and click New GitHub App. - -Use the next "Callback URL / Redirect URL". - -Redirect Urls: +GitHub App Integration is alternative of GitHub OAuth2. +To create GitHub go to: Settings / Developer settings / GitHub Apps and click `New GitHub App`. +- Enter a GitHub App name: Private Packeton. +- Enter a homepage url: https://packeton.example.com for example. +- Click `Add Callback URL` and use the next "Callback URL / Redirect URL". ``` -https://example.com/oauth2/{alias}/install -https://example.com/oauth2/{alias}/check +https://packeton.example.com/oauth2/{alias}/install +https://packeton.example.com/oauth2/{alias}/check ``` -The webhooks URL maybe any. We don't use it and setup webhooks per repository or choice organization. +- Uncheck webhook active checkbox + +Select Repository permissions: +- Content: read-only +- Webhooks: read-write +- Metadata: read-only (already selected) +- Pull requests read-write -Select Permissions: -- Webhooks read-write (Repository permissions) -- Metadata (Repository permissions) -- Pull requests read-write (Repository permissions) -- Webhooks read-write (Organization permissions) -- Members read (Organization permissions) - optional +Select Organization permissions: +- Webhooks: read-write +- Members: read (optional) [![Img](../img/githubapp1.png)](../img/githubapp1.png) @@ -40,15 +42,20 @@ packeton: app_id: 340120 ``` -When you must install GitHub App in you Github Account. Go to public App page, like `https://github.com/apps/{name}` -and click configure. Select you organization or own account. +When you must install GitHub App in your GitHub Account. + +Go to public App page, like `https://github.com/apps/{name}` and click configure. +Select your organization or own account. [![Img](../img/githubapp2.png)](../img/githubapp2.png) After install you will see `installation_id` on URL address. For example `https://github.com/settings/installations/38069000` -Now go to Packeton integration page and click Install Integration. When click to Connect under you githubapp configuration. +Now go to Packeton `integration` page and click `Install Integration`. +When click to `Connect` under you `github` configuration. + +[![Img](../img/githubapp4.png)](../img/githubapp4.png) -To finish setup Go to Packeton integration view page / Settings and provider `installation_id` in the form +To finish setup Go to Packeton `integration` view page / Settings and provider `installation_id` in the form [![Img](../img/githubapp3.png)](../img/githubapp3.png) diff --git a/src/EventListener/AuditLoginListener.php b/src/EventListener/AuditLoginListener.php index 9f0eca7e..2e2bf589 100644 --- a/src/EventListener/AuditLoginListener.php +++ b/src/EventListener/AuditLoginListener.php @@ -38,8 +38,10 @@ public function onLoginFailure(LoginFailureEvent $event): void } try { - $username = $event->getPassport()?->getUser()->getUserIdentifier(); - } catch (\Throwable $e) { + if(!$username = $event->getPassport()?->getUser()->getUserIdentifier()) { + return; + } + } catch (\Throwable) { return; } diff --git a/src/Integrations/Github/GitHubIntegration.php b/src/Integrations/Github/GitHubIntegration.php index 1a7cf47c..dbc1d976 100644 --- a/src/Integrations/Github/GitHubIntegration.php +++ b/src/Integrations/Github/GitHubIntegration.php @@ -432,7 +432,7 @@ public function fetchUser(Request|array $requestOrToken, array $options = [], ar $response = $response->toArray(); $response['user_name'] = $response['login'] ?? null; - $response['user_identifier'] = $response['email']; + $response['user_identifier'] = $response['email'] ?? $response['login']; $response['external_id'] = isset($response['id']) ? $this->getConfig()->getName() . ':' . $response['id'] : null; return $response; @@ -520,10 +520,12 @@ protected function getApiHeaders(array $token, array $default = []): array */ public function createUser(array $userData): User { + $email = $userData['email'] ?? (str_contains($userData['user_identifier'], '@') ? $userData['user_identifier'] : $userData['user_identifier'] .'@example.com'); + $user = new User(); $user->setEnabled(true) ->setRoles($this->getConfig()->roles()) - ->setEmail($userData['email']) + ->setEmail($email) ->setUsername($userData['login']) ->setGithubId($userData['external_id'] ?? null) ->generateApiToken(); diff --git a/tests/Functional/Controller/BaseAclControllerTest.php b/tests/Functional/Controller/BaseAclControllerTest.php index 75750ae0..00763e13 100644 --- a/tests/Functional/Controller/BaseAclControllerTest.php +++ b/tests/Functional/Controller/BaseAclControllerTest.php @@ -4,7 +4,7 @@ namespace Packeton\Tests\Functional\Controller; -use Packeton\Tests\Phpunit\PacketonTestTrait; +use Packeton\Tests\Functional\PacketonTestTrait; use PHPUnit\Framework\Attributes\DataProvider; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; diff --git a/tests/Functional/Controller/ProviderControllerTest.php b/tests/Functional/Controller/ProviderControllerTest.php index 1c7eddf2..cbc60ad3 100644 --- a/tests/Functional/Controller/ProviderControllerTest.php +++ b/tests/Functional/Controller/ProviderControllerTest.php @@ -2,7 +2,7 @@ namespace Packeton\Tests\Functional\Controller; -use Packeton\Tests\Phpunit\PacketonTestTrait; +use Packeton\Tests\Functional\PacketonTestTrait; use PHPUnit\Framework\Attributes\DataProvider; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; diff --git a/tests/Phpunit/PacketonTestTrait.php b/tests/Functional/PacketonTestTrait.php similarity index 96% rename from tests/Phpunit/PacketonTestTrait.php rename to tests/Functional/PacketonTestTrait.php index 03f86d7b..1157874f 100644 --- a/tests/Phpunit/PacketonTestTrait.php +++ b/tests/Functional/PacketonTestTrait.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Packeton\Tests\Phpunit; +namespace Packeton\Tests\Functional; use Doctrine\Persistence\ManagerRegistry; use Packeton\Entity\User; diff --git a/tests/Phpunit/ErrorHandler.php b/tests/PHPUnitOverride/ErrorHandler.php similarity index 100% rename from tests/Phpunit/ErrorHandler.php rename to tests/PHPUnitOverride/ErrorHandler.php diff --git a/tests/phpunit b/tests/phpunit index 5a58215a..e224d034 100755 --- a/tests/phpunit +++ b/tests/phpunit @@ -1,6 +1,6 @@ #!/usr/bin/env php