routmoute/routmoute-discord-bundle
Composer 安装命令:
composer require routmoute/routmoute-discord-bundle
包简介
This bundle is simple access to discord OAuth & API for Symfony 5
README 文档
README
Manual Installation
Make sure Composer is installed globally, as explained in the installation chapter of the Composer documentation.
Step 1: Create configuration file
Create configuration file config/packages/routmoute_discord.yaml and modify scopes if you want
// config/packages/routmoute_discord.yaml routmoute_discord: oauth: client_id: '%env(ROUTMOUTE_DISCORD_CLIENT_ID)%' client_secret: '%env(ROUTMOUTE_DISCORD_CLIENT_SECRET)%' scope: - identify - email api: bot_token: '%env(ROUTMOUTE_DISCORD_BOT_TOKEN)%'
Step 2: Download the Bundle
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
composer require routmoute/routmoute-discord-bundle
Configuration
Step 1: Create your Discord Application
- Go to https://discord.com/developers/applications
- Create a New Application
- Copy
CLIENT IDandCLIENT SECRETfor next step - Go to
OAuth2Tab - Add Redirect
https://yourDomain.domain/receiveDiscord - Go to Bot Tab and copy
TOKENfor next step
Step 2: Create your env variables
Add this environments vars in your .env file.
ROUTMOUTE_DISCORD_CLIENT_ID=YourClientId
ROUTMOUTE_DISCORD_CLIENT_SECRET=YourClientSecret
ROUTMOUTE_DISCORD_BOT_TOKEN=YourBotToken
Usage (for Symfony 5)
Discord OAuth
Step 1: Create Controller in your App
Create Controller, for exemple src/Controller/DiscordOAuthController.php
// src/Controller/DiscordOAuthController.php <?php namespace App\Controller; use Routmoute\Bundle\RoutmouteDiscordBundle\Service\RoutmouteDiscordOAuthService; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; class DiscordOAuthController extends AbstractController { /** * @Route("/connectToDiscord", name="routmoute_discord_redirect", methods="GET") */ public function redirectToDiscord(RoutmouteDiscordOAuthService $oAuthService, UrlGeneratorInterface $urlGenerator): RedirectResponse { $redirectUrl = $urlGenerator->generate('routmoute_discord_receiver', [], UrlGeneratorInterface::ABSOLUTE_URL); return new RedirectResponse($oAuthService->getRedirectDiscordUrl($redirectUrl)); } /** * @Route("/receiveDiscord", name="routmoute_discord_receiver", methods="GET") */ public function receiveFromDiscordAuthorize(Request $request, RoutmouteDiscordOAuthService $oAuthService, UrlGeneratorInterface $urlGenerator): RedirectResponse { $redirectUrl = $urlGenerator->generate('routmoute_discord_receiver', [], UrlGeneratorInterface::ABSOLUTE_URL); $userData = $oAuthService->getUserData($request, $redirectUrl); // TODO: Process userData and change path_to_redirect return $this->redirectToRoute('path_to_redirect'); } }
Step 2: Create your redirect button
Create a button in your frontend that redirect to routmoute_discord_redirect path.
for example, in twig template:
<a href="{{ path('routmoute_discord_redirect') }}"> <button type="button">Link my account with discord</button> </a>
Discord API (Bot)
Example usage in Controller:
<?php namespace App\Controller; use Routmoute\Bundle\RoutmouteDiscordBundle\Service\RoutmouteDiscordApiService; class MyController extends AbstractController { public function index(RoutmouteDiscordApiService $discordAPI) { $discordId = 'theUserDiscordId'; $userInfos = $discordAPI->getUserFromDiscordId($discordId); $userInfos["id"]; $userInfos["username"]; $userInfos["discriminator"]; $userInfos["avatar"]; } }
https://discord.com/developers/docs/resources/user
Parameters
client_id
Required
The CLIENT ID provided by discord
client_secret
Required
The CLIENT SECRET provided by discord
scope
Required The Discord API scopes - https://discord.com/developers/docs/topics/oauth2#shared-resources
identify- discordId, avatar, username, discriminatoremail- email- ...
bot_token
Required
The Bot TOKEN provided by discord
routmoute/routmoute-discord-bundle 适用场景与选型建议
routmoute/routmoute-discord-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 584 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 02 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「rest」 「api」 「Authentication」 「oauth」 「oauth2」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 routmoute/routmoute-discord-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 routmoute/routmoute-discord-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 routmoute/routmoute-discord-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The bundle for easy using json-rpc api on your project
A PSR-7 compatible library for making CRUD API endpoints
Api bundle
Bundle Symfony DaplosBundle
A Flickr wrapper to allow you to call the Flickr api with Guzzle as the backend.Goal is to have 100% Flickr api coverage rather than just upload/display photos (currently at 23%).
BlockCypher's PHP SDK for REST API
统计信息
- 总下载量: 584
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-02-12