How i can read the token from header in .net core 7 api - asynchronous

I try to read the token from header request but I don't no what is the manner to do that .
I use .net core 7 wep api
I try to read the request header by using [fromHeader]
But that isn't work.

Related

Migration a jmeter project from v3 to v5 : issue with soap request

i have a working project with jmeter 3.1 using soap request sampler :
Project Jmeter with version 3.1
Http header manager congig
i tried to figure out the same project with jmeter version 5 using http request like this :
Project jmeter version5
but i receive always those 2 error :
Error received
can you help on this please ?
I don't know what is in your HTTP Header Manager, but the system under test complains that you're not providing correct Content-Type header which must be text/xml
I believe if you add this header at least this issue will go away.
Going forward you can just record your test from JMeter 3.x in JMeter 5.x and it will generate relevant HTTP Request samplers and HTTP Header Managers.
More information: Testing REST\SOAP Web services

Authorization header missing in POST call done via NESTJS application

The scenario is that I am trying to hit an API which is in .NET-Core application from my NESTJS application and the while doing that the Authorization header is missing in the .Net-Core side. Rest all the headers are getting attached just this Authorization header is missing
I am using the nestjs/axios library to send the POST call and in the .Net-Core Side I have added all the required headers in CORS policy.
Problem:-
In NESTJS, I have a service, let's say, DemoService
I am calling an api using nestjs/axios like this:
this.httpService.post(url, data, config); // config = {headers: {'Authorization': "bearer", "abc": "abc"}}
And in .Net side there is a middleware where I am trying to read the Authorization header like this:-
var bearer = context.Request.Headers["Authorization"];
But this bearer is coming as empty.
Need some help on this.

customizing HTTP Request Headers

How we can control over the number of header going with the HTTP request? e.g.; If I don't want to send the "Cache-Control" header,how to control it?
I am using HttpClient for sending a JSON formatted request.
Using 4.5.1 version of org.apache.httpcomponents and 3.1 version of commons-httpclient in maven dependencies.

Can't get authentication token from web api 2

I am new to Web Api 2. I am trying to build a project to explore token authorization. I created a new project in VS 2013 and selected the WebApi2 template and used Fiddler to emulate http requests. I didn't change anything in the template, just ran it as it was and tried to play with it with Fiddler. I successfully created a user by issuing request to /api/account/register but I can't login by issuing a POST request to the /Token endpoint. The request is:
http://localhost:YYYY/token?grant_type=password&password=admin123456&username=admin
(i also tried to pass the parameters as a json object in the request body).
I get back this:
{"error":"unsupported_grant_type"}
From other posts such as ASP.NET WEB API 2 OWIN Authentication unsuported grant_Type I learned that I needed to enable CORS for web api and at the token endpoint, but that hasn't worked for me.
Are you sure that you are sending POST request message and not GET?
If you simply go to the URL with query string (or open connection to this URL from your code) you are sending GET message by default. It's not what WebAPI with "/token" path is listening for.
If you are calling web service from same place, CORS is not needed. The error "unsupported_grant_type" could be in the format of the data you are passing server in post action.
Try sending with Content-Type application/x-www-form-urlencoded

OAuth 2.0 Authorization Header

I want to develop a SDK that encapsules the OAuth 2.0 functions. I have checked the differences between OAuth 1.0 & 2.0, and I have some confusion on Authorization Header (1.0 and
2.0), OAuth 1.0 protocol parameters can be transmitted using the HTTP "Authorization" header, but I can't find this described in current OAuth 2.0 draft.
Does OAuth 2.0 supports authorization headers?
In OAuth 1.0 your header would look like:
Authorization: OAuth realm="Example",
oauth_consumer_key="0685bd9184jfhq22",
oauth_token="ad180jjd733klru7",
oauth_signature_method="HMAC-SHA1",
oauth_signature="wOJIO9A2W5mFwDgiDvZbTSMK%2FPY%3D",
oauth_timestamp="137131200",
oauth_nonce="4572616e48616d6d65724c61686176",
oauth_version="1.0"
For those looking for an example of how to pass the OAuth2 authorization (access token) in the header (as opposed to using a request or body parameter), here is how it's done:
Authorization: Bearer 0b79bab50daca910b000d4f1a2b675d604257e42
You can still use the Authorization header with OAuth 2.0. There is a Bearer type specified in the Authorization header for use with OAuth bearer tokens (meaning the client app simply has to present ("bear") the token). The value of the header is the access token the client received from the Authorization Server.
It's documented in this spec: https://www.rfc-editor.org/rfc/rfc6750#section-2.1
E.g.:
GET /resource HTTP/1.1
Host: server.example.com
Authorization: Bearer mF_9.B5f-4.1JqM
Where mF_9.B5f-4.1JqM is your OAuth access token.
I just want to specify that you can use "Property Expansion" in the header value as well to Automation your proccess.
( Actually i use a property transfer too, to transfer token into my TestSuite property and then as you can see return it with "${#TestSuite#token}" )
example:
Sources :
pass a property as access token,
Accessing Property
Best regards community !

Resources