akveo / ngx-admin-bundle-support

Support repository for ngx-admin backend bundles with issues tracking, instructions and code samples
58 stars 32 forks source link

Unauthorized requests on swagger #34

Open gustavo-oliveira-mendonca opened 5 years ago

gustavo-oliveira-mendonca commented 5 years ago

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.