Skip to content

Commit 4aec30a

Browse files
HerrickSpencernmetulev
authored andcommitted
Added ability to specify library for teams provider (#128)
* Removed docs from repo (#124) * removed docs from repo * updated docs repo * updated msal, graph sdk, and lit element (#123) * Added ability to specify library for teams provider
1 parent 959e6f0 commit 4aec30a

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/providers/TeamsProvider.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export class TeamsProvider extends MsalProvider {
2323
scopes: string[];
2424
private _authPopupUrl: string;
2525
private _accessToken: string;
26+
public static microsoftTeamsLib;
2627

2728
private _sessionStorageTokenKey = 'mgt-teamsprovider-accesstoken';
2829
private static _sessionStorageClientIdKey = 'msg-teamsprovider-clientId';
@@ -38,7 +39,7 @@ export class TeamsProvider extends MsalProvider {
3839
}
3940

4041
static async isAvailable() {
41-
return !!microsoftTeams;
42+
return !!(TeamsProvider.microsoftTeamsLib || microsoftTeams);
4243
}
4344

4445
static handleAuth() {
@@ -60,7 +61,8 @@ export class TeamsProvider extends MsalProvider {
6061
return;
6162
}
6263

63-
microsoftTeams.initialize();
64+
const teams = TeamsProvider.microsoftTeamsLib || microsoftTeams;
65+
teams.initialize();
6466

6567
if (!clientId) {
6668
clientId = url.searchParams.get('clientId');
@@ -70,7 +72,7 @@ export class TeamsProvider extends MsalProvider {
7072
}
7173

7274
if (!clientId) {
73-
microsoftTeams.authentication.notifyFailure('no clientId provided');
75+
teams.authentication.notifyFailure('no clientId provided');
7476
return;
7577
}
7678

@@ -86,9 +88,9 @@ export class TeamsProvider extends MsalProvider {
8688
} else if (provider.state === ProviderState.SignedIn) {
8789
try {
8890
let accessToken = await provider.getAccessTokenForScopes(...provider.scopes);
89-
microsoftTeams.authentication.notifySuccess(accessToken);
91+
teams.authentication.notifySuccess(accessToken);
9092
} catch (e) {
91-
microsoftTeams.authentication.notifyFailure(e);
93+
teams.authentication.notifyFailure(e);
9294
}
9395
}
9496
};
@@ -109,20 +111,23 @@ export class TeamsProvider extends MsalProvider {
109111
console.error('Make sure you have referenced the Microsoft Teams sdk before using the TeamsProvider');
110112
return;
111113
}
114+
const teams = TeamsProvider.microsoftTeamsLib || microsoftTeams;
112115

113116
this._authPopupUrl = config.authPopupUrl;
114-
microsoftTeams.initialize();
117+
teams.initialize();
115118
this.accessToken = sessionStorage.getItem(this._sessionStorageTokenKey);
116119
}
117120

118121
async login(): Promise<void> {
119122
this.setState(ProviderState.Loading);
123+
const teams = TeamsProvider.microsoftTeamsLib || microsoftTeams;
124+
120125
return new Promise((resolve, reject) => {
121-
microsoftTeams.getContext(context => {
126+
teams.getContext(context => {
122127
let url = new URL(this._authPopupUrl, new URL(window.location.href));
123128
url.searchParams.append('clientId', this.clientId);
124129

125-
microsoftTeams.authentication.authenticate({
130+
teams.authentication.authenticate({
126131
url: url.href,
127132
successCallback: result => {
128133
this.accessToken = result;

0 commit comments

Comments
 (0)