Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/world.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ class World {
}

async setBasicAuth(credentials) {
const { username, password } = credentials;
const secretCredentials = this.replaceVars(credentials);

const { username, password } = secretCredentials;
const agent = this.currentAgent;
const encodedCredentials = Buffer.from(`${username}:${password}`).toString('base64');
agent.set('Authorization', `Basic ${encodedCredentials}`);
Expand All @@ -181,13 +183,15 @@ class World {
async getOAuthAccessToken(url, credentials) {
const agent = this.currentAgent;

const secretCredentials = this.replaceVars(credentials);

// do an oauth2 login
// only set the bearer token once on the agent
if (!agent._bat.bearer) {
const res = await agent
.post(this.baseUrl + this.replaceVars(url))
.type('form')
.send(credentials);
.send(secretCredentials);

// get the access token from the response body
const getAccessToken = body => body.accessToken || body.access_token;
Expand Down