AzureAD / microsoft-authentication-library-for-java

Microsoft Authentication Library (MSAL) for Java http://aka.ms/aadv2
MIT License
285 stars 142 forks source link

How to add http parameters to Redirect URI? #745

Closed kilokili777 closed 10 months ago

kilokili777 commented 11 months ago

We are using the MSAL java servlet example, and SSO works great. However, if we authenticate with query parameters, the authentication completes, but the query parametes are stripped off when the Redirect URI is called. Is there any way to pass through the query parameter when Redirecting? Example Redirect URI = https://myserver.com/cpa/index.html BUT called with == https://myserver.com/cpa/index.html?code=123&id=456

Avery-Dunn commented 11 months ago

Hello @kilokili777 : Where are you setting this redirect URI? Is this the URI set in the Azure app, or is it the loopback address option in the interactive flow: https://github.com/AzureAD/microsoft-authentication-library-for-java/blob/d4b5096f9e7926fb491978b45599dc96b46f8f83/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/InteractiveRequestParameters.java#L40

Since you're using the servlet sample as a base, this might be a quirk of Azure or an issue with the sample rather than an issue in MSAL Java itself.

bgavrilMS commented 11 months ago

@kilokili777 - can you describe what you are trying to do? Are you trying to ensure the user is redirected back to the exact route he started from after they are authenticated? Would you not be able to use the session ID for this?

The sample adds a parameter called "state" to the authorization URI, see https://github.com/Azure-Samples/ms-identity-msal-java-samples/blob/main/3-java-servlet-web-app/1-Authentication/sign-in/src/main/java/com/microsoft/azuresamples/msal4j/helpers/AuthHelper.java#L116

Then when the auth completes, the sample extracts the auth code and checks that the state parameter is the same - https://github.com/Azure-Samples/ms-identity-msal-java-samples/blob/main/3-java-servlet-web-app/1-Authentication/sign-in/src/main/java/com/microsoft/azuresamples/msal4j/helpers/AuthHelper.java#L136

You should be able to use this to add more details, but make sure to add a unique identifier in it. Also ensure that the state isn't too long, or you get into URL size issues.