定制 ladamalina/remote-user-bundle 二次开发

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

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

ladamalina/remote-user-bundle

Composer 安装命令:

composer require ladamalina/remote-user-bundle

包简介

Symfony RemoteUserBundle

README 文档

README

Installation

Download the latest stable version of this bundle:

$ composer require ladamalina/remote-user-bundle

Enable the bundle:

<?php
// app/AppKernel.php

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...

            new Ladamalina\RemoteUserBundle\RemoteUserBundle(),
        );

        // ...
    }

    // ...
}

No matter how you authenticate, you need to create a User class that implements UserInterface:

<?php
// src/AppBundle/Entity/User.php

namespace AppBundle\Entity;

use Symfony\Component\Security\Core\User\UserInterface;

class User implements UserInterface
{
    private $id;
    private $username;
    private $name;

    public function getUsername() {
        return $this->username;
    }

    public function getRoles() {
        return ['ROLE_USER'];
    }

    public function getPassword() {}
    
    public function getSalt() {}
    
    public function eraseCredentials() {}

    // more getters/setters
}

Create a User Provider. Here you have to implement user credentials check:

<?php
// src/AppBundle/Security/UserProvider.php

// ...

class UserProvider extends AbstractRemoteUserProvider
{
    /**
     * @var string
     */
    protected $userClassName;

    public function __construct($userClassName) {
        if (!class_exists($userClassName)) {
            throw new \InvalidArgumentException("Class `$userClassName` does not exists. 
                Invalid service configuration: services.remote_user_provider");
        }
        $this->userClassName = $userClassName;
    }

    public function loadUserByUsernameAndPassword($username, $password)
    {
        try {
            // Remote API call checking $username and $password here
            // Populate new User instance with response data

            return $user;
        } catch (\Exception $e) {
            throw new UsernameNotFoundException();
        }
    }
}

Configure authenticator and user provider services app/config/services.yml

services:
    remote_user_provider:
        class: AppBundle\Security\UserProvider
        arguments: ["AppBundle\\Entity\\User"]

    remote_user_authenticator:
        class: RemoteUserBundle\Security\Guard\Authenticator

Configure security user provider app/config/security.yml

security:
    providers:
        remote:
            id: remote_user_provider

Configure firewall guard app/config/security.yml

security:
    firewalls:
        main:
            anonymous: ~
            # activate different ways to authenticate
            
            guard:
                authenticators:
                    - remote_user_authenticator

Usage

POST request with rua_username and rua_password fields will initiate remote authorization call.

curl --request POST \
  --url http://site.com/ \
  --header 'content-type: multipart/form-data; boundary=---011000010111000001101001' \
  --form rua_username=username \
  --form rua_password=password

In case of invalid credentials or remote service unavailability you will recieve HTTP status code 403 Forbidden, otherwise 200 OK.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-08-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固