vimar/flarum-whoami
Composer 安装命令:
composer require vimar/flarum-whoami
包简介
Add Whoami endpoint to Flarum
README 文档
README
This extension adds a new endpoint "/api/whoami" which exposes the data of currently logged-in user. By using this route with the POST /api/token route, you can use Flarum as an identity provider for your site.
Installation
Install manually:
composer require vimar/flarum-whoami
Updating
composer update vimar/flarum-whoami php flarum migrate php flarum cache:clear
Tutorial for Flarum Authentication
Login
To emulate a login statement to Flarum, we just call the Flarum POST /api/token in order to crate a token for registered user:
POST /api/token HTTP/1.1
{
"identification": "John",
"password": "pass7word",
"remember": 1
}
HTTP/1.1 200 OK
{
"token": "YACub2KLfe8mfmHPcUKtt6t2SMJOGPXnZbqhc3nX",
"userId": "1"
}
then we store this token as a cookie (eg: flarum_token) for future use (by default an access token lasts 1 hour unless you add the remember parameter, in which case it lasts for 5 years.).
Note: To enable SSO between our website and flarum, we need to store a session_remember token as flarum_remember cookie too;
Verify logged-in user profile
Now, each time we want to know if an user is logged-in, we only need to call the following endpoint:
POST /api/whoami HTTP/1.1
Authorization: Token YACub2KLfe8mfmHPcUKtt6t2SMJOGPXnZbqhc3nX
HTTP/1.1 200 OK
{
"data": {
"type": "users",
"id": "4",
"attributes": {
"username": "John",
"displayName": "Jon Doe",
"slug": "John-Doe",
"joinTime": "2003-04-02T20:29:29+00:00",
"discussionCount": 125,
"commentCount": 2799,
"canEdit": true,
"canEditCredentials": true,
"canEditGroups": true,
"canDelete": true,
"lastSeenAt": "2023-11-07T09:43:13+00:00",
"isEmailConfirmed": true,
"email": "john@doe.com",
"markedAllAsReadAt": null,
"unreadNotificationCount": 0,
"newNotificationCount": 0,
"preferences": {
...
},
"isAdmin": true,
...
},
"relationships": {
"groups": {
"data": [
{
"type": "groups",
"id": "1"
}
]
}
}
},
"included": [
{
"type": "groups",
"id": "1",
"attributes": {
"nameSingular": "Admin",
"namePlural": "Admins",
"color": "#B72A2A",
"icon": "fas fa-wrench",
"isHidden": 0
}
}
]
}
Logout
To logout, we need to delete our session cookie (containing access token) and eventually purge all of them on Flarum by calling
vimar/flarum-whoami 适用场景与选型建议
vimar/flarum-whoami 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 15 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 11 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「Authentication」 「single sign-on」 「flarum」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 vimar/flarum-whoami 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 vimar/flarum-whoami 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 vimar/flarum-whoami 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A bundle for Symfony, providing authentication against European Commission authentication service.
Automatically logs-in users if they are already authenticated by a remote source. (e.g. environment variable REMOTE_USER)
GraphQL authentication for your headless Craft CMS applications.
A bundle for Laravel, providing authentication against a Central Authentication Service (CAS) server.
Laravel middleware to restrict a site or specific routes using HTTP basic authentication
Libreria PHP per l'autenticazione al sistema di SSO Cohesion2 della Regione Marche
统计信息
- 总下载量: 15
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-11-07