This repository was archived by the owner on Nov 16, 2023. It is now read-only.
File tree 1 file changed +23
-4
lines changed
1 file changed +23
-4
lines changed Original file line number Diff line number Diff line change 1
1
import { Component , OnInit } from '@angular/core' ;
2
2
import { MsalService } from '@azure/msal-angular' ;
3
3
import { HttpClient } from '@angular/common/http' ;
4
+ import { InteractionRequiredAuthError , AuthError } from 'msal' ;
4
5
5
6
const GRAPH_ENDPOINT = 'https://graph.microsoft.com/v1.0/me' ;
6
7
@@ -19,9 +20,27 @@ export class ProfileComponent implements OnInit {
19
20
}
20
21
21
22
getProfile ( ) {
22
- this . http . get ( GRAPH_ENDPOINT ) . toPromise ( )
23
- . then ( profile => {
24
- this . profile = profile ;
25
- } ) ;
23
+ this . http . get ( GRAPH_ENDPOINT )
24
+ . subscribe ( {
25
+ next : ( profile ) => {
26
+ this . profile = profile ;
27
+ } ,
28
+ error : ( err : AuthError ) => {
29
+ // If there is an interaction required error,
30
+ // call one of the interactive methods and then make the request again.
31
+ if ( InteractionRequiredAuthError . isInteractionRequiredError ( err . errorCode ) ) {
32
+ this . authService . acquireTokenPopup ( {
33
+ scopes : this . authService . getScopesForEndpoint ( GRAPH_ENDPOINT )
34
+ } )
35
+ . then ( ( ) => {
36
+ this . http . get ( GRAPH_ENDPOINT )
37
+ . toPromise ( )
38
+ . then ( profile => {
39
+ this . profile = profile ;
40
+ } ) ;
41
+ } ) ;
42
+ }
43
+ }
44
+ } ) ;
26
45
}
27
46
}
You can’t perform that action at this time.
0 commit comments