develit-ab/grand-id-bundle

Symfony 插件,用于使用 Grand ID 服务 https://www.grandid.com/

安装: 298

依赖者: 0

建议者: 0

安全: 0

星级: 0

关注者: 2

分支: 1

类型:symfony-bundle

v0.1.10 2018-10-23 13:55 UTC

This package is not auto-updated.

Last update: 2024-09-19 17:16:05 UTC


README

Latest Stable Version Total Downloads License

此扩展提供了与 Grand ID API 一起工作所需的一系列服务方法。所有会话数据都存储在数据库中。

存在所谓的模拟系统,这在测试目的上很有帮助。模拟方法不会调用任何 Grand ID API 端点。它们只是模拟会话:在数据库表中创建、存储和更新它们。

安装

使用 Symfony Flex 的应用程序

打开命令行,进入您的项目目录,然后执行

$ composer require develit-ab/grand-id-bundle

不使用 Symfony Flex 的应用程序

步骤 1:下载插件

打开命令行,进入您的项目目录,然后执行以下命令以下载此插件的最新稳定版本

$ composer require develit-ab/grand-id-bundle

此命令要求您全局安装 Composer,具体请参阅 Composer 文档的 安装章节

步骤 2:启用插件

然后,通过将其添加到项目 app/AppKernel.php 文件中注册的插件列表来启用该插件

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...
            new DevelitAB\GrandIDBundle\GrandIDBundle(),
        );

        // ...
    }

    // ...
}

配置

添加 config/packages/grand_id.yaml 文件,其中包含以下设置

grand_id:
    base_url: '%env(GRAND_ID_BASE_URL)%' #(e.g. https://client-test.grandid.com/json1.1/)
    api_key: '%env(GRAND_ID_API_KEY)%'
    authenticate_service_key: '%env(GRAND_ID_AUTH_SERVICE_KEY)%'

执行 bin/console doctrine:migrations:diffbin/console doctrine:migrations:migrate 命令以创建 Grand ID 会话数据库表。

使用方法

在您的控制器中的某个地方

<?php

...

use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

...

class SomeController extends Controller
{
    ...
    
    private $bankIdProvider;

    public function __construct(ContainerInterface $container)
    {
        $this->bankIdProvider = $container->get('develit_ab.grand_id');
    }
    
    public function doSomething()
    {
        ...
        
        $callBackUrl = 'https://domain.com/my/action'

        $loginObject = $this->bankIdProvider->federatedLogin($callBackUrl);

        ...
    }   
    
    ...
}

可用方法

  • federatedLogin(string $callbackUrl) - 执行实际的 FederatedLogin API 调用。存储实际的会话参数。
  • federatedLoginMock(string $callbackUrl, string $host, string $protocol) - 不执行任何 API 调用。仅存储模拟会话参数。
  • federatedDirectLogin(string $username, string $password)- 执行实际的 FederatedDirectLogin API 调用。存储实际的会话参数。
  • logout(string $sessionId) - 执行实际的 API 注销。更新相关的数据库记录。
  • logoutMock(string $sessionId) - 不执行任何 API 调用。仅更新某些数据库记录。
  • getSession(string $sessionId) - 通过调用实际的 API GetSession 获取会话参数。
  • getSessionMock(string $sessionId) - 从数据库获取模拟会话参数。
  • enableMockSession(string $sessionId, string $username) - 通过添加用户名并将 is_logged_in 设置为 true 更新模拟会话数据库记录。