e4se / laravel-telegram-oidc
OpenID Telegram Connect OAuth2 Provider for Laravel Socialite
Requires
- php: ^8.1
- ext-json: *
- firebase/php-jwt: ^6.4|^7.0
- illuminate/http: ^9.0 | ^10.0 | ^11.0 | ^12.0
- illuminate/support: ^9.0 | ^10.0 | ^11.0 | ^12.0
- socialiteproviders/manager: ^4.0
README
Installation & Basic Usage
composer require e4se/laravel-telegram-oidc
Please see the Base Installation Guide, then follow the provider specific instructions below.
Add configuration to config/services.php
'telegram-oidc' => [ 'client_id' => env('TELEGRAM_OIDC_CLIENT_ID'), 'client_secret' => env('TELEGRAM_OIDC_CLIENT_SECRET'), 'redirect' => env('TELEGRAM_OIDC_REDIRECT_URI') ],
Add provider event listener
Configure the package's listener to listen for SocialiteWasCalled events.
Laravel 11+
In Laravel 11, the default EventServiceProvider provider was removed. Instead, add the listener using the listen method on the Event facade, in your AppServiceProvider boot method.
Event::listen(function (\SocialiteProviders\Manager\SocialiteWasCalled $event) { $event->extendSocialite('telegram-oidc', \SocialiteProviders\TelegramOIDC\Provider::class); });
Laravel 10 or below
Add the event to your listen[] array in app/Providers/EventServiceProvider. See the Base Installation Guide for detailed instructions.
protected $listen = [ \SocialiteProviders\Manager\SocialiteWasCalled::class => [ // ... other providers \SocialiteProviders\TelegramOIDC\TelegramOIDCExtendSocialite::class.'@handle', ], ];
Usage
You should now be able to use the provider like you would regularly use Socialite (assuming you have the facade installed):
return Socialite::driver('telegram-oidc')->redirect();
Returned User fields
idnamenicknameavatar
More fields are available under the user subkey:
$user = Socialite::driver('telegram-oidc')->user(); $phone_number = $user->user['phone_number'];
Customizing the scopes
You may extend the default scopes (openid profile) by adding a scopes option to your OIDC service configuration and separate multiple scopes with a space:
'telegram-oidc' => [ 'client_id' => env('TELEGRAM_OIDC_CLIENT_ID'), 'client_secret' => env('TELEGRAM_OIDC_CLIENT_SECRET'), 'redirect' => env('TELEGRAM_OIDC_REDIRECT_URI'), 'scopes' => 'phone', // or 'scopes' => env('TELEGRAM_OIDC_SCOPES'), ],
Based on the work of Kovah