Github Sponsors integration

Here’s the idea:

  1. My Grav site only accepts Github OAuth2 usernames and logins.
  2. I want to restrict access to my Grav site based on whether the user has sponsored my project and made a donation.

How would I accomplish this?


A few options come to mind:

  1. Only create accounts for sponsors.

  2. Create a group ‘sponsor’ and assign it to accounts from sponsors. Then add to some pages that only ‘sponsor’ users can login.

  3. As mentioned in the README of the Login plugin, there are several events that can be subscribed to in a custom plugin.

    • onUserLoginAuthorize Allows plugins to block user from being logged in.

    This sounds like a good candidate to add your own logic, to either read the list of sponsors online, or read an offline copy of the list.

Im thinking of doing a combination of #2 and #3. i have a Flarum forum running under Grav that has a REST api to synchronize accounts between Grav and Flarum, as well as get the Group the user is in on the Flarum side of things.

So what I want to do is, when the user logs into Grav, OnUserLogin in a custom plugin can get the group the user is in from Flarum, and synchronize it. So how would I change the user’s group in a Grav plugin?

@Spindizzy, There are some docs chapters you might want to read:

I understand how to do it from the Admin panel and manually but how would i do it inside a plugin?


So how would I change the user’s group in a Grav plugin?

Assuming the relevant Flarum group(s) has/have already been created in Grav, you might try something like:

public function onUserLoginAuthorize(Event $event)
  /** @var User */
  $user = $event['user'];
  $groups = $user->groups;

  // Get flarum group of user
  $flarum_group = ...

  if (!$groups) {
    $user->groups = [$flarum_group];
  } else if (!in_array($flarum_group, $groups)) {
    array_push($groups, $flarum_group);
    $user->groups = $groups;


exactly what i needed - thanks!