Skip to content

Commit bd8deb2

Browse files
authored
update code snippet, remove outdated api references
------- cc: @OwenRichards1
1 parent b7a6bcc commit bd8deb2

File tree

1 file changed

+9
-44
lines changed

1 file changed

+9
-44
lines changed

articles/active-directory/develop/msal-js-pass-custom-state-authentication-request.md

Lines changed: 9 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -20,58 +20,23 @@ ms.custom: aaddev
2020

2121
The *state* parameter, as defined by OAuth 2.0, is included in an authentication request and is also returned in the token response to prevent cross-site request forgery attacks. By default, the Microsoft Authentication Library for JavaScript (MSAL.js) passes a randomly generated unique *state* parameter value in the authentication requests.
2222

23-
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:
23+
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](https://azuread.github.io/microsoft-authentication-library-for-js/ref/modules/_azure_msal_browser.html#redirectrequest) object. For example:
2424

2525
```javascript
26-
// Request type
27-
export type AuthenticationParameters = {
28-
scopes?: Array<string>;
29-
extraScopesToConsent?: Array<string>;
30-
prompt?: string;
31-
extraQueryParameters?: QPDict;
32-
claimsRequest?: string;
33-
authority?: string;
34-
state?: string;
35-
correlationId?: string;
36-
account?: Account;
37-
sid?: string;
38-
loginHint?: string;
39-
forceRefresh?: boolean;
40-
};
41-
```
42-
43-
> [!Note]
44-
> If you would like to skip a cached token and go to the server, please pass in the boolean `forceRefresh` into the AuthenticationParameters object used to make a login/token request.
45-
> `forceRefresh` should not be used by default, because of the performance impact on your application.
46-
> Relying on the cache will give your users a better experience.
47-
> Skipping the cache should only be used in scenarios where you know the currently cached data does not have up-to-date information.
48-
> Such as an Admin tool that adds roles to a user that needs to get a new token with updated roles.
26+
import {PublicClientApplication} from "@azure/msal-browser";
4927

50-
For example:
28+
const myMsalObj = new PublicClientApplication({
29+
clientId: "ENTER_CLIENT_ID_HERE"
30+
});
5131

52-
```javascript
5332
let loginRequest = {
54-
scopes: ["user.read", "user.write"],
33+
scopes: ["user.read"],
5534
state: "page_url"
5635
}
5736

58-
myMSALObj.loginPopup(loginRequest);
37+
myMSALObj.loginRedirect(loginRequest);
5938
```
6039

61-
The passed in state is appended to the unique GUID set by MSAL.js when sending the request. When the response is returned, MSAL.js checks for a state match and then returns the custom passed in state in the `Response` object as `accountState`.
62-
63-
```javascript
64-
export type AuthResponse = {
65-
uniqueId: string;
66-
tenantId: string;
67-
tokenType: string;
68-
idToken: IdToken;
69-
accessToken: string;
70-
scopes: Array<string>;
71-
expiresOn: Date;
72-
account: Account;
73-
accountState: string;
74-
};
75-
```
40+
The passed in state is appended to the unique GUID set by MSAL.js when sending the request. When the response is returned, MSAL.js checks for a state match and then returns the custom passed in state in the [Response](https://azuread.github.io/microsoft-authentication-library-for-js/ref/modules/_azure_msal_common.html#authenticationresult) object as `state`.
7641

77-
To learn more, read about [building a single-page application (SPA)](scenario-spa-overview.md) using MSAL.js.
42+
To learn more, read about [building a single-page application (SPA)](scenario-spa-overview.md) using MSAL.js.

0 commit comments

Comments
 (0)