Looking to hire Laravel developers? Try LaraJobs

laravel-telegram-auth maintained by akxz

Description
Laravel Telegram Login Auth
Author
Last update
2020/09/29 08:56 (dev-master)
License
Links
Downloads
14
Tags

Comments
comments powered by Disqus

Telegram Login for Laravel 5-8

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('/');
    }
}