Last active
January 3, 2020 15:59
-
-
Save dwilhel1/9b88b8932840707d27e0a63968ea62b4 to your computer and use it in GitHub Desktop.
Example test for auth0 with Cypress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('Authentication with auth0', () => { | |
it('should successfully login to our app', () => { | |
cy.login() | |
.then(resp => resp.body) | |
.then((body) => { | |
const { access_token, expires_in, id_token } = body; | |
const auth0State = { | |
nonce: '', | |
state: 'some-random-state', | |
}; | |
const callbackUrl = `/callback#access_token=${access_token}&scope=openid&id_token=${id_token}&expires_in=${expires_in}&token_type=Bearer&state=${auth0State.state}`; | |
cy.visit(callbackUrl, { | |
onBeforeLoad(win) { | |
// eslint-disable-next-line no-param-reassign | |
win.document.cookie = `com.auth0.auth.some-random-state=${JSON.stringify(auth0State)}`; | |
// eslint-disable-next-line no-param-reassign | |
win.document.cookie = 'auth0.is.authenticated=true'; | |
}, | |
}); | |
}); | |
cy.visit('/'); | |
cy.get('body').should('contain', 'Home'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment