• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

kawax/socialite-mastodon

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

kawax/socialite-mastodon

开源软件地址(OpenSource Url):

https://github.com/kawax/socialite-mastodon

开源编程语言(OpenSource Language):

PHP 100.0%

开源软件介绍(OpenSource Introduction):

Socialite for Mastodon

https://github.com/tootsuite/mastodon

Requirements

  • PHP >= 7.2

Install

composer require revolution/socialite-mastodon

config/services.php

    'mastodon' => [
        'domain'        => env('MASTODON_DOMAIN'),
        'client_id'     => env('MASTODON_ID'),
        'client_secret' => env('MASTODON_SECRET'),
        'redirect'      => env('MASTODON_REDIRECT'),
        //'read', 'write', 'follow'
        'scope'         => ['read'],
    ],

.env

MASTODON_DOMAIN=https://mastodon.social
MASTODON_ID=
MASTODON_SECRET=
MASTODON_REDIRECT=https://example.com/callback

Create App and get the client_id & client_secret

  1. Go to your Mastodon's user preferences page.
  2. Go to development page.
  3. Create new application.
  4. Get Client key and Client secret

Usage

Use one instance

routes/web.php

Route::get('/', 'MastodonController@index');
Route::get('callback', 'MastodonController@callback');

MastodonController

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Socialite;

class MastodonController extends Controller
{
    public function index()
    {
        return Socialite::driver('mastodon')->redirect();
    }

    public function callback()
    {
        $user = Socialite::driver('mastodon')->user();
        dd($user);
    }
}

Set scopes

return Socialite::driver('mastodon')
           ->setScopes(config('services.mastodon.scope', ['read']))
           ->redirect();

Customize domain example

Mastodon API for Laravel https://github.com/kawax/laravel-mastodon-api

    public function login(Request $request)
    {
        //input domain by user
        $domain = $request->input('domain');

        //get app info. domain, client_id, client_secret ...
        //Server is Eloquent Model
        $server = Server::where('domain', $domain)->first();

        if (empty($server)) {
            //create new app
            $info = Mastodon::domain($domain)->createApp('my-app', 'https://example.com/callback', 'read');

            //save app info
            $server = Server::create([
                'domain'        => $domain,
                'client_id'     => $info['client_id'],
                'client_secret' => $info['client_secret'],
            ]);
        }

        //change config
        config(['services.mastodon.domain' => $domain]);
        config(['services.mastodon.client_id' => $server->client_id]);
        config(['services.mastodon.client_secret' => $server->client_secret]);

        session(['mastodon_domain' => $domain]);
        session(['mastodon_server' => $server]);

        return Socialite::driver('mastodon')->redirect();
    }
    
    public function callback()
    {
        $domain = session('mastodon_domain');
        $server = session('mastodon_server');
    
        config(['services.mastodon.domain' => $domain]);
        config(['services.mastodon.client_id' => $server->client_id]);
        config(['services.mastodon.client_secret' => $server->client_secret]);
    
        $user = Socialite::driver('mastodon')->user();
        dd($user);
    }

LICENCE

MIT




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap