在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):kawax/socialite-mastodon开源软件地址(OpenSource Url):https://github.com/kawax/socialite-mastodon开源编程语言(OpenSource Language):PHP 100.0%开源软件介绍(OpenSource Introduction):Socialite for Mastodonhttps://github.com/tootsuite/mastodon Requirements
Install
config/services.php
.env
Create App and get the client_id & client_secret
UsageUse one instanceroutes/web.php
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 exampleMastodon 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);
} LICENCEMIT |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论