-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
State parameter in login request #262
Comments
Hi @AnnaShk, Currently msal library is generating the state parameter in the constructor of AuthenticationRequestParameters. |
Hi @nehaagrawal, Thanks for that. Yes, the state parameter is, as you say, passing a new GUID to the Azure login page, but according to this page, there are two potential uses for the state parameter:
So our understanding is that, critically, the state parameter is preserved through the authentication process. We need to use the state parameter for the second scenario (perhaps in addition to the first), where we want to add our own value to be preserved and appended to the redirect_uri when the user is authenticated. As a simple example (ignoring the CSRF GUID for a moment), we might send a unique link to a potential new user, identifying them in an existing customer database: https://mysite.example.com/signup?customer_id=12345 We want the ID to be preserved through the authentication process so we can link the new B2C user to our existing customer record, and our understanding is that we should use the state parameter for this: so we should be able to grab the customer_id parameter in the original URL and stuff it into state: GET https://login.microsoftonline.com/mysite.onmicrosoft.com/oauth2/v2.0/authorize?client_id=90c0fe63-bcf2-44d5-8fb7-b8bbc0b29dc6&response_type=code&redirect_uri=https%3A%2F%2Fmysite.example.com%2Fwelcome&response_mode=query&scope=90c0fe63-bcf2-44d5-8fb7-b8bbc0b29dc6%20offline_access&state=12345&p=b2c_1_sign_up Then the user on successful signup and authentication would be redirected to: https://mysite.example.com/welcome?state=12345 We can then associate the newly created oid with their internal customer_id (note we won't be using the actual customer ID, rather a known unique GUID representing them). Another scenario might be that the user clicks on a link to a specific page, we URL encode that page in the state parameter and redirect the user back to that page after they are authenticated. Are we thinking about this the wrong way? It seems like this is a fairly fundamental use case for the state parameter, but unless we can either modify the state parameter or use some other parameter that is preserved through the authentication process, we can't achieve what I've outlined above. Thanks. |
@AnnaShk we have acknowledged this issue as an enhancement. |
Hi @nehaagrawal, Thank you for the update. I've tried to make this change on my side, and added state parameter as part of
Changes: Is this a good/safe solution? Thanks |
@AnnaShk Thanks for Pull Request. We are currently reviewing your change. There are some enhancements that needs to be done. I will add comment in your Pull Request. |
Hello @nehaagrawal. I made the code changes you mentioned above and added state parameter as part of UserAgentApplication options. The new client object now is
The state parameter which I pass is not preserved through the authentication process. If I don't pass my own state parameter, everything works fine. I need that state parameter to be preserved for the similar reason mentioned by @AnnaShk. Could you please help me with this? |
Is there currently any way to pass additional state when we trigger a loginRedirect ? If not, what is the recommended approach to handle a return URL ? Since the Open ID redirect URI is fixed, we have to put that information somewhere. |
I’ve been storing the ‘original uri that initiated the login request’ in session storage. When I get returned from B2C authentication, I’m logged in, everything’s been successful, I finally return to the url that initiated the request that has been saved in session storage. |
This method seems to have a minor drawback though. If the login is initiated from 2 different tabs, the last tab overwrites the redirect URL of the first one. Also, couldn't it be an attack vector for a malicious script hijacking your redirection URL (e.g. launching an 1px <iframe> pointing to your site from a malicious web page, thereby forcing all your redirections to a URI of their choosing (inside your website) ? |
Hi @AnnaShk , What is the status of your PR? The use case you described also apply to us and it seems to me it should be an expected behaviour. Thanks! |
* issue #262 state parameter in login request * added test cases * removed unused code * updated test cases * updated release version for msal-core
* Update config params in Readme * Na/release changes (#372) * Clean up of Readmes for msal core, angularjs and angular - Added contributing guide - Added advanced topics in readmes * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * fixed public apis visibility * fixed hashbang url issue * fixed test cases * renamed anonymous endpoint to unprotected resource * removing package.lock.json * updated msal-core version to 0.2.0 * Updated readme * Deleting package.lock.json * updated msal-angular sample * Removed code coverage from msal-core and fixed aot compilation for msal-angular * Added state parameter in login request * issue #262 state parameter in login request * added test cases * removed unused code * updated test cases * updated release version for msal-core
@AnnaShk @rendmath @qbodart @simonneedham @SujitGodavarti This is fixed and released in msal-core 0.2.1. I am closing this issue. |
* Added state parameter in login request for msal-core. * Update config params in Readme * Na/release changes (#372) * Clean up of Readmes for msal core, angularjs and angular - Added contributing guide - Added advanced topics in readmes * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * fixed public apis visibility * fixed hashbang url issue * fixed test cases * renamed anonymous endpoint to unprotected resource * removing package.lock.json * updated msal-core version to 0.2.0 * Updated readme * Deleting package.lock.json * updated msal-angular sample * Removed code coverage from msal-core and fixed aot compilation for msal-angular * Added state parameter in login request * issue #262 state parameter in login request * added test cases * removed unused code * updated test cases * updated release version for msal-core * changes for msal-angular and msal-angularjs 0.1.1 release
* Update config params in Readme * Na/release changes (#372) * Clean up of Readmes for msal core, angularjs and angular - Added contributing guide - Added advanced topics in readmes * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * fixed public apis visibility * fixed hashbang url issue * fixed test cases * renamed anonymous endpoint to unprotected resource * removing package.lock.json * updated msal-core version to 0.2.0 * Updated readme * Deleting package.lock.json * updated msal-angular sample * Removed code coverage from msal-core and fixed aot compilation for msal-angular * Added state parameter in login request * issue #262 state parameter in login request * added test cases * removed unused code * updated test cases * updated release version for msal-core * Msal-angular AOT fix. * Added state parameter in login request for msal-core. * Update config params in Readme * Na/release changes (#372) * Clean up of Readmes for msal core, angularjs and angular - Added contributing guide - Added advanced topics in readmes * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * fixed public apis visibility * fixed hashbang url issue * fixed test cases * renamed anonymous endpoint to unprotected resource * removing package.lock.json * updated msal-core version to 0.2.0 * Updated readme * Deleting package.lock.json * updated msal-angular sample * Removed code coverage from msal-core and fixed aot compilation for msal-angular * Added state parameter in login request * issue #262 state parameter in login request * added test cases * removed unused code * updated test cases * updated release version for msal-core * changes for msal-angular and msal-angularjs 0.1.1 release
* Update config params in Readme * Na/release changes (#372) * Clean up of Readmes for msal core, angularjs and angular - Added contributing guide - Added advanced topics in readmes * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * fixed public apis visibility * fixed hashbang url issue * fixed test cases * renamed anonymous endpoint to unprotected resource * removing package.lock.json * updated msal-core version to 0.2.0 * Updated readme * Deleting package.lock.json * updated msal-angular sample * Removed code coverage from msal-core and fixed aot compilation for msal-angular * Added state parameter in login request * issue #262 state parameter in login request * added test cases * removed unused code * updated test cases * updated release version for msal-core * Msal-angular AOT fix. * Added state parameter in login request for msal-core. * Update config params in Readme * Na/release changes (#372) * Clean up of Readmes for msal core, angularjs and angular - Added contributing guide - Added advanced topics in readmes * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * fixed public apis visibility * fixed hashbang url issue * fixed test cases * renamed anonymous endpoint to unprotected resource * removing package.lock.json * updated msal-core version to 0.2.0 * Updated readme * Deleting package.lock.json * updated msal-angular sample * Removed code coverage from msal-core and fixed aot compilation for msal-angular * Added state parameter in login request * issue #262 state parameter in login request * added test cases * removed unused code * updated test cases * updated release version for msal-core * changes for msal-angular and msal-angularjs 0.1.1 release * update readme updated the angular version we support. * IE and edge fix. * added fix for IE and edge for msal-core and msal-angularjs * deleted package-lock.json * added release details * added Null pointer check * updated msal-core version * removed fix in msal-angularjs * Fixed the explanation for storeAuthStateInCookie * updated change log for ie/edge issue * updated the change log on IE/Edge fix
Hi,
Could you please help me to find you how can I use the state parameter with msal?
How can I send state value in the request(loginRedirect), so it will be returned in the token response?
Here is my current UserAgentApplication:
and login:
clientApplication.loginRedirect(b2cScopes);
I see some state parameter exists in POST SelfAsserted request Referer.
Here is a link to state parameter explanation.
Thanks.
The text was updated successfully, but these errors were encountered: