I have implemented Azure SSO using open ID connect, I am redirecting a user to the homepage of my portal once he is logged in using an office account.
The problem is since the redirect URL(localhost:443/abc/test.aspx) is a constant that we have to put, I could not figure out how to retain a URL where a user was before login (e.g. localhost:443/abc/test.aspx#/item/30176). After SSO login it redirect me to only localhost:443/abc/test.aspx, I want to land to localhost:443/abc/test.aspx#/item/30176 (30176 is variable item id)
If state is the only way to go. I could not find how to use it. Any references of implementation would really be helpful
• You can surely use the ‘state’ parameter for this purpose to redirect the user after successful authentication to the same page before login, but it needs to be configured in the authentication request that is sent in ‘MSAL.js’ script. The state parameter can also be used to encode information of the app's state before redirect. You can pass the user's state in the app, such as the page or view they were on, as input to this parameter. The MSAL.js library allows you to pass your custom state as state parameter in the Request object as below: -
// Request type
export type AuthenticationParameters = {
scopes?: Array<string>;
extraScopesToConsent?: Array<string>;
prompt?: string;
extraQueryParameters?: QPDict;
claimsRequest?: string;
authority?: string;
state?: string;
correlationId?: string;
account?: Account;
sid?: string;
loginHint?: string;
forceRefresh?: boolean;
};
You can refer the below documentation links for more details on including this parameter in the Azure AD B2C redirect links: -
https://learn.microsoft.com/en-us/azure/active-directory-b2c/authorization-code-flow