Skip to content

Fix passing secrets to OAuth & Basic Auth: #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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