cypress-example-recipes icon indicating copy to clipboard operation
cypress-example-recipes copied to clipboard

Auth0 recipe?

Open dandv opened this issue 5 years ago • 9 comments
trafficstars

I've just filed https://github.com/cypress-io/cypress-documentation/issues/2872 before seeing this repo, but not sure if the issue belongs here better? Feel free to close in either place.

I was trying to test pages behind a login gate using Auth0, and didn't find anything in the Cypress docs. Found these 3rd party blog posts:

  • https://auth0.com/blog/end-to-end-testing-with-cypress-and-auth0/ - from Auth0 but 1.5 years old
  • https://sandrino.dev/blog/writing-cypress-e2e-tests-with-auth0 - unofficial

dandv avatar Jun 10 '20 19:06 dandv

@dandv we're actually working on this in addition to other vendors such as AWS Cognito (also Amplify). I will update folks here.

cc @kevinold

amirrustam avatar Jun 10 '20 20:06 amirrustam

Hi, any updates on this? The official Auth0 writeup has a lot of issues.

dandv avatar Jun 27 '20 23:06 dandv

@dandv Are you able to provide specifics about your setup? For instance, are you using Auth0 with a Node backed, SPA or SPA served by Node backend? Any additional details are helpful as we prepare documentation on these scenarios. Thanks!

kevinold avatar Jun 29 '20 14:06 kevinold

Hi @kevinold, I'm using what I think is a pretty common setup, a React SPA that allows Auth0 login with user/pass + social connections, and accesses an API written in Node.js and secured using JWTs.

If it helps with same-site cookies or whatnot, I'm using an Auth0 Custom Domain.

dandv avatar Jun 29 '20 20:06 dandv

@amirrustam Any update on the AWS Cognito example you referred to? We use this for login and are investigating how to get cypress.io tests to login automatically.

nathfy avatar Sep 07 '20 09:09 nathfy

Hi @nathfy, refer to this draft guide for a programmatic AWS Cognito solution - https://gist.github.com/kevinold/cfcf308c1827f07f17055e8572973216#login-to-amazon-cognito-via-api

In addition, a draft branch integrating AWS Cognito as an authentication provider into the Cypress Real World App is located here: https://github.com/cypress-io/cypress-realworld-app/compare/kevin/aws-cognito. This uses AWS Amplify CLI to orchestrate the creation of the AWS Cognito resources.

kevinold avatar Sep 08 '20 13:09 kevinold

A draft of an Auth0 Guide is located here: https://gist.github.com/kevinold/31dbbebd1cb75f311d798f5bc81574a4

In addition, a programmatic command for login to Auth0 is located on this branch in the Cypress Real World App: https://github.com/cypress-io/cypress-realworld-app/tree/kevin/auth0-programmatic-login

kevinold avatar Sep 08 '20 13:09 kevinold

@kevinold thank you for providing with an option on how to handle authentication.

Let me please share some thoughts, so possible inefficiencies from the gist are not added in the official example from the cypress team. Problems in the gist example that should be solved:

  • a developer shouldn't define a task to authenticate every time
    • could be solved by wrapping a cypress test
  • authentication should happen only if the authentication state persisted to disk is expired or invalid
    • you should consider to persist the authentication state to disk and only authenticate when the token is expired
      • instead of authentication requests for every test

o-alexandrov avatar Sep 08 '20 13:09 o-alexandrov

Is there any way we can test also signup functionalities?

frivolta avatar Sep 15 '20 16:09 frivolta