简体   繁体   English

Symfony2 API密钥身份验证-找不到路由

[英]Symfony2 API Key Authentication - No route found for

I followed the documentation , and this is how my code is organized: 我遵循了文档 ,这是我的代码的组织方式:

src/Company/AuthBundle/Security/ApiKeyAuthenticator.php src/Company/AuthBundle/Security/ApiKeyUserProvider.php src / Company / AuthBundle / Security / ApiKeyAuthenticator.php src / Company / AuthBundle / Security / ApiKeyUserProvider.php

(they are the same as sample classes in doc) (它们与doc中的示例类相同)

# File: services.yml

apikey_authenticator:
   class:  Company\AuthBundle\Security\ApiKeyAuthenticator
   public: false    

# File: security.yml

  firewalls: 
    api:
      pattern: ^/api
      stateless: false
      simple_preauth:
      authenticator: apikey_authenticator
      provider: fos_userbundle
      security: false
      anonymous: true

And now, If I try to access eg http://symfony-project.dev/api?apikey=somekey , I got the following error: 现在,如果我尝试访问例如http://symfony-project.dev/api?apikey=somekey ,则会出现以下错误:

No route found for "GET /api" 找不到“ GET / api”的路线

Any idea what's wrong? 知道有什么问题吗?

The error message is fairly clear really - you haven't defined a route for a GET request for '/api' . 错误消息确实很清楚-您尚未为'/api'GET请求定义路由。

The security component you've configured takes care of authentication and granting access, but it does not control any logic specific to your application. 您配置的安全组件负责身份验证和授予访问权限,但它不控制任何特定于您的应用程序的逻辑。 You must create a controller and a route for requests like this. 您必须为这样的请求创建控制器和路由。

You can see your currently defined routes with $ php app/console debug:router - if you've tried to define a route, that will help you debug it. 您可以使用$ php app/console debug:router查看当前定义的路由-如果您尝试定义路由,则将有助于您对其进行调试。 If not, you must create one . 如果不是,则必须创建一个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM