【问题标题】:The storage configuration for OAuth2 is missing when 'config_cache_enabled' is set to true当 'config_cache_enabled' 设置为 true 时,OAuth2 的存储配置丢失
【发布时间】:2016-01-22 05:24:16
【问题描述】:

我在我的 Web 应用程序中使用 zf2 apigility。在生产模式下,如果config_cache_enabledconfig/application.config.php 中为true,我在请求access_token 时收到此消息错误:

缺少 OAuth2 的存储配置

如果我将其设置为false,我将获得我的访问令牌。

所以我的问题是将config_cache_enabled 设置为true 并成功请求在生产模式下获取访问令牌,因为缓存配置时性能最佳。该怎么做?

这是我的zf-mvc-auth 配置:

'zf-mvc-auth' => array(
        'authentication' => array(
            'adapters' => array(
                'CustomStorage' => array(
                    'adapter' => 'ZF\\MvcAuth\\Authentication\\OAuth2Adapter',
                    'storage' => array(
                        'storage' => 'Application\\Adapter\\OAuth\\CustomPdoAdapter',
                        'route' => '/oauth',
                    ),
                ),
            ),
        ),
    ),

这是我的 oauth2.local.php :

'zf-oauth2' => array(
        'db' => array(
            'dsn'      => 'mysql:dbname=mydatabase;host=localhost',
            'username' => 'root',
            'password' => '',
        ),
        'allow_implicit' => true,
        'access_lifetime' => 3600,
        'enforce_state'  => true,
        'storage'        => 'Application\Adapter\OAuth\CustomPdoAdapter',
        'storage_settings' => array(
           'user_table' => 'users',
        ),
         'options' => array(
            'always_issue_new_refresh_token' => true,
        ),
    ),

我认为它配置得很好。

【问题讨论】:

    标签: php zend-framework2 oauth-2.0 access-token laminas-api-tools


    【解决方案1】:

    您是否正确设置了zf-mvc-auth。在the module.config.php you can read that you have to define a storage key。还有写how you can do this

    要指定存储实例,您可以使用以下两种方法之一:

    • 指定指向命名服务或数组的“存储”子键 要使用的命名服务。
    • 指定值为“pdo”或“mongo”的“适配器”子键,并且 包括用于配置 ZF\OAuth2\Adapter\PdoAdapter 的附加子项 或 ZF\OAuth2\Adapter\MongoAdapter,相应地。请参阅 zf-oauth2 有关详细信息的文档。

    【讨论】:

      【解决方案2】:

      如果您处于生产模式并且“config_cache_enabled”是真的,您需要删除文件 data/cache 文件夹

      【讨论】:

        猜你喜欢
        • 2023-03-21
        • 2011-04-02
        • 2020-07-10
        • 2017-06-28
        • 2021-08-01
        • 1970-01-01
        • 2021-09-05
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多