Prior to any action my script is required to authenticate via the UserId/Password credentials to get the valid authentication token. Authentication is based on a standard OAuth 2 grant type: Password Credentials. End User will need to use the credential’s and need to make a call to the OKTA URL to get the proper token. Bearer token that is to be returned by the OKTA authentication endpoint. The following CURL command works. (I also have a working postman and Jmeter script).
curl --location --request POST ‘https://login.epo.org/oauth2/aus3up3nz0N133c0V417/v1/token’ --header ‘Authorization: Basic MG9hM3VwZG43YW41cE1JOE80MTc=’ --header ‘Content-Type: application/x-www-form-urlencoded’ --header ‘Cookie: JSESSIONID=410A141E003CA043900BD8F707007F74’ --data-urlencode ‘grant_type=password’ --data-urlencode ‘username=akhtar1508@gmail.com’ --data-urlencode ‘password=Test@bdds1’ --data-urlencode ‘scope=openid’.
The following K6 script fails with a http 400 bad request error and the authorisation fails. Is there something obvious i am doing wring in this script.
import http from ‘k6/http’
import { check } from “k6”;
export default function () {
var url = ‘https://login.epo.org/oauth2/aus3up3nz0N133c0V417/v1/token’;
var headerParam = {
headers: {
'Authorization': 'Basic MG9hM3VwZG43YW41cE1JOE80MTc=',
'Content-Type': 'application/x-www-form-urlencoded',
'Cookie': 'JSESSIONID=410A141E003CA043900BD8F707007F74'
}
};
//lets define body - accepts email and password
var payload = JSON.stringify({
grant_type: 'password',
username: 'akhtar1508@gmail.com',
password: 'Test@bdds1',
scope: 'openid'
});
// URL, HEADER, JSON BODY
let response = http.post(url, headerParam, payload)
check(response, {
success: r => r.status == 200
});
}