Giter Site home page Giter Site logo

telegramsocialite's Introduction

Style Status Latest Stable Version

TelegramSocialite

Telegram provider for Laravel Socialite

Install

composer require max13/telegram-socialite

Configuration

First of all, you must create a bot by contacting @BotFather (https://core.telegram.org/bots#6-botfather)

Don't forget to set your website URL using /setdomain

Then, as required by Laravel Socialite, you need to add your bot's configuration to config/services.php. The bot username is required, client_id must be null. The provider will also ask permission for the bot to write to the user.

'telegram' => [
    'client_id' => null,
    'client_secret' => env('TELEGRAM_TOKEN'),
    'redirect' => '/login/telegram/callback',
]

Usage

Now, Telegram is technically using OAuth, but not the usual workflow.

First or all, you must add a javascript to your page, anywhere you want (in the <head> or bottom of page) with this snippet:

{!! Socialite::driver('telegram')->getScript() !!}

You also must call _TWidgetLogin.auth() on click on your login button, which will open a popup showing the Telegram OAuth access request. Because of browser's security, you can't automatically call this, it must be called as a result of a user's action.

If the user accept the access request, the browser is redirected to your services.telegram.redirect config key and you will have access to the logged-in user data the classic Socialite way:

Socialite::driver('telegram')->user();

If the user declines, an InvalidArgumentException exception will be thrown.

Using Socialite::driver('telegram')->redirect() will abort the connection with a 404 error.

If you want to see the Telegram Widget configuration page: https://core.telegram.org/widgets/login

Issues

https://github.com/Max13/TelegramSocialite/issues

telegramsocialite's People

Contributors

max13 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

telegramsocialite's Issues

undefined index

ErrorException
Undefined index: last_name

    protected function mapUserToObject(array $user)

    {

        return (new User())->setRaw($user)->map([

            'id'        => $user['id'],

            'nickname'  => $user['username'],

            'name'      => trim($user['first_name'].' '.$user['last_name']),

            'avatar'    => $user['photo_url'],

        ]);

    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.