Skip to content
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

Auth0 authentication #79

Open
larryg01 opened this issue Aug 13, 2021 · 16 comments
Open

Auth0 authentication #79

larryg01 opened this issue Aug 13, 2021 · 16 comments
Labels
enhancement New feature or request question Further information is requested

Comments

@larryg01
Copy link

larryg01 commented Aug 13, 2021

How can I use OAuth / ("Bearer " + token) authentication with Pactumjs, I can use basic username and password authentication just not find a way to use Auth0. Any help would be much appreciated.

@ASaiAnudeep
Copy link
Member

We can use withHeaders method to pass Bearer token.

const token = 'abc';

await pactum.spec()
  .get('<url>')
  .withHeaders('Authorization', `Bearer ${token}`)
  .expectStatus(200)

@ASaiAnudeep ASaiAnudeep added the question Further information is requested label Aug 13, 2021
@klassijs
Copy link

Would it be the same process for all these other auth methods as well: Digest, NTLM, API Keys, OAuth, HAWK etc

@ASaiAnudeep
Copy link
Member

Would it be the same process for all these other auth methods as well: Digest, NTLM, API Keys, OAuth, HAWK etc

Yes, for now. Currently the library doesn't have dedicated methods for handling different authentication methods. But we are open to add custom capabilities for the same.

@larryg01
Copy link
Author

larryg01 commented Aug 16, 2021

I am having problems and getting lots of errors trying to implement this:

await pactum.spec()
.get('url')
.withHeaders('Authorization', 'username=john + password=test')
.expectStatus(200)

Is that the correct implementation i have tried different variations but still no luck. Any help would be greatly appreciated

@larryg01 larryg01 reopened this Aug 16, 2021
@ASaiAnudeep
Copy link
Member

Are you able to make the same request in Postman? If you can, please capture the header value & use it in pactum headers.

@larryg01
Copy link
Author

I ca get it working with
.withHeaders('Authorization', Bearer ${token})
but not with
.withAuth(username, password)

@ASaiAnudeep
Copy link
Member

withAuth is for basic authentication. It won't work for bearer.

Examples

Using Headers

await pactum.spec()
  .get('<url>')
  .withHeaders('Authorization', 'Basic ' + Buffer.from(username + ':' + password).toString('base64'))
  .expectStatus(200)

Using withAuth

await pactum.spec()
  .get('<url>')
  .withAuth(username, password)
  .expectStatus(200)

@vijay-jaisankar
Copy link

This worked for Bearer Token
expected.reportData_body is a String formatted as JSON and bearerToken is a String too.

it("Check status code for TimePeriod.", async () => {
    const DTBody = expected.reportData_body;
    await pactum
        .spec()
        .post("http://localhost:3000/timeperiod")
        .withHeaders("Authorization", `Bearer ${bearerToken}`)
        .withBody(DTBody)
        .expectStatus(200);
});

@larryg01
Copy link
Author

Thanks for posting

@larryg01
Copy link
Author

I am fighting with getting it to work where the auth is part of the url?
i.e https://username:[email protected]

@larryg01 larryg01 reopened this Sep 10, 2021
@ASaiAnudeep
Copy link
Member

Not sure how to use basic auth as part of the URL. Raised an issue for the same in phin.

As a workaround we can use withAuth method.

Working

await pactum.spec()
  .get('https://the-internet.herokuapp.com/basic_auth')
  .withAuth('admin', 'admin')

Not Working

await pactum.spec()
  .get('https://admin:[email protected]/basic_auth')

@vijay-jaisankar
Copy link

Alternatively, if you're using JWT, you may send the username and password as JSON to your "verifier" route.

withAuth() seems too overpowered though :)

@larryg01
Copy link
Author

As a workaround we can use withAuth method.

await pactum.spec()
  .get('https://the-internet.herokuapp.com')
  .withAuth('admin', 'admin')

This worked for me Thank you very much.
Its a great tool but I have to admit the Doc needs some serious updating to avoid the 10000 questions.

@ASaiAnudeep ASaiAnudeep added the enhancement New feature or request label Sep 25, 2021
@larryg01
Copy link
Author

Do you have any updates with reference to using different types of Auth methods (i.e. Digest in particular) ?

@ASaiAnudeep
Copy link
Member

I have never worked on the Digest authentication method. It would be great, if you can give us a sample working code written with phin.

@larryg01
Copy link
Author

I am struggling to get it to work with aws Signature its working in postman but not in Pactum is there something am missing?
Any help would be greatly appreciated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants