akxz/laravel-telegram-auth

Laravel Telegram Login Auth

dev-master 2020-09-29 06:56 UTC

This package is not auto-updated.

Last update: 2025-07-03 05:52:13 UTC


README

License Latest Stable Version Total Downloads

This package is a Laravel 5-8 service provider which provides support for Laravel Login and is very easy to integrate with any project that requires Telegram authentication.

Installation

Require this package with composer.

composer require akxz/laravel-telegram-login-auth

Laravel >=5.5 uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider.

Copy the package config to your local config with the publish command:

php artisan vendor:publish --provider="Akxz\LaravelTelegramLoginAuth\TelegramLoginServiceProvider"

Usage example

Setup information Telegram Login Widget

In routes/web.php: for Laravel 5-7:

Route::get('auth/telegram/callback', 'AuthController@handleTelegramCallback')->name('auth.telegram.handle');

for Laravel 8:

use App\Http\Controllers\AuthController;

Route::get('auth/telegram/callback', [AuthController::class, 'handleTelegramCallback']);

In AuthController:

namespace App\Http\Controllers;

use Akxz\LaravelTelegramLoginAuth\TelegramLoginAuth;

class AuthController extends Controller
{
    /**
     * @var TelegramLoginAuth
     */
    protected $telegram;

    /**
     * AuthController constructor.
     *
     * @param TelegramLoginAuth $telegram
     */
    public function __construct(TelegramLoginAuth $telegram)
    {
        $this->telegram = $telegram;
    }

    /**
     * Get user info and log in (hypothetically)
     *
     * @return \Illuminate\Routing\Redirector|\Illuminate\Http\RedirectResponse
     */
    public function handleTelegramCallback()
    {
        if ($this->telegram->validate()) {
            $user = $this->telegram->user();

            //
        }

        return redirect('/');
    }
}