Automated authentication using cypress with organization and PKCE

This is really driving me crazy.

I’m trying to implement automated tests on my vue frontend app using cypress.

I read and used all articles I collected on the topic like this one or that one.

Then I realized what made it different is that we use organizations and grant_type=authorization_code so I read deeply this topic from this forum.
I also have been told by a team member that we use PKCE, so I followed the dedicated page.

In the end, I build a request with the following parameters:

{
    response_type: 'code',
    code_challenge,
    code_challenge_method: 'S256',
    client_id,
    redirect_uri,
    scope,
    state,
    organization,
}

which looks like:

https://APP_SLUG.eu.auth0.com/authorize?response_type=code&code_challenge=CODE_CHALLENGE&code_challenge_method=S256&client_id=CLIENT_ID&redirect_uri=http://frontend:3000/login/callback&scope=openid%20profile%20email%20offline_access&state=whatever&organization=org_ORGANIZATION_ID

But then all articles/tutorials/posts seem to agree that fetching /authorize with response_type=code would redirect to /callback?code=MY_CODE

But in my case (I tried within cypress, with curl and with the browser), I get redirected to /u/login?state=STATE:

HTTP/2 302 
location: /u/login?state=hqFo2SBxNlB5TGFvZlc0UmJ6eHVIZDF4ZGJFUC05aW5KSmpFdKFur3VuaXZlcnNhbC1sb2dpbqN0aWTZIHVicVRkaTFEX2MwMUlIcVJpRk41cjlVdmJuajV4QU5Co2NpZNkgNVJMS0RWOFVNek1BZGI2elFiT3FYbjFmUm9lTlRNSTWlb3GnaWS0b3JnXXdxdFBSZHRHZmg5a2s1Nkqnb3JnbmFtZa5taWNyb3NvZnQtZGVtbw

which is the auth0 login screen, which is not what I want…

And if I do authenticate manually on the /u/login screen, then I get redirected to my /callback?code=MY_CODE but then I’m loosing the benefits of automation.

What am I doing wrong?? :face_exhaling: Is there something to activate/deactivate to receive the code and THEN submit the authentication credentials to /oauth/token?

I tried multiple options in auth0 config, created a dedicated application for this, nothing worked :unamused:

Thanks a lot for support :hugs:

1 Like

Anyone can help? :face_with_spiral_eyes:

I’m completely stuck here !