Question

Oauth2 in testing

  • 23 February 2024
  • 1 reply
  • 42 views

I am struggling to understand how to authenticate via oauth2 in testing with Zapier CLI.

 

Initially I was using Platform UI and was able to authenticate via oauth2 just fine. Then I found a need to swap to CLI and have had issues with oauth2.

 

The issue seems to be 2 things:

  1. When visiting my website to authorise the oauth2 I have to log in via session so that my website knows which user account to authorise for oauth2. How do I authenticate in tests? I can’t work out a way of authenticating first and then continuing with the oauth2 flow. This is particularly confusing as in production I won’t need to authenticate first as this will be already done by the session cookie.
  2. Even if I can get the tests to authenticate first. How then do I authorise the oauth2? On my website you have to click a button to accept the authorisation. How is this done in tests?

1 reply

As far as I can tell, I need to get the authorisation code from my API somehow. This is easy when using the website graphically.

I just can’t workout how to do this from inside a test.

In the oauth2 example on GitHub it has a comment stating that in production the authorization code will be provided by the flow, which is obvious.

inputData: {
// In production, Zapier passes along whatever code your API set in the query params when it redirects
// the user's browser to the `redirect_uri`
code: 'one_time_code',
},

Link to code here

But what about in testing? How do I retrieve the authorization code without a graphical interface.

Reply