mkosiedowski/simple-api-key-bundle

为使用没有用户认证的ApiKey应用认证提供途径,适用于Symfony2

0.1.0 2019-11-25 15:37 UTC

This package is auto-updated.

Last update: 2024-09-26 08:24:06 UTC


README

为使用ApiKey应用认证在Symfony2中创建防火墙。

此包高度基于 uecode/api-key-bundle

安装

需要composer,按照以下方式安装

composer require mkosiedowski/simple-api-key-bundle dev-master

启用Bundle

将以下代码放入你的 AppKernel.php 中以启用该Bundle

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new mkosiedowski\SimpleApiKeyBundle\SimpleApiKeyBundle(),
    );
}

配置

你可以更改API密钥的交付方式和发送的参数名称。默认情况下,此Bundle在查询字符串中查找apiKey

simple_api_key:
    delivery: query #or header
    parameter_name: some_value # defaults to `api_key`

应用程序仓库

默认情况下,应用程序存储在applicationKeys表中。

你应该在你的Doctrine配置中注册Doctrine实体映射

doctrine:
    orm:
        entity_managers:
            default:
                mappings:
                    SimpleApiKeyBundle:
                        type: annotation
                        dir: Entity
                        is_bundle: true

更改安全设置

现在你可以在任何防火墙中添加 simple_api_key: true

例如

security:
    firewalls:
        auth:
            pattern: ^/api/*
            simple_api_key: true
            stateless: true