Google Authentication with Cypress #27322
Unanswered
mboban22
asked this question in
Questions and Help
Replies: 1 comment
-
As additional context for this issue; the users that are subject to this authentication workflow have MFA enforced, and the app that our colleague is using is behind Google's Identity Aware Proxy. We are keen to explore this flow running as a service account rather than a user if possible, and can see a couple of resources that may steer in this direction. https://github.com/onXmaps/cypress-iap and https://www.infitialis.com/2021/03/09/cypress-google-iap-service-accounts/. Any assistance you could provide to the OP would be greatly appreciated, thank you. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
The app works in this way - The user will redirect to google authentication screen on hitting url and then redirect to app on successful authentication.
I used the same code in https://docs.cypress.io/guides/end-to-end-testing/google-authentication for google authentication step.
Cypress.Commands.add('loginByGoogleApi', () => { cy.request({ method: 'POST', url: 'https://www.googleapis.com/oauth2/v4/token', body: { grant_type: 'refresh_token', client_id: Cypress.env('googleClientId'), client_secret: Cypress.env('googleClientSecret'), refresh_token: Cypress.env('googleRefreshToken'), }, }).then(({ body }) => { const { access_token, id_token } = body cy.request({ method: 'GET', url: 'https://www.googleapis.com/oauth2/v3/userinfo', headers: { Authorization:
Bearer ${access_token}}, }).then(({ body }) => { cy.log(body) const userItem = { token: id_token, user: { googleId: body.sub, email: body.email, givenName: body.given_name, familyName: body.family_name, imageUrl: body.picture, }, } window.localStorage.setItem('googleCypress', JSON.stringify(userItem)) cy.visit('/') }) }) })
But when running test, it is still redirecting to google sign in screen. I was expecting that user would land on home page.
Could you please advise why this is not working? am I missing something?
"cypress": "^12.17.1"
Beta Was this translation helpful? Give feedback.
All reactions