robert-kampas/symfony-graph-authenticator
最新稳定版本:1.7.0
Composer 安装命令:
composer require robert-kampas/symfony-graph-authenticator
包简介
Microsoft Graph authenticator bundle for Symfony.
README 文档
README
Installation
This package does not have Symfony Flex recipe. However, that is planned for future releases.
Step 1
Run composer require robert-kampas/symfony-graph-authenticator
Step 2
Add the line SymfonyGraphAuthenticator\GraphAuth\GraphAuth::class => ['all' => true] to config/bundles.php array.
Step 3
Create file graph_auth.yaml file in config/packages/ folder and populate it with bundle configuration. Refer to Package Configuration section for this step.
Step 4
Edit security.yaml file in config/packages/ folder. Add new user provider, e.g.
providers:
microsoft_graph_provider:
id: symfony_graph_auth.user_provider
and register new firewall, e.g.
firewalls:
main:
provider: microsoft_graph_provider
guard:
authenticators:
- symfony_graph_auth.authenticator
Step 5
Extend your User entity with SymfonyGraphAuthenticator\GraphAuth\Entity\AbstractUser abstract class. This class has all user entity methods required by the bundle. You will need to run php bin/console doctrine:schema:update --force to create user table with all required columns.
User entity requirements:
- User entity class must be called
Userand must be inApp\Entity\Usernamespace. - User accounts must be stored in
usertable.
What's Next?
Once bundle is setup users can login with their Microsoft account. Upon successfull login user account is created in the databse and user token in stored in session attribute called access_token. You can use microsoft/microsoft-graph (included with this bundle) to query Microsoft Graph. For example,
$graph = new Graph();
$graph->setAccessToken($session->get('access_token'));
$user = $graph
->createRequest('GET', '/me')
->setReturnType(Model\User::class)
->execute();
Package Configuration
Registering New Application
To acquire application id, secret and other configuration values you will need to register new application on your Microsoft Azure account.
- Login to Microsoft Azure portal.
- Go to App registrations page.
- Click on "New registration" and complete new application registration.
You can find more information about registering new applications here.
Configuration Parameters
| Parameter Name | Required | Type | Default Value | Notes |
|---|---|---|---|---|
| application_id | Yes | string | n/a | Also referred to as client ID. The application ID that the Azure app registration portal assigned to your app. |
| application_secret | Yes | string | n/a | Can be found in "Certificates & secrets" tab. |
| directory_id | Yes | string | n/a | Also referred to as tenant id. The directory tenant that you want to request permission from. This can be in GUID or friendly name format. If you don't know which tenant the user belongs to and you want to let them sign in with any tenant, use common as parameter value. |
| callback_uri | Yes | string | n/a | The redirect URI where you want the response to be sent for your app to handle. It must exactly match one of the redirect URIs that you registered in the "Authentication" tab. Controller handling this URI does not need to have any special code. It can be any valid URI in your application as long as it is protected by microsoft_graph_provider firewall. |
| post_logout_redirect_uri | No | string | null | The URL that the user is redirected to after successfully signing out. If the parameter isn't included, the user is shown a generic message that's generated by the Microsoft identity platform. This URL must match one of the redirect URIs registered for your application in the app registration portal. |
| scopes | No | array[string] | [] | Scopes are Microsoft Graph permission names. You can find list of all available scopes here. |
| first_user_role | No | string | ROLE_SUPER_ADMIN | Role automatically assigned to the very first user in the database. |
| default_user_role | No | string | ROLE_USER | Role automatically assigned to every user who successfully logs in with Microsoft account. |
Scopes
Scopes openid, offline_access, profile and user.read are required for bundle to work. Therefore, these scopes are automatically appended to requested scopes array. This means that these scopes do not have to be added as values to scopes parameter. Although, adding them will not cause any errors.
Example Bundle Configuration File
graph_auth:
application_id: b8753c4-3f876-9863-88765-88634mk2df3
application_secret: '2dd[nJ*//ewr00-pfdelL0872.oiw_T'
directory_id: d8763h-3552-9870a-b38a-ee987388j
callback_uri: https://my-application.com
post_logout_redirect_uri: https://my-application.com/login
scopes:
- calendars.read
first_user_role: ROLE_DEVELOPER
default_user_role: NO_ACCESS
Example Security Configuration File
security:
role_hierarchy:
ROLE_DEVELOPER: [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
ROLE_ADMIN: [ROLE_USER]
ROLE_USER: []
providers:
microsoft_graph_provider:
id: symfony_graph_auth.user_provider
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
provider: microsoft_graph_provider
anonymous: true
switch_user: true
pattern: ^/
logout:
path: /logout
invalidate_session: true
guard:
authenticators:
- symfony_graph_auth.authenticator
access_control:
- { path: ^/logout, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/, role: ROLE_USER }
Example User Entity File
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use SymfonyGraphAuthenticator\GraphAuth\Entity\AbstractUser;
/**
* @ORM\Table(name="user")
* @ORM\Entity
*/
final class User extends AbstractUser
{
/**
* @ORM\Id()
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\Column(name="id", type="integer")
*/
private $id;
public function getId(): int
{
return $this->id;
}
}
robert-kampas/symfony-graph-authenticator 适用场景与选型建议
robert-kampas/symfony-graph-authenticator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.16k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 09 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「User management」 「Symfony Bundle」 「authenticator」 「office 365」 「Microsoft graph」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 robert-kampas/symfony-graph-authenticator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 robert-kampas/symfony-graph-authenticator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 robert-kampas/symfony-graph-authenticator 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The bundle for easy using json-rpc api on your project
Bundle Symfony DaplosBundle
A Silverstripe module to allow you to log into any of your Silverstripe sites from one place.
Task system for APPUI
Standalone replacement for php's native get_browser() function
User component for Yii2
统计信息
- 总下载量: 1.16k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-09-16