fof/github-sponsors
Composer 安装命令:
composer require fof/github-sponsors
包简介
GitHub Sponsors integration for your Flarum forum
关键字:
README 文档
README
A Flarum extension that automatically synchronizes your GitHub Sponsors with Flarum user groups.
Features
- 🔄 Automatic Synchronization: Hourly checks for new and removed sponsors
- 👥 Smart User Matching: Matches sponsors via email and GitHub OAuth login
- 🎯 Flexible Configuration: Works with both user and organization sponsor accounts
- 🔒 Safe Group Management: Only manages users it adds, won't interfere with manually assigned groups
- 📝 Detailed Logging: Tracks all changes in dedicated log files
How It Works
This extension connects your GitHub Sponsors program with your Flarum forum by:
- Fetching Sponsors: Queries GitHub's GraphQL API to retrieve your current sponsors
- Matching Users: Identifies Flarum users by matching:
- Email addresses from GitHub sponsors with Flarum user emails
- GitHub OAuth provider IDs for users who logged in via GitHub
- Managing Groups: Automatically adds sponsors to a designated Flarum group and removes users who are no longer sponsors
- Tracking Changes: Logs all additions and removals to help you monitor the process
Installation
Install with composer:
composer require fof/github-sponsors:"*"
php flarum migrate
php flarum cache:clear
Required: Flarum Scheduler
This extension requires Flarum's scheduler to be set up and running. The extension will automatically check for sponsor updates every hour.
Configuration
After installation, configure the extension in your Flarum admin panel:
1. Create a GitHub Personal Access Token
- Go to GitHub Settings > Tokens
- Click "Generate new token (classic)"
- Give it a descriptive name (e.g., "Flarum Sponsors Sync")
- Select the following scopes:
read:user- Read user profile datauser:email- Read the user email addressread:org- Read organization membership (if syncing an organization)
- Click "Generate token" and copy it
2. Configure the Extension
In your Flarum admin panel, navigate to the GitHub Sponsors extension settings:
- API Token: Paste your GitHub personal access token
- Account Type: Choose "user" or "organization" depending on your sponsor account type
- Login: Enter your GitHub username or organization name
- Group: Select which Flarum group to assign to sponsors
Save the settings, and the extension will start syncing on the next scheduled run.
Usage
Once configured, the extension runs automatically every hour. You can also manually trigger an update:
php flarum fof:github-sponsors:update
Command Options
Dry-Run Mode
Preview what changes would be made without actually applying them:
php flarum fof:github-sponsors:update --dry-run
This is useful for testing your configuration before letting the extension make real changes to your groups.
Verbose Output
Get detailed information about the synchronization process:
php flarum fof:github-sponsors:update -v
Verbose mode shows:
- Configuration details (account type, login, target group)
- All sponsors from GitHub with their IDs and emails
- Matched Flarum users with match method (email or GitHub OAuth)
- Unmatched sponsors who couldn't be linked to Flarum accounts
- Summary of users staying, being added, and being removed
Combine both options for detailed preview:
php flarum fof:github-sponsors:update --dry-run -v
Viewing Logs
Check the synchronization logs:
tail -f storage/logs/fof-github-sponsors.log
Log output includes:
- Number of sponsors found on GitHub
- Number of sponsors matched to Flarum users
- Users added to the group (with
+ #userID username) - Users removed from the group (with
- #userID username) - Any API errors or configuration issues
How User Matching Works
The extension uses two methods to match GitHub sponsors to Flarum users:
- Email Matching: Direct comparison of sponsor email from GitHub with Flarum user emails
- OAuth Matching: For users who logged in via GitHub, matches their GitHub ID with sponsor IDs
This dual approach maximizes the chance of correctly identifying your sponsors.
Important Notes
- The extension only removes the group from users it previously added. It won't affect users who were manually added to the group.
- Users must have either the same email address as their GitHub account OR have logged into Flarum via GitHub OAuth at least once.
- The GitHub API has rate limits. The extension checks once per hour to stay well within these limits.
For Developers: Event System
This extension dispatches events when sponsors are added or removed, allowing other extensions to react to these changes.
Available Events
FoF\GitHubSponsors\Event\SponsorAdded
Dispatched when a user is added to the sponsors group.
Properties:
$user(Flarum\User\User) - The Flarum user who was added$sponsorData(object|null) - GitHub sponsor data including:email- Sponsor's email addressdatabaseId- GitHub user IDlogin- GitHub username- Other fields from the GitHub API
Example listener:
use Flarum\Extend; use FoF\GitHubSponsors\Event\SponsorAdded; return [ (new Extend\Event) ->listen(SponsorAdded::class, function (SponsorAdded $event) { $user = $event->user; $githubId = $event->sponsorData->databaseId ?? null; // Your custom logic here // e.g., send a welcome email, grant additional permissions, etc. }), ];
FoF\GitHubSponsors\Event\SponsorRemoved
Dispatched when a user is removed from the sponsors group (sponsorship ended).
Properties:
$user(Flarum\User\User) - The Flarum user who was removed
Example listener:
use Flarum\Extend; use FoF\GitHubSponsors\Event\SponsorRemoved; return [ (new Extend\Event) ->listen(SponsorRemoved::class, function (SponsorRemoved $event) { $user = $event->user; // Your custom logic here // e.g., send a thank you message, revoke special access, etc. }), ];
Notes on Events
- Events are not dispatched when running with the
--dry-runflag - Events fire after the database changes have been made
- The
SponsorAddedevent includes raw GitHub data for additional context - These events only fire for automated changes, not manual group assignments
Troubleshooting
No sponsors are being synced
- Verify your GitHub token has the correct scopes (
userandread:org) - Check that the account type and login match your GitHub Sponsors account
- Ensure the cron job is running (
schedule:run) - Check logs in
storage/logs/fof-github-sponsors.log
Some sponsors aren't being matched
- Ensure sponsors have public email addresses on their GitHub profiles
- Alternatively, have them log into your Flarum forum using GitHub OAuth at least once
Updating
composer update fof/github-sponsors php flarum migrate php flarum cache:clear
An extension by FriendsOfFlarum.
fof/github-sponsors 适用场景与选型建议
fof/github-sponsors 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 690 次下载、GitHub Stars 达 3, 最近一次更新时间为 2019 年 12 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「flarum」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 fof/github-sponsors 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 fof/github-sponsors 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 fof/github-sponsors 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Adds more BBCode
Output of discussions lists in form of cards
Allow users to log in with QQ
A headless CLI performance benchmarking tool for Flarum
The admin panel of afrux/asirem
Enhanced typography for french writings, mainly around punctuation.
统计信息
- 总下载量: 690
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 10
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-12-14