askvortsov / flarum-auth-sync
Manage Sync from External Identity Providers
Installs: 461
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 11
Type:flarum-extension
Requires
- flarum/core: ^0.1.0-beta.15
- dev-master
- v2.0.0
- v1.1.0
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- v0.1.3
- v0.1.2
- v0.1.1
- v0.1.0
- dev-dependabot/npm_and_yarn/js/json5-1.0.2
- dev-dependabot/npm_and_yarn/js/decode-uri-component-0.2.2
- dev-dependabot/npm_and_yarn/js/loader-utils-and-webpack-cli-1.4.2
- dev-dependabot/npm_and_yarn/js/terser-4.8.1
- dev-dependabot/npm_and_yarn/js/ajv-6.12.6
- dev-dependabot/npm_and_yarn/js/path-parse-1.0.7
- dev-dependabot/npm_and_yarn/js/browserslist-4.16.6
- dev-dependabot/npm_and_yarn/js/lodash-4.17.21
- dev-dependabot/npm_and_yarn/js/ssri-6.0.2
- dev-dependabot/npm_and_yarn/js/y18n-4.0.1
- dev-dependabot/npm_and_yarn/js/elliptic-6.5.4
- dev-mithril-2-update
- dev-beta8-support
This package is auto-updated.
Last update: 2024-12-06 06:55:01 UTC
README
A Flarum extension to sync user attributes when authenticated by an external identity provider. This extension provides support for syncing:
- Avatar
- Groups
- Bio
- Masquerade Attributes
Some authentication protocols, such as SAML2, LDAP, OpenID Connect, etc have the ability to send attributes along with an authentication response. This extension provides a framework for syncing user attributes and permissions via that attribute response.
Installation
Use Bazaar or install manually with composer:
composer require askvortsov/flarum-auth-sync
Updating
composer update askvortsov/flarum-auth-sync
How to Use
For flarum administrators, if you're using an authentication extension that uses flarum auth sync, you can use the settings popup on the Flarum Admin extensions page to choose which types of attributes you'd like to sync. Please note that in order to sync Bios and Masquerade Profile Fields, you need to install and enable the Friends of Flarum User Bios and Friends of Flarum Masquerade extensions.
To use this extension in another authentication extension:
- Import the AuthEventSync model via
use Askvortsov\FlarumAuthSync\Models\AuthSyncEvent;
- Before logging in/registering the user, create an AuthSyncEvent. Ex:
use Askvortsov\FlarumAuthSync\Models\AuthSyncEvent;
use use Carbon\Carbon;
...
if ($this->extensions->isEnabled('askvortsov-auth-sync') && $this->settings->get('askvortsov-saml.sync_attributes', '')) {
$event = new AuthSyncEvent();
$event->email="example.user@example.com";
$event->attributes = json_encode([
"avatar" => "https://example.com/avatar.jpg",
"bio" => "Hello, this is my bio",
"groups" => [1, 15, 2],
"masquerade_attributes" => [
"First Name" => "Example",
"Last Name" => "User",
"Website" => "https://example.com
]
]);
$event->time = Carbon::now();
$event->save();
}
- Of course, replace the generic values above with attributes from your Identity Provider's response.
- Attributes should be provided in a json-encoded string (see above example). The JSON string should have the following attributes:
avatar
: A URL pointing to an image for the user's avatar. Make sure that the file type is compatible with Flarum (jpeg or png I believe).groups
: A comma-separated list of ids for groups that a user should belong to. Keep in mind that this will both add and remove groups, so make sure that all desired groups are included.bio
: A string that will be synced to the user's bio if Friends of Flarum User Bios is enabledmasquerade_attributes
: An associative array for any masquerade keys and attributes you want to sync. Make sure that the key matches the name of the profile field exactly.
This was originally developed for Flarum SAML2 SSO. For an example of how to integrate it, please see this line.
TODO
- Add better validation and error handling.
- Add a setting to support default groups that all users should be added to, and groups that users should never be synced to.
- Add an expiry setting for Auth Sync Events.
- Add support for getting users via LoginProvider providers and identifiers, in addition to email.
- Due to a bug in flarum core, the
LoggedIn
event isn't dispatched when logging in via an external identity provider. Until this is fixed, the UserUpdatedListener listens toSerialize
events (except those going to masquerade). This workaround will be promptly removed when the upstream bug is fixed.
Feedback
Super excited to be posting my first extensions, hopefully more to follow! If you run into issues or have feature requests, let me know and I'll look into it!