11import  {  Injectable  }  from  '@angular/core' ; 
2- import  {  Subject  }  from  'rxjs' ; 
3- import  {  filter ,  takeUntil  }  from  'rxjs/operators' ; 
4- import  {  AccountInfo ,  AuthenticationResult ,  InteractionRequiredAuthError ,  InteractionType ,  EventType ,  EventMessage  }  from  "@azure/msal-browser" ; 
5- import  {  MsalService ,  MsalBroadcastService  }  from  '@azure/msal-angular' ; 
2+ import  {  AccountInfo ,  AuthenticationResult ,  InteractionRequiredAuthError ,  InteractionType  }  from  "@azure/msal-browser" ; 
3+ import  {  MsalService  }  from  '@azure/msal-angular' ; 
64import  {  Client ,  AuthenticationProvider ,  AuthenticationProviderOptions  }  from  '@microsoft/microsoft-graph-client' ; 
75
86
@@ -17,7 +15,7 @@ export interface ProviderOptions extends AuthenticationProviderOptions {
1715} ) 
1816export  class  GraphService  { 
1917
20-  constructor ( private  authService : MsalService ,   private   msalBroadcastService :  MsalBroadcastService )  {  } 
18+  constructor ( private  authService : MsalService )  {  } 
2119
2220 /** 
2321 * Returns a graph client object with the provided token acquisition options 
@@ -32,7 +30,7 @@ export class GraphService {
3230 * For more information, visit: https://github.com/microsoftgraph/msgraph-sdk-javascript/blob/dev/docs/CreatingClientInstance.md 
3331 */ 
3432 let  clientOptions  =  { 
35-  authProvider : new  MyAuthenticationProvider ( providerOptions ,  this . authService ,   this . msalBroadcastService ) , 
33+  authProvider : new  MsalAuthenticationProvider ( providerOptions ,  this . authService ) , 
3634 } ; 
3735
3836 const  graphClient  =  Client . initWithMiddleware ( clientOptions ) ; 
@@ -45,15 +43,13 @@ export class GraphService {
4543 * This class implements the IAuthenticationProvider interface, which allows a custom auth provider to be 
4644 * used with the Graph client. See: https://github.com/microsoftgraph/msgraph-sdk-javascript/blob/dev/src/IAuthenticationProvider.ts 
4745 */ 
48- class  MyAuthenticationProvider  implements  AuthenticationProvider  { 
46+ class  MsalAuthenticationProvider  implements  AuthenticationProvider  { 
4947
5048 account ; 
5149 scopes ; 
5250 interactionType ; 
5351
54-  private  readonly  _destroying$  =  new  Subject < void > ( ) ; 
55- 
56-  constructor ( providerOptions : ProviderOptions ,  private  authService : MsalService ,  private  msalBroadcastService : MsalBroadcastService )  { 
52+  constructor ( providerOptions : ProviderOptions ,  private  authService : MsalService )  { 
5753 this . account  =  providerOptions . account ; 
5854 this . scopes  =  providerOptions . scopes ; 
5955 this . interactionType  =  providerOptions . interactionType ; 
@@ -97,22 +93,14 @@ class MyAuthenticationProvider implements AuthenticationProvider {
9793 break ; 
9894
9995 case  InteractionType . Redirect :
96+  /** 
97+  * This will cause the app to leave the current page and redirect to the consent screen. 
98+  * Once consent is provided, the app will return back to the current page and then the  
99+  * silent token acquisition will succeed.  
100+  */ 
100101 this . authService . instance . acquireTokenRedirect ( { 
101102 scopes : this . scopes 
102103 } ) ; 
103- 
104-  this . msalBroadcastService . msalSubject$ . pipe ( 
105-  filter ( ( msg : EventMessage )  =>  msg . eventType  ===  EventType . ACQUIRE_TOKEN_SUCCESS ) , 
106-  takeUntil ( this . _destroying$ ) 
107-  ) . subscribe ( ( result : EventMessage )  =>  { 
108-  response  =  result . payload  as  AuthenticationResult ; 
109- 
110-  if  ( response . accessToken )  { 
111-  resolve ( response . accessToken ) ; 
112-  }  else  { 
113-  reject ( Error ( 'Failed to acquire an access token' ) ) ; 
114-  } 
115-  } ) ; 
116104 break ; 
117105
118106 default :
0 commit comments