Inspecting bearer token - asp.net-web-api

I have some challenges authentication to WEB API so I started a fiddler to see what going on. I got a bearer token but I am suspecting the framework is not attaching the token to the request.
I cant see any bearer token in the header, is it correct to assume that the bearer token should have been in the header of the request, or can bearer token be added otherwise?

is it correct to assume that the bearer token should have been in the header of the request
Yes, that's exactly what the response tells you:
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer
This means your client should send a Authorization: Bearer $token request header.

Related

Swagger-Net and Bearer Token Authorization

We are using Swagger-Net with Bearer Token Authorization as follows:
c.ApiKey("Authorization", "header", "Bearer Token Authentication");
The request needs to be sent in the format "Bearer [bearertoken]", and I have verified this does work correctly when pasted in this format into the "API Key" authorization textbox. The Curl shows it being passed in the header as -H "Authorization: Bearer [token] and the API request succeeds.
Is there any way to automatically send a known token along with every API request? Or asked another way, is there any way to pre-fill this dynamically created API Key textbox with a known string to simplify the process for the end using testing our API?

Error on authentication when using passport package on laravel

Hello Everyone i am using the passport package for authentication in laravel but i got the error "Unauthenticated" when i am using on postman.
token_type: Bearer
email:mhd.kashif1#gmail.com
access_token:eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6ImEzODBiNDhlYWU4OTU0NGZlMGYyMjViMWEzZWIyMGQ3OTZlN2Y1Y2RjNjBkMDJhM2MzZTA5ZjIzN2Y5NmNkZjgzZTU4ODkyOTE1MjY4MjRiIn0.eyJhdWQiOiI0IiwianRpIjoiYTM4MGI0OGVhZTg5NTQ0ZmUwZjIyNWIxYTNlYjIwZDc5NmU3ZjVjZGM2MGQwMmEzYzNlMDlmMjM3Zjk2Y2RmODNlNTg4OTI5MTUyNjgyNGIiLCJpYXQiOjE1Njg3OTE1NTQsIm5iZiI6MTU2ODc5MTU1NCwiZXhwIjoxNTcwMDg3NTU0LCJzdWIiOiIxNjkiLCJzY29wZXMiOltdfQ.sRIVRrFLb9AFrE1oMd5njmkyjWkhgtA-pM6czmTnieDN020n75-r4FL9jNnXC5tTuPJcvm0o-xiy4nOy8rMeaq0OMr0Kr0kcM0RHiSVnNXAfObR1Iy23z5zXMQf_d1kuo-8NX_1ltpZ3FfskzbwVLffYLT6TLR_pIeqBTpTD8jXQyfq8V2yNk7jlH51nZvZbeJJCIaeP9DAqNYmYPOnV5D9Xbzmrx4dXDA0lyIa8Lksz3SvF56JT6xsCf3fjW1uy91nGyfGyCXSF-7bqtkfp2wTlDMW66c43HNMblqfjdPJKOQkwD5Z_rMPCCuOepnzqqShsUdCOWFh2YML-Fg8CXKJ3Lz-rRN_Oj_c-ZFMKyp9cvKht5fDa7Mkjou8m8zG3GCLlsjmU7OMjDNkgXHr-GHh0PNV38lcgz3R3_ZpS_RKzvw3LYOVmBFJP9GvwDLfFMP7Vh2S8GtuG12VfSuyP5e0iK4EMnBPaptXTfeLO7Dz0VGQVzWxYRltef415bVtWMrjJ-dii_BEpJorGINEr0BdTsJoIeKGXAjPsPCQD5MZf3gTM5fE3tdD6ICIrIIczZoss-QPgV-LYn-RMqOeSLMeC-s_ZB1X1MnyHGz8gbTl_QHnnyHJPo3PbkKHcGrW20OwL-l1Rw5rW8zw5vqb0Iy1g7hp1_Yp5eU_MrAIA6l0
device_type:android
device_id:762ead278b86a114
device_token:faS3KB_cjvY:APA91bE5c9Jg2u9mNNWLcw_pWF78Z1wpyBl11GUV8kczaUWQwj5w0mG-KecoXoLgPdcbpQbEcNRvydtNVR1BESHBNz9-WjlSO3daCF-VFqXoG9ap29HMrmgjyS-qvJsLIIqy0TTLx88Z
Accept:application/json
Laravel passport expects an Authorization header when authenticating so you need to concatenate Bearer with the access_token in the request headers of postman
Accept: application/json
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6ImEzODBiNDhlYWU4OTU0NGZlMGYyMjViMWEzZWIyMGQ3OTZlN2Y1Y2RjNjBkMDJhM2MzZTA5ZjIzN2Y5NmNkZjgzZTU4ODkyOTE1MjY4MjRiIn0.eyJhdWQiOiI0IiwianRpIjoiYTM4MGI0OGVhZTg5NTQ0ZmUwZjIyNWIxYTNlYjIwZDc5NmU3ZjVjZGM2MGQwMmEzYzNlMDlmMjM3Zjk2Y2RmODNlNTg4OTI5MTUyNjgyNGIiLCJpYXQiOjE1Njg3OTE1NTQsIm5iZiI6MTU2ODc5MTU1NCwiZXhwIjoxNTcwMDg3NTU0LCJzdWIiOiIxNjkiLCJzY29wZXMiOltdfQ.sRIVRrFLb9AFrE1oMd5njmkyjWkhgtA-pM6czmTnieDN020n75-r4FL9jNnXC5tTuPJcvm0o-xiy4nOy8rMeaq0OMr0Kr0kcM0RHiSVnNXAfObR1Iy23z5zXMQf_d1kuo-8NX_1ltpZ3FfskzbwVLffYLT6TLR_pIeqBTpTD8jXQyfq8V2yNk7jlH51nZvZbeJJCIaeP9DAqNYmYPOnV5D9Xbzmrx4dXDA0lyIa8Lksz3SvF56JT6xsCf3fjW1uy91nGyfGyCXSF-7bqtkfp2wTlDMW66c43HNMblqfjdPJKOQkwD5Z_rMPCCuOepnzqqShsUdCOWFh2YML-Fg8CXKJ3Lz-rRN_Oj_c-ZFMKyp9cvKht5fDa7Mkjou8m8zG3GCLlsjmU7OMjDNkgXHr-GHh0PNV38lcgz3R3_ZpS_RKzvw3LYOVmBFJP9GvwDLfFMP7Vh2S8GtuG12VfSuyP5e0iK4EMnBPaptXTfeLO7Dz0VGQVzWxYRltef415bVtWMrjJ-dii_BEpJorGINEr0BdTsJoIeKGXAjPsPCQD5MZf3gTM5fE3tdD6ICIrIIczZoss-QPgV-LYn-RMqOeSLMeC-s_ZB1X1MnyHGz8gbTl_QHnnyHJPo3PbkKHcGrW20OwL-l1Rw5rW8zw5vqb0Iy1g7hp1_Yp5eU_MrAIA6l0
From the docs

