定制 tiriel/firestore-security-bridge 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tiriel/firestore-security-bridge

最新稳定版本:v0.2.2

Composer 安装命令:

composer require tiriel/firestore-security-bridge

包简介

Symfony Bridge to provide UserProvider for Firestore-persisted users in Symfony

README 文档

README

A small bridge to be used in conjunction with Firestore ODM Bundle. This bridge allows you to use your Firestore DTO as users in Symfony's Security Bundle.

Requirements

This bundle requires PHP 8.2+, Symfony 7+, and Firestore ODM Bundle.

This bundle also relies heavily on Google Glouc Firestore PHP Client, and its technical requirements are the same (most notably PHP gRPC and Protobuf extensions). See Google's documentation for more details.

Installation

If you have Symfony Flex, a contrib recipe is available:

composer require tiriel/firestore-security-bridge

That's it, you're good to go.

If you haven't got Flex installed, first require the bundle as shown above. Then, enable the bundle in the config/bundles.php file:

<?php

return [
    // ...
    Tiriel\FirestoreOdmBundle\TirielFirestoreOdmBundle::class => ['all' => true],
    Tiriel\FirestoreSecurityBridge\TirielFirestoreSecurityBundle::class => ['all' => true],
];

You can now reuse the file config/packages/tiriel.yaml from Firestore ODM and add the following content:

tiriel_firestore_odm:
    # ...

tiriel_firestore_security:
    # The service id or the manager responsible for the DTO you want to use as UserInterface
    user_manager: App\Manager\UserFirestoreDtoManager

Usage

User DTO

See the documentation for Firestore ODM Bundle if you want a basic understanding of how DTOs are used in Firebase ODM.

In addition, the DTO you wish to use as your Security user should extend Tiriel\FirestoreSecurityBridge\Dto\AbstractUser. This class implements Tiriel\FirestoreOdmBundle\Dto\Interface\PersistableDtoInterface and Symfony\Component\Security\Core\User\UserInterface. If you want your users to be authenticated using password, you can still implement Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface.

Example:

use Tiriel\FirestoreSecurityBridge\Dto\AbstractUser;

class User extends AbstractUser implements PasswordAuthenticatedUserInterface
{
    // ...

You can now create a manager for your DTO as usual per Firestore ODM Bundle's documentation.

Using the DTO and Manager in the Security Bundle

You are now set to use your new DTO and its manager in your firewalls, simply define a new User Provider in config/packages/security.yaml with the id tiriel.firestore_security.user_provider:

security:
    # ...
    # https://symfony.com/doc/current/security.html#loading-the-user-the-user-provider
    providers:
        # used to reload user from session & other features (e.g. switch_user)
        app_user_provider:
            id: 'tiriel.firestore_security.user_provider'

You are now set, you can use your User DTO as a security User.

统计信息

  • 总下载量: 20
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-05-30