restoauth-2.0codeceptjs

How do I test the API using REST + CodeceptJS, access to which is protected with Auth0?


I want to use the REST helper (for CodeceptJS) to write automated tests for API

The difficulty lies in the fact that access to the API is protected by OAuth2.

If someone had experience passing OAuth2 authorization to write autotests using REST + CodeceptJS, I would be very grateful if you could tell me about your case


Solution

  • You can add a default header in your helper as below with OAuth2 :

    REST: {
          endpoint: 'https://baseurl/endpoint',
          defaultHeaders:{
            Authorization: 'Bearer xxxtoken'
          },
        },