2023-03-17 14:33:48 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Providers;
|
|
|
|
|
|
2024-06-10 20:43:34 +00:00
|
|
|
use App\Models\PersonalAccessToken;
|
2024-12-13 11:12:52 +00:00
|
|
|
use Illuminate\Support\Facades\Event;
|
2023-05-30 13:52:17 +00:00
|
|
|
use Illuminate\Support\Facades\Http;
|
2023-03-17 14:33:48 +00:00
|
|
|
use Illuminate\Support\ServiceProvider;
|
2024-10-28 20:57:00 +00:00
|
|
|
use Illuminate\Validation\Rules\Password;
|
2023-10-18 16:02:09 +00:00
|
|
|
use Laravel\Sanctum\Sanctum;
|
2025-01-07 13:52:08 +00:00
|
|
|
use Laravel\Telescope\TelescopeServiceProvider;
|
|
|
|
|
use SocialiteProviders\Authentik\Provider;
|
|
|
|
|
use SocialiteProviders\Manager\SocialiteWasCalled;
|
2023-03-17 14:33:48 +00:00
|
|
|
|
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
|
|
|
{
|
2024-11-02 11:09:33 +00:00
|
|
|
public function register(): void
|
|
|
|
|
{
|
|
|
|
|
if ($this->app->environment('local')) {
|
2025-01-07 13:52:08 +00:00
|
|
|
$this->app->register(TelescopeServiceProvider::class);
|
2024-11-02 11:09:33 +00:00
|
|
|
}
|
|
|
|
|
}
|
2023-03-17 14:33:48 +00:00
|
|
|
|
|
|
|
|
public function boot(): void
|
|
|
|
|
{
|
2025-01-07 13:52:08 +00:00
|
|
|
Event::listen(function (SocialiteWasCalled $socialiteWasCalled) {
|
|
|
|
|
$socialiteWasCalled->extendSocialite('authentik', Provider::class);
|
2024-12-13 11:12:52 +00:00
|
|
|
});
|
2023-10-18 16:02:09 +00:00
|
|
|
Sanctum::usePersonalAccessTokenModel(PersonalAccessToken::class);
|
2024-07-12 10:59:53 +00:00
|
|
|
|
2024-10-28 20:57:00 +00:00
|
|
|
Password::defaults(function () {
|
2025-01-07 13:52:08 +00:00
|
|
|
$password = Password::min(8);
|
2024-10-28 20:57:00 +00:00
|
|
|
|
|
|
|
|
return $this->app->isProduction()
|
2025-01-07 13:52:08 +00:00
|
|
|
? $password->mixedCase()->letters()->numbers()->symbols()
|
|
|
|
|
: $password;
|
2024-10-28 20:57:00 +00:00
|
|
|
});
|
|
|
|
|
|
2024-06-10 20:43:34 +00:00
|
|
|
Http::macro('github', function (string $api_url, ?string $github_access_token = null) {
|
2023-06-13 13:01:11 +00:00
|
|
|
if ($github_access_token) {
|
|
|
|
|
return Http::withHeaders([
|
|
|
|
|
'X-GitHub-Api-Version' => '2022-11-28',
|
|
|
|
|
'Accept' => 'application/vnd.github.v3+json',
|
|
|
|
|
'Authorization' => "Bearer $github_access_token",
|
|
|
|
|
])->baseUrl($api_url);
|
|
|
|
|
}
|
2025-01-07 13:52:08 +00:00
|
|
|
|
|
|
|
|
return Http::withHeaders([
|
|
|
|
|
'Accept' => 'application/vnd.github.v3+json',
|
|
|
|
|
])->baseUrl($api_url);
|
2023-05-30 13:52:17 +00:00
|
|
|
});
|
2023-03-17 14:33:48 +00:00
|
|
|
}
|
|
|
|
|
}
|