Skip to content

Commit 0c859a8

Browse files
committed
bump msal
1 parent 72fe1bb commit 0c859a8

File tree

25 files changed

+150
-400
lines changed

25 files changed

+150
-400
lines changed

1-Authentication/1-sign-in/SPA/package-lock.json

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

1-Authentication/1-sign-in/SPA/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
"@angular/platform-browser": "~11.0.0",
2222
"@angular/platform-browser-dynamic": "~11.0.0",
2323
"@angular/router": "~11.0.0",
24-
"@azure/msal-angular": "^2.0.0-beta.0",
25-
"@azure/msal-browser": "^2.12.0",
24+
"@azure/msal-angular": "^2.0.0-beta.3",
25+
"@azure/msal-browser": "^2.13.1",
2626
"core-js": "^3.8.0",
2727
"rxjs": "~6.6.0",
2828
"tslib": "^2.0.0",

1-Authentication/2-sign-in-b2c/README-incremental.md

Lines changed: 0 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -282,99 +282,6 @@ For more information, see: [Events in MSAL Angular v2](https://github.com/AzureA
282282

283283
This user-flow allows your users to sign-in to your application if the user has an account already, or sign-up for an account if not. This is the default user-flow that we pass during the initialization of MSAL instance.
284284

285-
- **Password reset**
286-
287-
When a user clicks on the **forgot your password?** link during sign-in, **Azure AD B2C** will respond with an error. To initiate the password reset user-flow, we need to catch this error and handle it by sending another login request with the corresponding password reset authority string (e.g. `B2C_1_reset`).
288-
289-
```typescript
290-
export class AppComponent implements OnInit, OnDestroy {
291-
292-
private readonly _destroying$ = new Subject<void>();
293-
294-
constructor(
295-
@Inject(MSAL_GUARD_CONFIG) private msalGuardConfig: MsalGuardConfiguration,
296-
private authService: MsalService,
297-
private msalBroadcastService: MsalBroadcastService
298-
) {}
299-
300-
ngOnInit(): void {
301-
this.msalBroadcastService.msalSubject$
302-
.pipe(
303-
filter((msg: EventMessage) => msg.eventType === EventType.LOGIN_FAILURE || msg.eventType === EventType.ACQUIRE_TOKEN_FAILURE),
304-
takeUntil(this._destroying$)
305-
)
306-
.subscribe((result: EventMessage) => {
307-
if (result.error instanceof AuthError) {
308-
// Check for forgot password error
309-
// Learn more about AAD error codes at https://docs.microsoft.com/azure/active-directory/develop/reference-aadsts-error-codes
310-
if (result.error.message.includes('AADB2C90118')) {
311-
312-
// login request with reset authority
313-
let resetPasswordFlowRequest = {
314-
scopes: ["openid"],
315-
authority: b2cPolicies.authorities.forgotPassword.authority,
316-
};
317-
318-
this.login(resetPasswordFlowRequest);
319-
}
320-
}
321-
});
322-
}
323-
324-
login(userFlowRequest?: RedirectRequest | PopupRequest) {
325-
if (this.msalGuardConfig.interactionType === InteractionType.Popup) {
326-
if (this.msalGuardConfig.authRequest) {
327-
this.authService.loginPopup({...this.msalGuardConfig.authRequest, ...userFlowRequest} as PopupRequest)
328-
.subscribe((response: AuthenticationResult) => {
329-
this.authService.instance.setActiveAccount(response.account);
330-
});
331-
} else {
332-
this.authService.loginPopup(userFlowRequest)
333-
.subscribe((response: AuthenticationResult) => {
334-
this.authService.instance.setActiveAccount(response.account);
335-
});
336-
}
337-
} else {
338-
if (this.msalGuardConfig.authRequest){
339-
this.authService.loginRedirect({...this.msalGuardConfig.authRequest, ...userFlowRequest} as RedirectRequest);
340-
} else {
341-
this.authService.loginRedirect(userFlowRequest);
342-
}
343-
}
344-
}
345-
346-
ngOnDestroy(): void {
347-
this._destroying$.next(undefined);
348-
this._destroying$.complete();
349-
}
350-
}
351-
```
352-
353-
We need to reject ID tokens that were not issued with the default sign-in policy (e.g. `B2C_1_SUSI`). After the user resets her password and signs-in again, we will force a logout and prompt for login again (with the default sign-in policy). To do this, register another event in [app.component.ts](./SPA/src/app/app.component.ts) as shown below:
354-
355-
```typescript
356-
this.msalBroadcastService.msalSubject$
357-
.pipe(
358-
filter((msg: EventMessage) => msg.eventType === EventType.LOGIN_SUCCESS || msg.eventType === EventType.ACQUIRE_TOKEN_SUCCESS),
359-
takeUntil(this._destroying$)
360-
)
361-
.subscribe((result: EventMessage) => {
362-
363-
let payload: IdTokenClaims = <AuthenticationResult>result.payload;
364-
365-
// We need to reject id tokens that were not issued with the default sign-in policy.
366-
// "acr" claim in the token tells us what policy is used (NOTE: for new policies (v2.0), use "tfp" instead of "acr")
367-
// To learn more about b2c tokens, visit https://docs.microsoft.com/en-us/azure/active-directory-b2c/tokens-overview
368-
369-
if (payload.idTokenClaims?.acr === b2cPolicies.names.forgotPassword) {
370-
window.alert('Password has been reset successfully. \nPlease sign-in with your new password.');
371-
return this.authService.logout();
372-
}
373-
374-
return result;
375-
});
376-
```
377-
378285
- **Edit Profile**
379286

380287
When a user selects the **Edit Profile** button on the navigation bar, we simply initiate a sign-in flow:

1-Authentication/2-sign-in-b2c/README.md

Lines changed: 0 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -282,99 +282,6 @@ For more information, see: [Events in MSAL Angular v2](https://github.com/AzureA
282282

283283
This user-flow allows your users to sign-in to your application if the user has an account already, or sign-up for an account if not. This is the default user-flow that we pass during the initialization of MSAL instance.
284284

285-
- **Password reset**
286-
287-
When a user clicks on the **forgot your password?** link during sign-in, **Azure AD B2C** will respond with an error. To initiate the password reset user-flow, we need to catch this error and handle it by sending another login request with the corresponding password reset authority string (e.g. `B2C_1_reset`).
288-
289-
```typescript
290-
export class AppComponent implements OnInit, OnDestroy {
291-
292-
private readonly _destroying$ = new Subject<void>();
293-
294-
constructor(
295-
@Inject(MSAL_GUARD_CONFIG) private msalGuardConfig: MsalGuardConfiguration,
296-
private authService: MsalService,
297-
private msalBroadcastService: MsalBroadcastService
298-
) {}
299-
300-
ngOnInit(): void {
301-
this.msalBroadcastService.msalSubject$
302-
.pipe(
303-
filter((msg: EventMessage) => msg.eventType === EventType.LOGIN_FAILURE || msg.eventType === EventType.ACQUIRE_TOKEN_FAILURE),
304-
takeUntil(this._destroying$)
305-
)
306-
.subscribe((result: EventMessage) => {
307-
if (result.error instanceof AuthError) {
308-
// Check for forgot password error
309-
// Learn more about AAD error codes at https://docs.microsoft.com/azure/active-directory/develop/reference-aadsts-error-codes
310-
if (result.error.message.includes('AADB2C90118')) {
311-
312-
// login request with reset authority
313-
let resetPasswordFlowRequest = {
314-
scopes: ["openid"],
315-
authority: b2cPolicies.authorities.forgotPassword.authority,
316-
};
317-
318-
this.login(resetPasswordFlowRequest);
319-
}
320-
}
321-
});
322-
}
323-
324-
login(userFlowRequest?: RedirectRequest | PopupRequest) {
325-
if (this.msalGuardConfig.interactionType === InteractionType.Popup) {
326-
if (this.msalGuardConfig.authRequest) {
327-
this.authService.loginPopup({...this.msalGuardConfig.authRequest, ...userFlowRequest} as PopupRequest)
328-
.subscribe((response: AuthenticationResult) => {
329-
this.authService.instance.setActiveAccount(response.account);
330-
});
331-
} else {
332-
this.authService.loginPopup(userFlowRequest)
333-
.subscribe((response: AuthenticationResult) => {
334-
this.authService.instance.setActiveAccount(response.account);
335-
});
336-
}
337-
} else {
338-
if (this.msalGuardConfig.authRequest){
339-
this.authService.loginRedirect({...this.msalGuardConfig.authRequest, ...userFlowRequest} as RedirectRequest);
340-
} else {
341-
this.authService.loginRedirect(userFlowRequest);
342-
}
343-
}
344-
}
345-
346-
ngOnDestroy(): void {
347-
this._destroying$.next(undefined);
348-
this._destroying$.complete();
349-
}
350-
}
351-
```
352-
353-
We need to reject ID tokens that were not issued with the default sign-in policy (e.g. `B2C_1_SUSI`). After the user resets her password and signs-in again, we will force a logout and prompt for login again (with the default sign-in policy). To do this, register another event in [app.component.ts](./SPA/src/app/app.component.ts) as shown below:
354-
355-
```typescript
356-
this.msalBroadcastService.msalSubject$
357-
.pipe(
358-
filter((msg: EventMessage) => msg.eventType === EventType.LOGIN_SUCCESS || msg.eventType === EventType.ACQUIRE_TOKEN_SUCCESS),
359-
takeUntil(this._destroying$)
360-
)
361-
.subscribe((result: EventMessage) => {
362-
363-
let payload: IdTokenClaims = <AuthenticationResult>result.payload;
364-
365-
// We need to reject id tokens that were not issued with the default sign-in policy.
366-
// "acr" claim in the token tells us what policy is used (NOTE: for new policies (v2.0), use "tfp" instead of "acr")
367-
// To learn more about b2c tokens, visit https://docs.microsoft.com/en-us/azure/active-directory-b2c/tokens-overview
368-
369-
if (payload.idTokenClaims?.acr === b2cPolicies.names.forgotPassword) {
370-
window.alert('Password has been reset successfully. \nPlease sign-in with your new password.');
371-
return this.authService.logout();
372-
}
373-
374-
return result;
375-
});
376-
```
377-
378285
- **Edit Profile**
379286

380287
When a user selects the **Edit Profile** button on the navigation bar, we simply initiate a sign-in flow:

1-Authentication/2-sign-in-b2c/SPA/package-lock.json

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

1-Authentication/2-sign-in-b2c/SPA/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
"@angular/platform-browser": "~11.0.0",
2222
"@angular/platform-browser-dynamic": "~11.0.0",
2323
"@angular/router": "~11.0.0",
24-
"@azure/msal-angular": "^2.0.0-beta.0",
25-
"@azure/msal-browser": "^2.12.0",
24+
"@azure/msal-angular": "^2.0.0-beta.3",
25+
"@azure/msal-browser": "^2.13.1",
2626
"core-js": "^3.8.0",
2727
"rxjs": "~6.6.0",
2828
"tslib": "^2.0.0",

1-Authentication/2-sign-in-b2c/SPA/src/app/app.component.ts

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@ import { EventMessage, EventType, InteractionType, InteractionStatus, PopupReque
77

88
import { b2cPolicies } from './auth-config';
99

10-
interface IdTokenClaims extends AuthenticationResult {
11-
idTokenClaims: {
12-
acr?: string // "acr" claim in the token tells us what policy is used (NOTE: for new policies (v2.0), replace with "tfp" instead)
13-
}
14-
}
15-
1610
@Component({
1711
selector: 'app-root',
1812
templateUrl: './app.component.html',
@@ -45,52 +39,6 @@ export class AppComponent implements OnInit, OnDestroy {
4539
.subscribe(() => {
4640
this.setLoginDisplay();
4741
});
48-
49-
this.msalBroadcastService.msalSubject$
50-
.pipe(
51-
filter((msg: EventMessage) => msg.eventType === EventType.LOGIN_SUCCESS || msg.eventType === EventType.ACQUIRE_TOKEN_SUCCESS),
52-
takeUntil(this._destroying$)
53-
)
54-
.subscribe((result: EventMessage) => {
55-
56-
let payload: IdTokenClaims = <AuthenticationResult>result.payload;
57-
58-
// We need to reject id tokens that were not issued with the default sign-in policy.
59-
// "acr" claim in the token tells us what policy is used (NOTE: for new policies (v2.0), use "tfp" instead of "acr")
60-
// To learn more about b2c tokens, visit https://docs.microsoft.com/en-us/azure/active-directory-b2c/tokens-overview
61-
62-
if (payload.idTokenClaims?.acr === b2cPolicies.names.forgotPassword) {
63-
window.alert('Password has been reset successfully. \nPlease sign-in with your new password.');
64-
return this.authService.logout();
65-
} else if (payload.idTokenClaims['acr'] === b2cPolicies.names.editProfile) {
66-
window.alert('Profile has been updated successfully. \nPlease sign-in again.');
67-
return this.authService.logout();
68-
}
69-
70-
return result;
71-
});
72-
73-
this.msalBroadcastService.msalSubject$
74-
.pipe(
75-
filter((msg: EventMessage) => msg.eventType === EventType.LOGIN_FAILURE || msg.eventType === EventType.ACQUIRE_TOKEN_FAILURE),
76-
takeUntil(this._destroying$)
77-
)
78-
.subscribe((result: EventMessage) => {
79-
if (result.error instanceof AuthError) {
80-
// Check for forgot password error
81-
// Learn more about AAD error codes at https://docs.microsoft.com/azure/active-directory/develop/reference-aadsts-error-codes
82-
if (result.error.message.includes('AADB2C90118')) {
83-
84-
// login request with reset authority
85-
let resetPasswordFlowRequest = {
86-
scopes: ["openid"],
87-
authority: b2cPolicies.authorities.forgotPassword.authority,
88-
};
89-
90-
this.login(resetPasswordFlowRequest);
91-
}
92-
}
93-
});
9442
}
9543

9644
setLoginDisplay() {

1-Authentication/2-sign-in-b2c/SPA/src/app/auth-config.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
* in app.module.ts file.
66
*/
77

8-
98
import { LogLevel, Configuration, BrowserCacheLocation } from '@azure/msal-browser';
109

1110
const isIE = window.navigator.userAgent.indexOf("MSIE ") > -1 || window.navigator.userAgent.indexOf("Trident/") > -1;
@@ -17,19 +16,15 @@ const isIE = window.navigator.userAgent.indexOf("MSIE ") > -1 || window.navigato
1716
*/
1817
export const b2cPolicies = {
1918
names: {
20-
signUpSignIn: "b2c_1_susi",
21-
forgotPassword: "b2c_1_reset",
22-
editProfile: "b2c_1_edit_profile"
19+
signUpSignIn: "b2c_1_susi_reset_v2",
20+
editProfile: "b2c_1_edit_profile_v2"
2321
},
2422
authorities: {
2523
signUpSignIn: {
26-
authority: "https://fabrikamb2c.b2clogin.com/fabrikamb2c.onmicrosoft.com/b2c_1_susi",
27-
},
28-
forgotPassword: {
29-
authority: "https://fabrikamb2c.b2clogin.com/fabrikamb2c.onmicrosoft.com/b2c_1_reset",
24+
authority: "https://fabrikamb2c.b2clogin.com/fabrikamb2c.onmicrosoft.com/b2c_1_susi_reset_v2",
3025
},
3126
editProfile: {
32-
authority: "https://fabrikamb2c.b2clogin.com/fabrikamb2c.onmicrosoft.com/b2c_1_edit_profile"
27+
authority: "https://fabrikamb2c.b2clogin.com/fabrikamb2c.onmicrosoft.com/b2c_1_edit_profile_v2"
3328
}
3429
},
3530
authorityDomain: "fabrikamb2c.b2clogin.com"

0 commit comments

Comments
 (0)