juunas11 / AzureAdUiTestAutomation

Examples of running UI tests on an Azure AD protected single page app that calls an Azure AD protected API
33 stars 16 forks source link

Auth issue on Azure Ad uiTest application automation. #1

Open Imamitashish opened 2 years ago

Imamitashish commented 2 years ago

Thank you for a wonderful code and process learning to use Azure AD and generating token to login to React applications. we are seeing a issue after we put the client id, secrets and other details where the part of the URL which does not match the actual URL generated. Can you help us with the error.

URL before we login to react app and authorization token is generated.

https://login.microsoftonline.com/tenant_id/oauth2/v2.0/authorize?client_id=client_id&scope=api_scope%2FRead%20openid%20profile%20offline_access&redirect_uri=https%3A%2F%2Fuiptest.fti-cloud.com&client-request-id=client-request-id&response_mode=fragment&response_type=code&x-client-SKU=msal.js.browser&x-client-VER=2.18.0&x-client-OS=&x-client-CPU=&client_info=1&code_challenge=gkLAk_UiZBzyt-0dA5xOtuWICklY4YAgLQuNgBNC8Cw**&**code_challenge_method=S256&nonce=dc8b80a3-8291-4206-b351-83c6bdea5b0c&state=eyJpZCI6ImFhNDFmMDZjLWNiY2ItNGQ3NC1iZDRjLWZkMGNmZGNhMDgwNCIsIm1ldGEiOnsiaW50ZXJhY3Rpb25UeXBlIjoicmVkaXJlY3QifX0%3D%7C%2Fportfolios%2Fsummary**&sso_reload=true

URL Generated from the code of Azure Ad uiTest Automation**

https://login.microsoftonline.com/tenant id/oauth2/v2.0/authorize?client_id=client_id&scope=api_scope%2FRead%20openid%20profile%20offline_access&redirect_uri=https%3A%2F%2Fuiptest.fti-cloud.com&client-request-id=client-request-id&response_mode=fragment&response_type=code&x-client-SKU=msal.js.browser&x-client-VER=2.18.0&x-client-OS=&x-client-CPU=&client_info=1&codechallenge=A74xunmr537AgM6e9H386STibM5uEc2p6GW67xfyLZk&codechallenge_method=S256&nonce=979776b5-f362-48de-a004-a74467ab64df&state=eyJpZCI6ImExMjlhMzdiLTA3MDctNDBhMC05ZTE3LWE0OGM0ODg0NjNjNCIsIm1ldGEiOnsiaW50ZXJhY3Rpb25UeXBlIjoicmVkaXJlY3QifX0%3D&sso_reload=true

Difference is from the challenge code, we are new to react and authorizations, can you help us with the resolution. Thank you for your support and time.

malazo commented 2 years ago

HI, wonderfull job on the video explanation. I'm having a problem with the authentication. When i do the login everything works, but i get redirected to the microsoft ad portal to type the user and password. I think that this is not the expected behavior. Thanks a lot.

juunas11 commented 2 years ago

There is a possibility that the storage format has changed in some way for MSAL.js and that would mean it does not correctly recognize the cached tokens injected by the tests. I won't have time to check this right now but at some point I will.

malazo commented 2 years ago

HI @juunas11 . Thanks for your response. The problem was related with missing information that was saved in localstorage so msal does not recognize it because I was using and old tenant(created a long time ago when was in beta) and the information in the token was different. All the explanation is here: https://stackoverflow.com/questions/72529561/cypress-azuread-login-always-redirects-outside-the-cypress-window/72576632#72576632 . Thanks again for your quick response