ngx-admin-bundle-support icon indicating copy to clipboard operation
ngx-admin-bundle-support copied to clipboard

Unauthorized requests on swagger

Open gustavo-oliveira-mendonca opened this issue 6 years ago • 0 comments

I follow the instructions provided on the docs folder of the nestjs-angular bundle to test the api using <api_url>/swagger. First I made a POST to /api/auth/login and got a token. I then set the authorization by the button located on the top right of the page using the format Bearer <token>.

All the attempts to access locked paths on the api returned me error 401 - Unauthorized with the body:

{
  "statusCode": 401,
  "error": "Unauthorized"
}

Analyzing the post, swagger was sending on the header of my requests with the key Authentication: Bearer <my-token>. I believe the correct is Authorization: Bearer <my-token>.

I changed .addBearerAuth('Authentication', 'header') to .addBearerAuth('Authorization', 'header') on the main.ts from the backend project and got it working.