@azure/msal-browser 3.2.0 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app/IPublicClientApplication.mjs +1 -1
- package/dist/app/PublicClientApplication.mjs +2 -2
- package/dist/app/PublicClientApplication.mjs.map +1 -1
- package/dist/app/PublicClientNext.d.ts +274 -0
- package/dist/app/PublicClientNext.d.ts.map +1 -0
- package/dist/app/PublicClientNext.mjs +362 -0
- package/dist/app/PublicClientNext.mjs.map +1 -0
- package/dist/broker/nativeBroker/NativeMessageHandler.mjs +1 -1
- package/dist/broker/nativeBroker/NativeStatusCodes.mjs +1 -1
- package/dist/cache/AsyncMemoryStorage.mjs +1 -1
- package/dist/cache/BrowserCacheManager.d.ts +2 -13
- package/dist/cache/BrowserCacheManager.d.ts.map +1 -1
- package/dist/cache/BrowserCacheManager.mjs +7 -64
- package/dist/cache/BrowserCacheManager.mjs.map +1 -1
- package/dist/cache/BrowserStorage.mjs +1 -1
- package/dist/cache/CryptoKeyStore.mjs +1 -1
- package/dist/cache/DatabaseStorage.mjs +1 -1
- package/dist/cache/MemoryStorage.mjs +1 -1
- package/dist/cache/TokenCache.mjs +1 -1
- package/dist/config/Configuration.d.ts +4 -0
- package/dist/config/Configuration.d.ts.map +1 -1
- package/dist/config/Configuration.mjs +2 -1
- package/dist/config/Configuration.mjs.map +1 -1
- package/dist/controllers/ControllerFactory.d.ts +2 -1
- package/dist/controllers/ControllerFactory.d.ts.map +1 -1
- package/dist/controllers/ControllerFactory.mjs +26 -19
- package/dist/controllers/ControllerFactory.mjs.map +1 -1
- package/dist/controllers/NestedAppAuthController.d.ts +96 -0
- package/dist/controllers/NestedAppAuthController.d.ts.map +1 -0
- package/dist/controllers/NestedAppAuthController.mjs +345 -0
- package/dist/controllers/NestedAppAuthController.mjs.map +1 -0
- package/dist/controllers/StandardController.d.ts.map +1 -1
- package/dist/controllers/StandardController.mjs +16 -13
- package/dist/controllers/StandardController.mjs.map +1 -1
- package/dist/controllers/UnknownOperatingContextController.d.ts +88 -0
- package/dist/controllers/UnknownOperatingContextController.d.ts.map +1 -0
- package/dist/controllers/UnknownOperatingContextController.mjs +275 -0
- package/dist/controllers/UnknownOperatingContextController.mjs.map +1 -0
- package/dist/crypto/BrowserCrypto.d.ts.map +1 -1
- package/dist/crypto/BrowserCrypto.mjs +3 -3
- package/dist/crypto/BrowserCrypto.mjs.map +1 -1
- package/dist/crypto/CryptoOps.d.ts.map +1 -1
- package/dist/crypto/CryptoOps.mjs +8 -5
- package/dist/crypto/CryptoOps.mjs.map +1 -1
- package/dist/crypto/PkceGenerator.mjs +1 -1
- package/dist/crypto/SignedHttpRequest.mjs +1 -1
- package/dist/encode/Base64Decode.mjs +1 -1
- package/dist/encode/Base64Encode.mjs +1 -1
- package/dist/error/BrowserAuthError.mjs +1 -1
- package/dist/error/BrowserAuthErrorCodes.mjs +1 -1
- package/dist/error/BrowserConfigurationAuthError.mjs +1 -1
- package/dist/error/BrowserConfigurationAuthErrorCodes.mjs +1 -1
- package/dist/error/NativeAuthError.mjs +1 -1
- package/dist/error/NativeAuthErrorCodes.mjs +1 -1
- package/dist/error/NestedAppAuthError.d.ts +15 -0
- package/dist/error/NestedAppAuthError.d.ts.map +1 -0
- package/dist/error/NestedAppAuthError.mjs +30 -0
- package/dist/error/NestedAppAuthError.mjs.map +1 -0
- package/dist/event/EventHandler.mjs +1 -1
- package/dist/event/EventMessage.mjs +1 -1
- package/dist/event/EventType.mjs +1 -1
- package/dist/index.d.ts +3 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +4 -2
- package/dist/index.mjs.map +1 -1
- package/dist/interaction_client/BaseInteractionClient.mjs +4 -4
- package/dist/interaction_client/HybridSpaAuthorizationCodeClient.mjs +1 -1
- package/dist/interaction_client/NativeInteractionClient.d.ts.map +1 -1
- package/dist/interaction_client/NativeInteractionClient.mjs +15 -4
- package/dist/interaction_client/NativeInteractionClient.mjs.map +1 -1
- package/dist/interaction_client/PopupClient.d.ts.map +1 -1
- package/dist/interaction_client/PopupClient.mjs +5 -4
- package/dist/interaction_client/PopupClient.mjs.map +1 -1
- package/dist/interaction_client/RedirectClient.mjs +7 -7
- package/dist/interaction_client/SilentAuthCodeClient.d.ts.map +1 -1
- package/dist/interaction_client/SilentAuthCodeClient.mjs +4 -4
- package/dist/interaction_client/SilentAuthCodeClient.mjs.map +1 -1
- package/dist/interaction_client/SilentCacheClient.d.ts.map +1 -1
- package/dist/interaction_client/SilentCacheClient.mjs +4 -3
- package/dist/interaction_client/SilentCacheClient.mjs.map +1 -1
- package/dist/interaction_client/SilentIframeClient.d.ts.map +1 -1
- package/dist/interaction_client/SilentIframeClient.mjs +27 -13
- package/dist/interaction_client/SilentIframeClient.mjs.map +1 -1
- package/dist/interaction_client/SilentRefreshClient.mjs +1 -1
- package/dist/interaction_client/StandardInteractionClient.mjs +5 -5
- package/dist/interaction_handler/InteractionHandler.mjs +1 -1
- package/dist/interaction_handler/RedirectHandler.mjs +1 -1
- package/dist/interaction_handler/SilentHandler.d.ts +13 -47
- package/dist/interaction_handler/SilentHandler.d.ts.map +1 -1
- package/dist/interaction_handler/SilentHandler.mjs +120 -155
- package/dist/interaction_handler/SilentHandler.mjs.map +1 -1
- package/dist/naa/AccountInfo.d.ts +13 -0
- package/dist/naa/AccountInfo.d.ts.map +1 -0
- package/dist/naa/AccountRequests.d.ts +10 -0
- package/dist/naa/AccountRequests.d.ts.map +1 -0
- package/dist/naa/AuthBridge.d.ts +6 -0
- package/dist/naa/AuthBridge.d.ts.map +1 -0
- package/dist/naa/BridgeCapabilities.d.ts +4 -0
- package/dist/naa/BridgeCapabilities.d.ts.map +1 -0
- package/dist/naa/BridgeError.d.ts +10 -0
- package/dist/naa/BridgeError.d.ts.map +1 -0
- package/dist/naa/BridgeError.mjs +12 -0
- package/dist/naa/BridgeError.mjs.map +1 -0
- package/dist/naa/BridgeProxy.d.ts +72 -0
- package/dist/naa/BridgeProxy.d.ts.map +1 -0
- package/dist/naa/BridgeProxy.mjs +154 -0
- package/dist/naa/BridgeProxy.mjs.map +1 -0
- package/dist/naa/BridgeRequest.d.ts +7 -0
- package/dist/naa/BridgeRequest.d.ts.map +1 -0
- package/dist/naa/BridgeRequestEnvelope.d.ts +14 -0
- package/dist/naa/BridgeRequestEnvelope.d.ts.map +1 -0
- package/dist/naa/BridgeResponseEnvelope.d.ts +11 -0
- package/dist/naa/BridgeResponseEnvelope.d.ts.map +1 -0
- package/dist/naa/BridgeStatusCode.d.ts +11 -0
- package/dist/naa/BridgeStatusCode.d.ts.map +1 -0
- package/dist/naa/BridgeStatusCode.mjs +20 -0
- package/dist/naa/BridgeStatusCode.mjs.map +1 -0
- package/dist/naa/IBridgeProxy.d.ts +11 -0
- package/dist/naa/IBridgeProxy.d.ts.map +1 -0
- package/dist/naa/InitializeBridgeResponse.d.ts +7 -0
- package/dist/naa/InitializeBridgeResponse.d.ts.map +1 -0
- package/dist/naa/TokenRequest.d.ts +22 -0
- package/dist/naa/TokenRequest.d.ts.map +1 -0
- package/dist/naa/TokenResponse.d.ts +17 -0
- package/dist/naa/TokenResponse.d.ts.map +1 -0
- package/dist/naa/mapping/NestedAppAuthAdapter.d.ts +26 -0
- package/dist/naa/mapping/NestedAppAuthAdapter.d.ts.map +1 -0
- package/dist/naa/mapping/NestedAppAuthAdapter.mjs +178 -0
- package/dist/naa/mapping/NestedAppAuthAdapter.mjs.map +1 -0
- package/dist/navigation/NavigationClient.mjs +1 -1
- package/dist/network/FetchClient.mjs +1 -1
- package/dist/operatingcontext/BaseOperatingContext.mjs +1 -1
- package/dist/operatingcontext/StandardOperatingContext.mjs +1 -1
- package/dist/operatingcontext/TeamsAppOperatingContext.d.ts +7 -0
- package/dist/operatingcontext/TeamsAppOperatingContext.d.ts.map +1 -1
- package/dist/operatingcontext/TeamsAppOperatingContext.mjs +45 -4
- package/dist/operatingcontext/TeamsAppOperatingContext.mjs.map +1 -1
- package/dist/operatingcontext/UnknownOperatingContext.d.ts +26 -0
- package/dist/operatingcontext/UnknownOperatingContext.d.ts.map +1 -0
- package/dist/operatingcontext/UnknownOperatingContext.mjs +49 -0
- package/dist/operatingcontext/UnknownOperatingContext.mjs.map +1 -0
- package/dist/packageMetadata.d.ts +1 -1
- package/dist/packageMetadata.mjs +2 -2
- package/dist/telemetry/BrowserPerformanceClient.mjs +1 -1
- package/dist/telemetry/BrowserPerformanceMeasurement.mjs +1 -1
- package/dist/utils/BrowserConstants.mjs +1 -1
- package/dist/utils/BrowserProtocolUtils.mjs +1 -1
- package/dist/utils/BrowserUtils.d.ts +54 -53
- package/dist/utils/BrowserUtils.d.ts.map +1 -1
- package/dist/utils/BrowserUtils.mjs +114 -102
- package/dist/utils/BrowserUtils.mjs.map +1 -1
- package/lib/msal-browser.cjs +61 -17728
- package/lib/msal-browser.cjs.map +1 -1
- package/lib/msal-browser.js +14625 -13223
- package/lib/msal-browser.js.map +1 -1
- package/lib/msal-browser.min.js +66 -68
- package/package.json +2 -2
- package/src/app/PublicClientApplication.ts +1 -1
- package/src/app/PublicClientNext.ts +442 -0
- package/src/cache/BrowserCacheManager.ts +11 -100
- package/src/config/Configuration.ts +5 -0
- package/src/controllers/ControllerFactory.ts +36 -25
- package/src/controllers/NestedAppAuthController.ts +525 -0
- package/src/controllers/StandardController.ts +8 -6
- package/src/controllers/UnknownOperatingContextController.ts +383 -0
- package/src/crypto/BrowserCrypto.ts +2 -2
- package/src/crypto/CryptoOps.ts +8 -5
- package/src/error/NestedAppAuthError.ts +32 -0
- package/src/index.ts +3 -10
- package/src/interaction_client/BaseInteractionClient.ts +1 -1
- package/src/interaction_client/NativeInteractionClient.ts +19 -3
- package/src/interaction_client/PopupClient.ts +2 -1
- package/src/interaction_client/RedirectClient.ts +1 -1
- package/src/interaction_client/SilentAuthCodeClient.ts +5 -4
- package/src/interaction_client/SilentCacheClient.ts +11 -3
- package/src/interaction_client/SilentIframeClient.ts +53 -17
- package/src/interaction_client/StandardInteractionClient.ts +1 -1
- package/src/interaction_handler/SilentHandler.ts +177 -233
- package/src/naa/AccountInfo.ts +17 -0
- package/src/naa/AccountRequests.ts +16 -0
- package/src/naa/AuthBridge.ts +16 -0
- package/src/naa/BridgeCapabilities.ts +8 -0
- package/src/naa/BridgeError.ts +18 -0
- package/src/naa/BridgeProxy.ts +230 -0
- package/src/naa/BridgeRequest.ts +12 -0
- package/src/naa/BridgeRequestEnvelope.ts +46 -0
- package/src/naa/BridgeResponseEnvelope.ts +21 -0
- package/src/naa/BridgeStatusCode.ts +15 -0
- package/src/naa/IBridgeProxy.ts +25 -0
- package/src/naa/InitializeBridgeResponse.ts +12 -0
- package/src/naa/TokenRequest.ts +26 -0
- package/src/naa/TokenResponse.ts +61 -0
- package/src/naa/mapping/NestedAppAuthAdapter.ts +252 -0
- package/src/operatingcontext/TeamsAppOperatingContext.ts +43 -3
- package/src/operatingcontext/UnknownOperatingContext.ts +48 -0
- package/src/packageMetadata.ts +1 -1
- package/src/utils/BrowserUtils.ts +133 -125
- package/dist/utils/BrowserStringUtils.d.ts +0 -22
- package/dist/utils/BrowserStringUtils.d.ts.map +0 -1
- package/dist/utils/BrowserStringUtils.mjs +0 -144
- package/dist/utils/BrowserStringUtils.mjs.map +0 -1
- package/src/utils/BrowserStringUtils.ts +0 -143
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { TokenRequest } from "../TokenRequest";
|
|
7
|
+
import { AccountInfo as NaaAccountInfo } from "../AccountInfo";
|
|
8
|
+
import { RedirectRequest } from "../../request/RedirectRequest";
|
|
9
|
+
import { PopupRequest } from "../../request/PopupRequest";
|
|
10
|
+
import { TokenResponse } from "../TokenResponse";
|
|
11
|
+
import {
|
|
12
|
+
AccountInfo as MsalAccountInfo,
|
|
13
|
+
AuthError,
|
|
14
|
+
ClientAuthError,
|
|
15
|
+
ClientConfigurationError,
|
|
16
|
+
InteractionRequiredAuthError,
|
|
17
|
+
ServerError,
|
|
18
|
+
TimeUtils,
|
|
19
|
+
ICrypto,
|
|
20
|
+
Logger,
|
|
21
|
+
AuthToken,
|
|
22
|
+
TokenClaims,
|
|
23
|
+
ClientAuthErrorCodes,
|
|
24
|
+
} from "@azure/msal-common";
|
|
25
|
+
import { isBridgeError } from "../BridgeError";
|
|
26
|
+
import { BridgeStatusCode } from "../BridgeStatusCode";
|
|
27
|
+
import { SilentRequest } from "../../request/SilentRequest";
|
|
28
|
+
import { AuthenticationResult } from "../../response/AuthenticationResult";
|
|
29
|
+
import {} from "../../error/BrowserAuthErrorCodes";
|
|
30
|
+
|
|
31
|
+
export class NestedAppAuthAdapter {
|
|
32
|
+
protected crypto: ICrypto;
|
|
33
|
+
protected logger: Logger;
|
|
34
|
+
protected clientId: string;
|
|
35
|
+
protected clientCapabilities: string[];
|
|
36
|
+
|
|
37
|
+
constructor(
|
|
38
|
+
clientId: string,
|
|
39
|
+
clientCapabilities: string[],
|
|
40
|
+
crypto: ICrypto,
|
|
41
|
+
logger: Logger
|
|
42
|
+
) {
|
|
43
|
+
this.clientId = clientId;
|
|
44
|
+
this.clientCapabilities = clientCapabilities;
|
|
45
|
+
this.crypto = crypto;
|
|
46
|
+
this.logger = logger;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public toNaaSilentTokenRequest(request: SilentRequest): TokenRequest {
|
|
50
|
+
let extraParams: Map<string, string>;
|
|
51
|
+
if (request.extraQueryParameters === undefined) {
|
|
52
|
+
extraParams = new Map<string, string>();
|
|
53
|
+
} else {
|
|
54
|
+
extraParams = new Map<string, string>(
|
|
55
|
+
Object.entries(request.extraQueryParameters)
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Need to get information about the client to populate request correctly
|
|
60
|
+
* For example: client id, client capabilities
|
|
61
|
+
*/
|
|
62
|
+
const tokenRequest: TokenRequest = {
|
|
63
|
+
userObjectId: request.account?.homeAccountId,
|
|
64
|
+
clientId: this.clientId,
|
|
65
|
+
authority: request.authority,
|
|
66
|
+
scope: request.scopes.join(" "),
|
|
67
|
+
correlationId:
|
|
68
|
+
request.correlationId !== undefined
|
|
69
|
+
? request.correlationId
|
|
70
|
+
: this.crypto.createNewGuid(),
|
|
71
|
+
prompt: request.prompt !== undefined ? request.prompt : "",
|
|
72
|
+
claims: request.claims !== undefined ? request.claims : "",
|
|
73
|
+
authenticationScheme:
|
|
74
|
+
request.authenticationScheme !== undefined
|
|
75
|
+
? request.authenticationScheme
|
|
76
|
+
: "",
|
|
77
|
+
clientCapabilities: this.clientCapabilities,
|
|
78
|
+
extraParameters: extraParams,
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
return tokenRequest;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
public toNaaTokenRequest(
|
|
85
|
+
request: PopupRequest | RedirectRequest
|
|
86
|
+
): TokenRequest {
|
|
87
|
+
let extraParams: Map<string, string>;
|
|
88
|
+
if (request.extraQueryParameters === undefined) {
|
|
89
|
+
extraParams = new Map<string, string>();
|
|
90
|
+
} else {
|
|
91
|
+
extraParams = new Map<string, string>(
|
|
92
|
+
Object.entries(request.extraQueryParameters)
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const tokenRequest: TokenRequest = {
|
|
97
|
+
userObjectId: request.account?.homeAccountId,
|
|
98
|
+
clientId: this.clientId,
|
|
99
|
+
authority: request.authority,
|
|
100
|
+
scope: request.scopes.join(" "),
|
|
101
|
+
correlationId:
|
|
102
|
+
request.correlationId !== undefined
|
|
103
|
+
? request.correlationId
|
|
104
|
+
: "",
|
|
105
|
+
prompt: request.prompt !== undefined ? request.prompt : "",
|
|
106
|
+
nonce: request.nonce !== undefined ? request.nonce : "",
|
|
107
|
+
claims: request.claims !== undefined ? request.claims : "",
|
|
108
|
+
state: request.state !== undefined ? request.state : "",
|
|
109
|
+
authenticationScheme:
|
|
110
|
+
request.authenticationScheme !== undefined
|
|
111
|
+
? request.authenticationScheme
|
|
112
|
+
: "",
|
|
113
|
+
clientCapabilities: undefined,
|
|
114
|
+
extraParameters: extraParams,
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
return tokenRequest;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
public fromNaaTokenResponse(
|
|
121
|
+
request: TokenRequest,
|
|
122
|
+
response: TokenResponse
|
|
123
|
+
): AuthenticationResult {
|
|
124
|
+
const expiresOn = new Date(
|
|
125
|
+
TimeUtils.nowSeconds() + (response.expires_in || 0) * 1000
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
const account = this.fromNaaAccountInfo(response.account);
|
|
129
|
+
|
|
130
|
+
const authenticationResult: AuthenticationResult = {
|
|
131
|
+
authority: response.account.environment,
|
|
132
|
+
uniqueId: response.account.homeAccountId,
|
|
133
|
+
tenantId: response.account.tenantId,
|
|
134
|
+
scopes: response.scope.split(" "),
|
|
135
|
+
account: this.fromNaaAccountInfo(response.account),
|
|
136
|
+
idToken: response.id_token !== undefined ? response.id_token : "",
|
|
137
|
+
idTokenClaims:
|
|
138
|
+
account.idTokenClaims !== undefined
|
|
139
|
+
? account.idTokenClaims
|
|
140
|
+
: {},
|
|
141
|
+
accessToken: response.access_token,
|
|
142
|
+
fromCache: true,
|
|
143
|
+
expiresOn: expiresOn,
|
|
144
|
+
tokenType:
|
|
145
|
+
request.authenticationScheme !== undefined
|
|
146
|
+
? request.authenticationScheme
|
|
147
|
+
: "Bearer",
|
|
148
|
+
correlationId: request.correlationId,
|
|
149
|
+
requestId: "",
|
|
150
|
+
extExpiresOn: expiresOn,
|
|
151
|
+
state: response.state,
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
return authenticationResult;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/*
|
|
158
|
+
* export type AccountInfo = {
|
|
159
|
+
* homeAccountId: string;
|
|
160
|
+
* environment: string;
|
|
161
|
+
* tenantId: string;
|
|
162
|
+
* username: string;
|
|
163
|
+
* localAccountId: string;
|
|
164
|
+
* name?: string;
|
|
165
|
+
* idToken?: string;
|
|
166
|
+
* idTokenClaims?: TokenClaims & {
|
|
167
|
+
* [key: string]:
|
|
168
|
+
* | string
|
|
169
|
+
* | number
|
|
170
|
+
* | string[]
|
|
171
|
+
* | object
|
|
172
|
+
* | undefined
|
|
173
|
+
* | unknown;
|
|
174
|
+
* };
|
|
175
|
+
* nativeAccountId?: string;
|
|
176
|
+
* authorityType?: string;
|
|
177
|
+
* };
|
|
178
|
+
*/
|
|
179
|
+
public fromNaaAccountInfo(fromAccount: NaaAccountInfo): MsalAccountInfo {
|
|
180
|
+
let tokenClaims: TokenClaims | undefined;
|
|
181
|
+
if (fromAccount.idToken !== undefined) {
|
|
182
|
+
tokenClaims = AuthToken.extractTokenClaims(
|
|
183
|
+
fromAccount.idToken,
|
|
184
|
+
this.crypto.base64Decode
|
|
185
|
+
);
|
|
186
|
+
} else {
|
|
187
|
+
tokenClaims = undefined;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const account: MsalAccountInfo = {
|
|
191
|
+
homeAccountId: fromAccount.homeAccountId,
|
|
192
|
+
environment: fromAccount.environment,
|
|
193
|
+
tenantId: fromAccount.tenantId,
|
|
194
|
+
username: fromAccount.username,
|
|
195
|
+
localAccountId: fromAccount.localAccountId,
|
|
196
|
+
name: fromAccount.name,
|
|
197
|
+
idToken: fromAccount.idToken,
|
|
198
|
+
idTokenClaims: tokenClaims,
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
return account;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
*
|
|
206
|
+
* @param error BridgeError
|
|
207
|
+
* @returns AuthError, ClientAuthError, ClientConfigurationError, ServerError, InteractionRequiredError
|
|
208
|
+
*/
|
|
209
|
+
public fromBridgeError(
|
|
210
|
+
error: unknown
|
|
211
|
+
):
|
|
212
|
+
| AuthError
|
|
213
|
+
| ClientAuthError
|
|
214
|
+
| ClientConfigurationError
|
|
215
|
+
| ServerError
|
|
216
|
+
| InteractionRequiredAuthError {
|
|
217
|
+
if (isBridgeError(error)) {
|
|
218
|
+
switch (error.status) {
|
|
219
|
+
case BridgeStatusCode.USER_CANCEL:
|
|
220
|
+
return new ClientAuthError(
|
|
221
|
+
ClientAuthErrorCodes.userCanceled
|
|
222
|
+
);
|
|
223
|
+
case BridgeStatusCode.NO_NETWORK:
|
|
224
|
+
return new ClientAuthError(
|
|
225
|
+
ClientAuthErrorCodes.noNetworkConnectivity
|
|
226
|
+
);
|
|
227
|
+
case BridgeStatusCode.ACCOUNT_UNAVAILABLE:
|
|
228
|
+
return new ClientAuthError(
|
|
229
|
+
ClientAuthErrorCodes.noAccountFound
|
|
230
|
+
);
|
|
231
|
+
case BridgeStatusCode.DISABLED:
|
|
232
|
+
return new ClientAuthError(
|
|
233
|
+
ClientAuthErrorCodes.nestedAppAuthBridgeDisabled
|
|
234
|
+
);
|
|
235
|
+
case BridgeStatusCode.NESTED_APP_AUTH_UNAVAILABLE:
|
|
236
|
+
return new ClientAuthError(error.code, error.description);
|
|
237
|
+
case BridgeStatusCode.TRANSIENT_ERROR:
|
|
238
|
+
case BridgeStatusCode.PERSISTENT_ERROR:
|
|
239
|
+
return new ServerError(error.code, error.description);
|
|
240
|
+
case BridgeStatusCode.USER_INTERACTION_REQUIRED:
|
|
241
|
+
return new InteractionRequiredAuthError(
|
|
242
|
+
error.code,
|
|
243
|
+
error.description
|
|
244
|
+
);
|
|
245
|
+
default:
|
|
246
|
+
return new AuthError(error.code, error.description);
|
|
247
|
+
}
|
|
248
|
+
} else {
|
|
249
|
+
return new AuthError("unknown_error", "An unknown error occurred");
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
@@ -4,8 +4,14 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { BaseOperatingContext } from "./BaseOperatingContext";
|
|
7
|
+
import { IBridgeProxy } from "../naa/IBridgeProxy";
|
|
8
|
+
import { BridgeProxy } from "../naa/BridgeProxy";
|
|
9
|
+
import { AccountInfo } from "../naa/AccountInfo";
|
|
7
10
|
|
|
8
11
|
export class TeamsAppOperatingContext extends BaseOperatingContext {
|
|
12
|
+
protected bridgeProxy: IBridgeProxy | undefined = undefined;
|
|
13
|
+
protected activeAccount: AccountInfo | undefined = undefined;
|
|
14
|
+
|
|
9
15
|
/*
|
|
10
16
|
* TODO: Once we have determine the bundling code return here to specify the name of the bundle
|
|
11
17
|
* containing the implementation for this operating context
|
|
@@ -33,6 +39,18 @@ export class TeamsAppOperatingContext extends BaseOperatingContext {
|
|
|
33
39
|
return TeamsAppOperatingContext.ID;
|
|
34
40
|
}
|
|
35
41
|
|
|
42
|
+
getBridgeProxy(): IBridgeProxy | undefined {
|
|
43
|
+
return this.bridgeProxy;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
getActiveAccount(): AccountInfo | undefined {
|
|
47
|
+
return this.activeAccount;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
setActiveAccount(account: AccountInfo): void {
|
|
51
|
+
this.activeAccount = account;
|
|
52
|
+
}
|
|
53
|
+
|
|
36
54
|
/**
|
|
37
55
|
* Checks whether the operating context is available.
|
|
38
56
|
* Confirms that the code is running a browser rather. This is required.
|
|
@@ -40,9 +58,31 @@ export class TeamsAppOperatingContext extends BaseOperatingContext {
|
|
|
40
58
|
*/
|
|
41
59
|
async initialize(): Promise<boolean> {
|
|
42
60
|
/*
|
|
43
|
-
* TODO: Add implementation to check for presence of inject
|
|
44
|
-
*
|
|
61
|
+
* TODO: Add implementation to check for presence of inject Nested App Auth Bridge JavaScript interface
|
|
62
|
+
*
|
|
45
63
|
*/
|
|
46
|
-
|
|
64
|
+
try {
|
|
65
|
+
if (typeof window !== "undefined") {
|
|
66
|
+
const bridgeProxy: IBridgeProxy = await BridgeProxy.create();
|
|
67
|
+
/*
|
|
68
|
+
* Because we want single sign on we need to attempt to
|
|
69
|
+
* grab the active account as part of initialization
|
|
70
|
+
* this.activeAccount = await bridgeProxy.getActiveAccount();
|
|
71
|
+
*/
|
|
72
|
+
try {
|
|
73
|
+
this.activeAccount = await bridgeProxy.getActiveAccount();
|
|
74
|
+
} catch (e) {
|
|
75
|
+
this.activeAccount = undefined;
|
|
76
|
+
}
|
|
77
|
+
this.bridgeProxy = bridgeProxy;
|
|
78
|
+
this.available = bridgeProxy !== undefined;
|
|
79
|
+
} else {
|
|
80
|
+
this.available = false;
|
|
81
|
+
}
|
|
82
|
+
} catch (e) {
|
|
83
|
+
this.available = false;
|
|
84
|
+
} finally {
|
|
85
|
+
return this.available;
|
|
86
|
+
}
|
|
47
87
|
}
|
|
48
88
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { BaseOperatingContext } from "./BaseOperatingContext";
|
|
7
|
+
|
|
8
|
+
export class UnknownOperatingContext extends BaseOperatingContext {
|
|
9
|
+
/*
|
|
10
|
+
* TODO: Once we have determine the bundling code return here to specify the name of the bundle
|
|
11
|
+
* containing the implementation for this operating context
|
|
12
|
+
*/
|
|
13
|
+
static readonly MODULE_NAME: string = "";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Unique identifier for the operating context
|
|
17
|
+
*/
|
|
18
|
+
static readonly ID: string = "UnknownOperatingContext";
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Return the module name. Intended for use with import() to enable dynamic import
|
|
22
|
+
* of the implementation associated with this operating context
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
getModuleName(): string {
|
|
26
|
+
return UnknownOperatingContext.MODULE_NAME;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Returns the unique identifier for this operating context
|
|
30
|
+
* @returns string
|
|
31
|
+
*/
|
|
32
|
+
getId(): string {
|
|
33
|
+
return UnknownOperatingContext.ID;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Checks whether the operating context is available.
|
|
38
|
+
* Confirms that the code is running a browser rather. This is required.
|
|
39
|
+
* @returns Promise<boolean> indicating whether this operating context is currently available.
|
|
40
|
+
*/
|
|
41
|
+
async initialize(): Promise<boolean> {
|
|
42
|
+
/**
|
|
43
|
+
* This operating context is in use when we have not checked for what the operating context is.
|
|
44
|
+
* The context is unknown until we check it.
|
|
45
|
+
*/
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
}
|
package/src/packageMetadata.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import { UrlString } from "@azure/msal-common";
|
|
7
7
|
import {
|
|
8
8
|
createBrowserAuthError,
|
|
9
9
|
BrowserAuthErrorCodes,
|
|
@@ -11,146 +11,154 @@ import {
|
|
|
11
11
|
import { InteractionType, BrowserConstants } from "./BrowserConstants";
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
14
|
+
* Clears hash from window url.
|
|
15
15
|
*/
|
|
16
|
-
export
|
|
17
|
-
//
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
// Full removes "#" from url
|
|
27
|
-
contentWindow.history.replaceState(
|
|
28
|
-
null,
|
|
29
|
-
Constants.EMPTY_STRING,
|
|
30
|
-
`${contentWindow.location.origin}${contentWindow.location.pathname}${contentWindow.location.search}`
|
|
31
|
-
);
|
|
32
|
-
}
|
|
16
|
+
export function clearHash(contentWindow: Window): void {
|
|
17
|
+
// Office.js sets history.replaceState to null
|
|
18
|
+
contentWindow.location.hash = "";
|
|
19
|
+
if (typeof contentWindow.history.replaceState === "function") {
|
|
20
|
+
// Full removes "#" from url
|
|
21
|
+
contentWindow.history.replaceState(
|
|
22
|
+
null,
|
|
23
|
+
"",
|
|
24
|
+
`${contentWindow.location.origin}${contentWindow.location.pathname}${contentWindow.location.search}`
|
|
25
|
+
);
|
|
33
26
|
}
|
|
27
|
+
}
|
|
34
28
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
29
|
+
/**
|
|
30
|
+
* Replaces current hash with hash from provided url
|
|
31
|
+
*/
|
|
32
|
+
export function replaceHash(url: string): void {
|
|
33
|
+
const urlParts = url.split("#");
|
|
34
|
+
urlParts.shift(); // Remove part before the hash
|
|
35
|
+
window.location.hash = urlParts.length > 0 ? urlParts.join("#") : "";
|
|
36
|
+
}
|
|
44
37
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Returns boolean of whether the current window is in an iframe or not.
|
|
40
|
+
*/
|
|
41
|
+
export function isInIframe(): boolean {
|
|
42
|
+
return window.parent !== window;
|
|
43
|
+
}
|
|
51
44
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
45
|
+
/**
|
|
46
|
+
* Returns boolean of whether or not the current window is a popup opened by msal
|
|
47
|
+
*/
|
|
48
|
+
export function isInPopup(): boolean {
|
|
49
|
+
return (
|
|
50
|
+
typeof window !== "undefined" &&
|
|
51
|
+
!!window.opener &&
|
|
52
|
+
window.opener !== window &&
|
|
53
|
+
typeof window.name === "string" &&
|
|
54
|
+
window.name.indexOf(`${BrowserConstants.POPUP_NAME_PREFIX}.`) === 0
|
|
55
|
+
);
|
|
56
|
+
}
|
|
64
57
|
|
|
65
|
-
|
|
58
|
+
// #endregion
|
|
66
59
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
60
|
+
/**
|
|
61
|
+
* Returns current window URL as redirect uri
|
|
62
|
+
*/
|
|
63
|
+
export function getCurrentUri(): string {
|
|
64
|
+
return window.location.href.split("?")[0].split("#")[0];
|
|
65
|
+
}
|
|
73
66
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
67
|
+
/**
|
|
68
|
+
* Gets the homepage url for the current window location.
|
|
69
|
+
*/
|
|
70
|
+
export function getHomepage(): string {
|
|
71
|
+
const currentUrl = new UrlString(window.location.href);
|
|
72
|
+
const urlComponents = currentUrl.getUrlComponents();
|
|
73
|
+
return `${urlComponents.Protocol}//${urlComponents.HostNameAndPort}/`;
|
|
74
|
+
}
|
|
82
75
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
BrowserAuthErrorCodes.blockIframeReload
|
|
95
|
-
);
|
|
96
|
-
}
|
|
76
|
+
/**
|
|
77
|
+
* Throws error if we have completed an auth and are
|
|
78
|
+
* attempting another auth request inside an iframe.
|
|
79
|
+
*/
|
|
80
|
+
export function blockReloadInHiddenIframes(): void {
|
|
81
|
+
const isResponseHash = UrlString.hashContainsKnownProperties(
|
|
82
|
+
window.location.hash
|
|
83
|
+
);
|
|
84
|
+
// return an error if called from the hidden iframe created by the msal js silent calls
|
|
85
|
+
if (isResponseHash && isInIframe()) {
|
|
86
|
+
throw createBrowserAuthError(BrowserAuthErrorCodes.blockIframeReload);
|
|
97
87
|
}
|
|
88
|
+
}
|
|
98
89
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
BrowserAuthErrorCodes.redirectInIframe
|
|
117
|
-
);
|
|
118
|
-
}
|
|
90
|
+
/**
|
|
91
|
+
* Block redirect operations in iframes unless explicitly allowed
|
|
92
|
+
* @param interactionType Interaction type for the request
|
|
93
|
+
* @param allowRedirectInIframe Config value to allow redirects when app is inside an iframe
|
|
94
|
+
*/
|
|
95
|
+
export function blockRedirectInIframe(
|
|
96
|
+
interactionType: InteractionType,
|
|
97
|
+
allowRedirectInIframe: boolean
|
|
98
|
+
): void {
|
|
99
|
+
const isIframedApp = isInIframe();
|
|
100
|
+
if (
|
|
101
|
+
interactionType === InteractionType.Redirect &&
|
|
102
|
+
isIframedApp &&
|
|
103
|
+
!allowRedirectInIframe
|
|
104
|
+
) {
|
|
105
|
+
// If we are not in top frame, we shouldn't redirect. This is also handled by the service.
|
|
106
|
+
throw createBrowserAuthError(BrowserAuthErrorCodes.redirectInIframe);
|
|
119
107
|
}
|
|
108
|
+
}
|
|
120
109
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
BrowserAuthErrorCodes.blockNestedPopups
|
|
129
|
-
);
|
|
130
|
-
}
|
|
110
|
+
/**
|
|
111
|
+
* Block redirectUri loaded in popup from calling AcquireToken APIs
|
|
112
|
+
*/
|
|
113
|
+
export function blockAcquireTokenInPopups(): void {
|
|
114
|
+
// Popups opened by msal popup APIs are given a name that starts with "msal."
|
|
115
|
+
if (isInPopup()) {
|
|
116
|
+
throw createBrowserAuthError(BrowserAuthErrorCodes.blockNestedPopups);
|
|
131
117
|
}
|
|
118
|
+
}
|
|
132
119
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
120
|
+
/**
|
|
121
|
+
* Throws error if token requests are made in non-browser environment
|
|
122
|
+
* @param isBrowserEnvironment Flag indicating if environment is a browser.
|
|
123
|
+
*/
|
|
124
|
+
export function blockNonBrowserEnvironment(
|
|
125
|
+
isBrowserEnvironment: boolean
|
|
126
|
+
): void {
|
|
127
|
+
if (!isBrowserEnvironment) {
|
|
128
|
+
throw createBrowserAuthError(
|
|
129
|
+
BrowserAuthErrorCodes.nonBrowserEnvironment
|
|
130
|
+
);
|
|
143
131
|
}
|
|
132
|
+
}
|
|
144
133
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
134
|
+
/**
|
|
135
|
+
* Throws error if initialize hasn't been called
|
|
136
|
+
* @param initialized
|
|
137
|
+
*/
|
|
138
|
+
export function blockAPICallsBeforeInitialize(initialized: boolean): void {
|
|
139
|
+
if (!initialized) {
|
|
140
|
+
throw createBrowserAuthError(
|
|
141
|
+
BrowserAuthErrorCodes.uninitializedPublicClientApplication
|
|
142
|
+
);
|
|
155
143
|
}
|
|
156
144
|
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Adds a preconnect link element to the header which begins DNS resolution and SSL connection in anticipation of the /token request
|
|
148
|
+
* @param loginDomain Authority domain, including https protocol e.g. https://login.microsoftonline.com
|
|
149
|
+
* @returns
|
|
150
|
+
*/
|
|
151
|
+
export function preconnect(authority: string): void {
|
|
152
|
+
const link = document.createElement("link");
|
|
153
|
+
link.rel = "preconnect";
|
|
154
|
+
link.href = new URL(authority).origin;
|
|
155
|
+
link.crossOrigin = "anonymous";
|
|
156
|
+
document.head.appendChild(link);
|
|
157
|
+
|
|
158
|
+
// The browser will close connection if not used within a few seconds, remove element from the header after 10s
|
|
159
|
+
window.setTimeout(() => {
|
|
160
|
+
try {
|
|
161
|
+
document.head.removeChild(link);
|
|
162
|
+
} catch {}
|
|
163
|
+
}, 10000); // 10s Timeout
|
|
164
|
+
}
|