如何使用API PLATFORM(符号4)将Login添加到swagger UI? [英] How to add Login to swagger UI with API PLATFORM (symfony 4)?
问题描述
我安装了&配置LexikJWTAuthenticationBundle,它可以正常工作,但是我有一个小问题.
I installed & configured LexikJWTAuthenticationBundle, it works fine but I've got a small problem.
我已经包含用于放置JWT令牌的授权"按钮,问题是我拥有令牌的唯一方法是使用以下命令:
I have include the Authorization button for put the JWT token, the problem is the only way I can have my token is to use this commands:
curl -X POST -H "Content-Type: application/json" http://localhost:8000/api/login_check -d '{"username":"johndoe","password":"test"}'
它将令牌发送给我,然后将其放入API中.
It send my the token and I put it in the API, OK.
第一个问题:当我用POSTMAN尝试此请求时,出现错误:
First problem: When I try this request with POSTMAN I get an error :
无法找到路径"/api/login_check"的控制器.路由配置错误.(找不到404)
Unable to find the controller for path "/api/login_check". The route is wrongly configured. (404 Not Found)
请求:localhost:8000/api/login_check?username = johndoe& password =使用POST方法进行测试
The request : localhost:8000/api/login_check?username=johndoe&password=test with POST method
因此,使用curl可以正常使用,但是不能使用POSTMAN,为什么?这是我的security.yaml:
So with curl it's working but not with POSTMAN, why ? Here is my security.yaml:
security:
encoders:
App\Entity\User:
algorithm: argon2i
providers:
app_user_provider:
entity:
class: App\Entity\User
property: email
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
login:
pattern: ^/api/login
stateless: true
anonymous: true
json_login:
check_path: /api/login_check
success_handler: lexik_jwt_authentication.handler.authentication_success
failure_handler: lexik_jwt_authentication.handler.authentication_failure
require_previous_session: false
register:
pattern: ^/api/register
stateless: true
anonymous: true
api:
pattern: ^/api
stateless: true
anonymous: true
provider: app_user_provider
main:
anonymous: true
access_control:
- { path: ^/api/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/api/register, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/api, roles: IS_AUTHENTICATED_ANONYMOUSLY }
role_hierarchy:
ROLE_DELEGATION: [ROLE_USER]
ROLE_EXPORT: [ROLE_USER]
ROLE_USER_ADMIN: [ROLE_USER]
ROLE_LIST_ADMIN: [ROLE_USER]
ROLE_IMPORT: [ROLE_USER]
ROLE_MOBILE: [ROLE_USER]
ROLE_ADMIN: [ROLE_USER, ROLE_ALLOWED_TO_SWITCH]
ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ALLOWED_TO_SWITCH]
第二个问题,我想在Swagger中添加登录名.像这样:
Second problem, I'd like to add the login inside the Swagger. Like this:
我不知道如何执行此操作,尝试在LoginCheckController内添加@ApiRessource(),但它什么也没做.
I have no idea how to doing this, tryed to add @ApiRessource() inside the LoginCheckController but it's doing nothing.
需要一些帮助/提示,在此先感谢
Need some help / tips, thanks by advance
推荐答案
404消息告诉您,没有定义/api/login_check
的路由,或者配置存在问题,并且路由不是成立您应该先检查并调试路由,看看是否已经定义
The 404 message tells you there's either no route defining /api/login_check
or there's a configuration problem with it and the route is not found
You should check and debug your routes first and see if this is already defined
login_check:
path: /login_check
您可能还需要检查 GitHub问题
后来经过更多研究后,我在Stackoverflow上找到了一个可能的解决方案
Later After researching a bit more, I found a possible solution to your problem here on Stackoverflow
这篇关于如何使用API PLATFORM(符号4)将Login添加到swagger UI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!