Request headers being ignored by Apache server

I posted earlier this post right here
The problem is that when i send my requests after login on my ionic app a have the token stored and I use it to send other request that needs authentication these request has the header like this:
Accept: application/json
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI.....
Content-Type: application/json
Origin: http://localhost:8100
Referer: http://localhost:8100/
An after 3 days of search I figured out the request headers are being ignored by Apache and all requests arrives without token so i get this message error as response from all API routes:
{"message": "Unauthenticated"}

How to develop test-automation using Postman when OAuth 2.0 authorization is required

I have an ASP.NET Web API 2 which is using OAuth 2.0 for authorization. And let's imagine I have a simple Web API method, like:
GET: http://host/api/profiles/user123 (requires OAuth 2.0 token)
So, with Postman, it is easy to test this Web API. I get an OAuth token for user123 from the Web API OAuthAuthorization method and then I use that token in the header of the HTTP request:
GET /api/profiles/user123 HTTP/1.1
Host: {host}
Authorization: Bearer {Token}
Content-Type: application/json
Cache-Control: no-cache
However, if I save my test and run it later (either by Postman itself or by Newman), the token will be expired at that time and it won't work.
How can I make Newman to get a new token automatically for user123 and use it in the HTTP request?
Note: I know how to use Postman's Authentication helpers to ask for a new token. But this scenario doesn't fit the test-automation. In test-automation, I want to remove any human interaction.
It's simple, get your access token at run time and save it into environment variable. Then use it in your next Get request.
In Get Token request, do this in Tests sections:
var body = JSON.parse(responseBody);
pm.environment.set('AccessToken', body.access_token);
In your main Get request, you can use the environment variable in Authorization header:
Authorization: Bearer {{AccessToken}}
Hope this helps.

Is it possible to convert Token from request string to Header in jwt authentication?

I'm using Tymon\JWTAuth with laravel
and I'm sending the requests like this
www.example.com/test?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOjUzNywiaXNzIjoiaHR0cDpcL1wvbG9jYWxob3N0Ojg4ODhcL3YyXC9zZWxmXC9hdXRoZW50aWNhdGUiLCJpYXQiOjE0NzE0MzI0ODMsImV4cCI6MTQ3MTQ3NTY4MywibmJmIjoxNDcxNDMyNDgzLCJqdGkiOiI4ZDVlZGE4MmE2MTZlMzM5NjgwMmFmZTk5NWI3N2Q1MCJ9.-t0El5nJj_pgNzpgtLy8EVLUsf9dp8RTLhWA3cK_Vmw
I want to move this token to header is that possible ?
Yes. You can send the token with header.
From the documentation:
To make authenticated requests via http using the built in methods, you will need to set an authorization header as follows:
Authorization: Bearer {yourtokenhere}

Resources