I have a curl Oauth 1.0a request:
curl --location --request POST ‘https://dev/api/login’
–header ‘Content-Type: application/consumer-key+json’
–header ‘Authorization: OAuth oauth_consumer_key=“42a3be6e77dc41d6bfeab5229b172b53”,oauth_signature_method=“HMAC-SHA1”,oauth_timestamp=“1504127763”,oauth_nonce=“6ULC6xT4Fxi”,oauth_version=“1.0”,oauth_signature=“0dr9PXF1mkkyDD%2BWehj1%2FYsouVY%3D”’
–data-raw ‘{
“key”: “42a3be6e77dc41d6bfeab5229b172b53”,
“secret”: “6437eb48-6828-2222-a923-1681be663d3e”
}’
My scripts:
import http from 'k6/http';
import { check } from 'k6';
import { crypto } from "k6/crypto";
export let options = {
vus: 1,
duration: '1s',
};
export default function () {
var url = `https://dev/api/login`;
var requestBody =
{
"key": "42a3be6e77dc41d6bfeab5229b172b53",
"secret": "6437eb48-6828-2222-a923-1681be663d3e"
};
let headers = {
'headers': {
'Content-Type': 'application/consumer-key+json',
'Authorization': `OAuth oauth_consumer_key="42a3be6e77dc41d6bfeab5229b172b53",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1504127763",oauth_nonce="6ULC6xT4Fxi",oauth_version="1.0",oauth_signature="0dr9PXF1mkkyDD%2BWehj1%2FYsouVY%3D"`
}
};
let res = http.post(url, requestBody, headers);
check(res, {
'Consumer login: is status 200': (r) => r.status === 200,
});
}
Problem statement: I am getting unauthorized when running my script. It seems that oauth_signature is incorrect. There is no documentation for Outh 1.0 but there is for 2.0 including an example. I am stuck. I do not how to structure the code and generate oauth signature and use it.