coresite/apiauthbundle

REST应用程序的令牌授权。

安装: 137

依赖: 0

建议者: 0

安全: 0

星标: 1

关注者: 3

分支: 0

开放问题: 0

类型:symfony-bundle

0.3.2 2017-02-24 14:08 UTC

This package is not auto-updated.

Last update: 2024-09-14 19:31:06 UTC


README

令牌授权,适用于REST应用程序。

安装与连接

安装

$ composer require coresite/apiauthbundle

连接

// app/AppKernel.php
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...
            new CoreSite\APIAuthBundle\CoreSiteAPIAuthBundle(),
            // ...
        );

        // ...
    }
}   

配置

配置示例,您可能需要根据您的配置进行调整。

// app/security.yml
firewalls:

    # ...
    
    api:
        pattern: ^/api
        stateless: true
        simple_preauth:
            authenticator: cs_apiauth_authenticator
            provider: cs_apiauth_user_provider

    api_login:
        provider: fos_userbundle
        stateless: true
        anonymous: ~
        cs_apiauth_login:
            check_path:               api_login_check
            username_parameter:       _username
            password_parameter:       _password
            success_handler:          cs_apiauth_user_handler_authentication_success
            failure_handler:          cs_apiauth_user_handler_authentication_failure
            require_previous_session: false
        logout:
            success_handler:          cs_apiauth_user_handler_logout
    
    # ...
                    
    providers:
        fos_userbundle:
            id: fos_user.user_provider.username
        cs_apiauth_user_provider:
            id: cs_apiauth_user_provider
    
        access_control:
            - { path: ^/api, role: IS_AUTHENTICATED_FULLY }
            - { path: ^/login_check, roles: IS_AUTHENTICATED_ANONYMOUSLY }     
    
    # ...                   

创建用于存储令牌的表

    # php bin/console doctrine:schema:update --force 

免责声明

请注意,此插件是为个人需求开发的,并不完全是一个完善的工程项目,不建议用于工业目的。作者对使用此代码可能出现的任何问题不承担任何责任。