66 */
77
88import { AuthenticationProviderOptions } from '@microsoft/microsoft-graph-client/lib/es/IAuthenticationProviderOptions' ;
9- import { MsalProvider } from './MsalProvider' ;
10- import { LoginType , ProviderState } from './IProvider' ;
119import { Configuration , UserAgentApplication } from 'msal' ;
10+ import { LoginType , ProviderState } from './IProvider' ;
11+ import { MsalProvider } from './MsalProvider' ;
1212
1313declare var microsoftTeams : any ;
1414
@@ -20,43 +20,35 @@ export interface TeamsConfig {
2020}
2121
2222export class TeamsProvider extends MsalProvider {
23- scopes : string [ ] ;
24- private _authPopupUrl : string ;
25- private _accessToken : string ;
26- public static microsoftTeamsLib ;
27-
28- private _sessionStorageTokenKey = 'mgt-teamsprovider-accesstoken' ;
29- private static _sessionStorageClientIdKey = 'msg-teamsprovider-clientId' ;
30-
3123 private set accessToken ( value : string ) {
3224 this . _accessToken = value ;
33- sessionStorage . setItem ( this . _sessionStorageTokenKey , value ) ;
25+ sessionStorage . setItem ( TeamsProvider . _sessionStorageTokenKey , value ) ;
3426 this . setState ( value ? ProviderState . SignedIn : ProviderState . SignedOut ) ;
3527 }
3628
3729 private get accessToken ( ) {
3830 return this . _accessToken ;
3931 }
4032
41- static async isAvailable ( ) {
33+ public static async isAvailable ( ) {
4234 return ! ! ( TeamsProvider . microsoftTeamsLib || microsoftTeams ) ;
4335 }
4436
45- static handleAuth ( ) {
37+ public static handleAuth ( ) {
4638 if ( ! this . isAvailable ) {
4739 console . error ( 'Make sure you have referenced the Microsoft Teams sdk before using the TeamsProvider' ) ;
4840 return ;
4941 }
5042
5143 // we are in popup world now - authenticate and handle it
5244
53- var url = new URL ( window . location . href ) ;
45+ const url = new URL ( window . location . href ) ;
5446
5547 let clientId = sessionStorage . getItem ( this . _sessionStorageClientIdKey ) ;
5648
5749 if ( UserAgentApplication . prototype . isCallback ( window . location . hash ) ) {
5850 new MsalProvider ( {
59- clientId : clientId
51+ clientId
6052 } ) ;
6153 return ;
6254 }
@@ -76,8 +68,8 @@ export class TeamsProvider extends MsalProvider {
7668 return ;
7769 }
7870
79- let provider = new MsalProvider ( {
80- clientId : clientId // need to add scopes
71+ const provider = new MsalProvider ( {
72+ clientId // need to add scopes
8173 } ) ;
8274
8375 const handleProviderState = async ( ) => {
@@ -87,7 +79,7 @@ export class TeamsProvider extends MsalProvider {
8779 provider . login ( ) ;
8880 } else if ( provider . state === ProviderState . SignedIn ) {
8981 try {
90- let accessToken = await provider . getAccessTokenForScopes ( ...provider . scopes ) ;
82+ const accessToken = await provider . getAccessTokenForScopes ( ...provider . scopes ) ;
9183 teams . authentication . notifySuccess ( accessToken ) ;
9284 } catch ( e ) {
9385 teams . authentication . notifyFailure ( e ) ;
@@ -99,6 +91,16 @@ export class TeamsProvider extends MsalProvider {
9991 handleProviderState ( ) ;
10092 }
10193
94+ private static _sessionStorageClientIdKey = 'msg-teamsprovider-clientId' ;
95+ private static _sessionStorageTokenKey = 'mgt-teamsprovider-accesstoken' ;
96+
97+ public static microsoftTeamsLib ;
98+
99+ private _authPopupUrl : string ;
100+ private _accessToken : string ;
101+
102+ public scopes : string [ ] ;
103+
102104 constructor ( config : TeamsConfig ) {
103105 super ( {
104106 clientId : config . clientId ,
@@ -115,16 +117,16 @@ export class TeamsProvider extends MsalProvider {
115117
116118 this . _authPopupUrl = config . authPopupUrl ;
117119 teams . initialize ( ) ;
118- this . accessToken = sessionStorage . getItem ( this . _sessionStorageTokenKey ) ;
120+ this . accessToken = sessionStorage . getItem ( TeamsProvider . _sessionStorageTokenKey ) ;
119121 }
120122
121- async login ( ) : Promise < void > {
123+ public async login ( ) : Promise < void > {
122124 this . setState ( ProviderState . Loading ) ;
123125 const teams = TeamsProvider . microsoftTeamsLib || microsoftTeams ;
124126
125127 return new Promise ( ( resolve , reject ) => {
126128 teams . getContext ( context => {
127- let url = new URL ( this . _authPopupUrl , new URL ( window . location . href ) ) ;
129+ const url = new URL ( this . _authPopupUrl , new URL ( window . location . href ) ) ;
128130 url . searchParams . append ( 'clientId' , this . clientId ) ;
129131
130132 teams . authentication . authenticate ( {
@@ -142,7 +144,7 @@ export class TeamsProvider extends MsalProvider {
142144 } ) ;
143145 }
144146
145- async getAccessToken ( options : AuthenticationProviderOptions ) : Promise < string > {
147+ public async getAccessToken ( options : AuthenticationProviderOptions ) : Promise < string > {
146148 return this . accessToken ;
147149 }
148150}
0 commit comments