51 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			51 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
 | 
						|
namespace App\Providers;
 | 
						|
 | 
						|
use App\Models\PersonalAccessToken;
 | 
						|
use Illuminate\Support\Facades\Event;
 | 
						|
use Illuminate\Support\Facades\Http;
 | 
						|
use Illuminate\Support\ServiceProvider;
 | 
						|
use Illuminate\Validation\Rules\Password;
 | 
						|
use Laravel\Sanctum\Sanctum;
 | 
						|
 | 
						|
class AppServiceProvider extends ServiceProvider
 | 
						|
{
 | 
						|
    public function register(): void
 | 
						|
    {
 | 
						|
        if ($this->app->environment('local')) {
 | 
						|
            $this->app->register(\Laravel\Telescope\TelescopeServiceProvider::class);
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    public function boot(): void
 | 
						|
    {
 | 
						|
        Event::listen(function (\SocialiteProviders\Manager\SocialiteWasCalled $event) {
 | 
						|
            $event->extendSocialite('authentik', \SocialiteProviders\Authentik\Provider::class);
 | 
						|
        });
 | 
						|
        Sanctum::usePersonalAccessTokenModel(PersonalAccessToken::class);
 | 
						|
 | 
						|
        Password::defaults(function () {
 | 
						|
            $rule = Password::min(8);
 | 
						|
 | 
						|
            return $this->app->isProduction()
 | 
						|
                ? $rule->mixedCase()->letters()->numbers()->symbols()
 | 
						|
                : $rule;
 | 
						|
        });
 | 
						|
 | 
						|
        Http::macro('github', function (string $api_url, ?string $github_access_token = null) {
 | 
						|
            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);
 | 
						|
            } else {
 | 
						|
                return Http::withHeaders([
 | 
						|
                    'Accept' => 'application/vnd.github.v3+json',
 | 
						|
                ])->baseUrl($api_url);
 | 
						|
            }
 | 
						|
        });
 | 
						|
    }
 | 
						|
}
 |