Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

Commit 1b85e5f

Browse files
committed
updated component and added account type
1 parent a5a0091 commit 1b85e5f

File tree

8 files changed

+35
-50
lines changed

8 files changed

+35
-50
lines changed

2-Authorization-I/1-call-graph/README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,14 @@ Here you'll learn about [Access Tokens](https://aka.ms/access-tokens), [acquirin
4848

4949
## Contents
5050

51-
| File/folder | Description |
52-
|---------------------------------|-----------------------------------------------------------------------|
53-
| `src/app/auth-config.ts` | Authentication configuration parameters reside here. |
54-
| `src/app/app.module.ts` | MSAL-Angular configuration parameters reside here. |
55-
| `src/app/app-routing.module.ts` | Configure your MSAL-Guard here. |
56-
| `src/app/graph.service.ts` | Class to call graph API. |
51+
| File/folder | Description |
52+
|-----------------------------------------------------------|-----------------------------------------------------------------------|
53+
| `src/app/auth-config.ts` | Authentication configuration parameters reside here. |
54+
| `src/app/app.module.ts` | MSAL-Angular configuration parameters reside here. |
55+
| `src/app/app-routing.module.ts` | Configure your MSAL-Guard here. |
56+
| `src/app/graph.service.ts` | Class to call graph API. |
57+
| `src/app/account-switch-account-switch.component.ts` | Contains logic to handle multiple account selection with MSAL.js. |
58+
5759

5860
## Prerequisites
5961

2-Authorization-I/1-call-graph/SPA/src/app/account-switch-component/account-switch-component.component.spec.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@ import {
99
RedirectRequest,
1010
InteractionRequiredAuthError,
1111
SilentRequest,
12+
AccountInfo,
1213
} from '@azure/msal-browser';
1314

1415
@Component({
1516
selector: 'app-account-switch-component',
16-
templateUrl: './account-switch-component.component.html',
17-
styleUrls: ['./account-switch-component.component.css'],
17+
templateUrl: './account-switch.component.html',
18+
styleUrls: ['./account-switch.component.css'],
1819
})
19-
export class AccountSwitchComponentComponent implements OnInit {
20-
accounts: any = [];
20+
export class AccountSwitchComponent implements OnInit {
21+
accounts: AccountInfo[] = [];
2122
constructor(
2223
@Inject(MAT_DIALOG_DATA) public data: any,
2324
@Inject(MSAL_GUARD_CONFIG) private msalGuardConfig: MsalGuardConfiguration,
@@ -26,7 +27,7 @@ export class AccountSwitchComponentComponent implements OnInit {
2627

2728
ngOnInit(): void {}
2829

29-
switchAccount(account: any) {
30+
switchAccount(account: AccountInfo | null) {
3031
const activeAccount = this.authService.instance.getActiveAccount();
3132
if (!account) {
3233
this.authService.instance.setActiveAccount(account);

2-Authorization-I/1-call-graph/SPA/src/app/app.component.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
Login
1010
</button>
1111

12-
<button mat-raised-button *ngIf="loginDisplay" [matMenuTriggerFor]="menu">{{name}}</button>
12+
<button mat-raised-button color="accent" *ngIf="loginDisplay" [matMenuTriggerFor]="menu">
13+
<mat-icon>keyboard_arrow_down</mat-icon>
14+
{{name}}
15+
</button>
1316

1417
<mat-menu #menu="matMenu">
1518
<button mat-menu-item (click)="openDialog()">Switch Account</button>

2-Authorization-I/1-call-graph/SPA/src/app/app.component.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
import { Component, OnInit, Inject, OnDestroy } from '@angular/core';
22
import { MsalService, MsalBroadcastService, MSAL_GUARD_CONFIG, MsalGuardConfiguration } from '@azure/msal-angular';
3-
import { AuthenticationResult, InteractionStatus, InteractionType, PopupRequest, RedirectRequest } from '@azure/msal-browser';
3+
import {
4+
AuthenticationResult,
5+
InteractionStatus,
6+
InteractionType,
7+
PopupRequest,
8+
RedirectRequest,
9+
AccountInfo,
10+
} from '@azure/msal-browser';
411
import { Subject } from 'rxjs';
512
import { filter, takeUntil } from 'rxjs/operators';
613
import { clearStorage } from './utils/storage-utils';
714
import { MatDialog } from '@angular/material/dialog';
8-
import { AccountSwitchComponentComponent } from "./account-switch-component/account-switch-component.component"
15+
import { AccountSwitchComponent } from "./account-switch/account-switch.component"
916

1017
@Component({
1118
selector: 'app-root',
@@ -17,7 +24,7 @@ export class AppComponent implements OnInit, OnDestroy {
1724
loginDisplay = false;
1825
isIframe = false;
1926
name: string | undefined;
20-
accounts : any[] = [];
27+
accounts: AccountInfo[] = [];
2128

2229
private readonly _destroying$ = new Subject<void>();
2330

@@ -58,18 +65,15 @@ export class AppComponent implements OnInit, OnDestroy {
5865
this.accounts = this.authService.instance.getAllAccounts();
5966
}
6067

61-
62-
6368
openDialog(): void {
64-
let dialogRef = this.dialog.open(AccountSwitchComponentComponent, {
69+
let dialogRef = this.dialog.open(AccountSwitchComponent, {
6570
data: {
6671
accounts: this.accounts,
6772
},
6873
});
69-
dialogRef.afterClosed().subscribe(result => {
70-
console.log(result);
71-
})
72-
74+
dialogRef.afterClosed().subscribe((result) => {
75+
console.log(result);
76+
});
7377
}
7478

7579
checkAndSetActiveAccount() {
@@ -90,8 +94,6 @@ export class AppComponent implements OnInit, OnDestroy {
9094
}
9195
}
9296

93-
94-
9597
login() {
9698
if (this.msalGuardConfig.interactionType === InteractionType.Popup) {
9799
if (this.msalGuardConfig.authRequest) {

2-Authorization-I/1-call-graph/SPA/src/app/app.module.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { AppComponent } from './app.component';
1616
import { ProfileComponent } from './profile/profile.component';
1717
import { HomeComponent } from './home/home.component';
1818
import { ContactsComponent } from './contacts/contacts.component';
19+
import { AccountSwitchComponent } from './account-switch/account-switch.component';
1920

2021

2122

@@ -42,7 +43,6 @@ import {
4243
import { msalConfig, loginRequest, protectedResources } from './auth-config';
4344
import { getClaimsFromStorage } from './utils/storage-utils';
4445
import { GraphService } from './graph.service';
45-
import { AccountSwitchComponentComponent } from './account-switch-component/account-switch-component.component';
4646

4747
/**
4848
* Here we pass the configuration parameters to create an MSAL instance.
@@ -118,9 +118,9 @@ export function MSALGuardConfigFactory(): MsalGuardConfiguration {
118118
ProfileComponent,
119119
HomeComponent,
120120
ContactsComponent,
121-
AccountSwitchComponentComponent,
121+
AccountSwitchComponent,
122122
],
123-
entryComponents: [AccountSwitchComponentComponent],
123+
entryComponents: [AccountSwitchComponent],
124124
imports: [
125125
BrowserModule,
126126
AppRoutingModule,

0 commit comments

Comments
 (0)