Skip to content
New issue

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

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

Already on GitHub? # to your account

how to add basic auth #380

Open
nils-hoyer opened this issue Aug 14, 2017 · 3 comments
Open

how to add basic auth #380

nils-hoyer opened this issue Aug 14, 2017 · 3 comments

Comments

@nils-hoyer
Copy link

i want to add basic auth for get and post requests. I assume globalSetup() createWithAction() will be the right place, but i have no idea how to parse the information correctly.

@vlucas
Copy link
Owner

vlucas commented Aug 15, 2017

Actually I would like to add an auth method back on Frisby like v0.x had to make this easier. It would just use setup internally on the single test, so it would be a method on FrisbySpec.

@benrobey
Copy link

Shouldn't you be able to just add a header? Such as:

frisby.get(url + 'user/search/{query}', { headers: { "Authorization": 'My auth here' }}) .expect('status', 200) .expect('jsonTypes', 'data.?', scheme) .expect('header', 'content-type', 'application/json')

@H1Gdev
Copy link
Collaborator

H1Gdev commented Nov 15, 2017

Hi everyone.

If basic authentication, can test like following code.
(user: user, password: passwd)

const frisby = require('frisby');

it('auth test', function (done) {
  frisby.get('https://user:passwd@httpbin.org/basic-auth/user/passwd')
    .expect('status', 200)
    .done(done);
});

or

const frisby = require('frisby');
const url = require('url');

it('auth test(2)', function (done) {
  // use Legacy URL API.
  var myURL = url.parse('https://httpbin.org/basic-auth/user/passwd');
  myURL.auth = 'user:passwd';
  frisby.get(url.format(myURL))
    .expect('status', 200)
    .done(done);
});

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

5 participants