@azure/msal-common 14.2.0 → 14.4.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/account/AuthToken.mjs +1 -1
- package/dist/account/CcsCredential.mjs +1 -1
- package/dist/account/ClientInfo.mjs +1 -1
- package/dist/authority/Authority.d.ts.map +1 -1
- package/dist/authority/Authority.mjs +4 -5
- package/dist/authority/Authority.mjs.map +1 -1
- package/dist/authority/AuthorityFactory.mjs +1 -1
- package/dist/authority/AuthorityMetadata.d.ts +29 -172
- package/dist/authority/AuthorityMetadata.d.ts.map +1 -1
- package/dist/authority/AuthorityMetadata.mjs +79 -413
- package/dist/authority/AuthorityMetadata.mjs.map +1 -1
- package/dist/authority/AuthorityOptions.d.ts +2 -2
- package/dist/authority/AuthorityOptions.d.ts.map +1 -1
- package/dist/authority/AuthorityOptions.mjs +1 -1
- package/dist/authority/AuthorityOptions.mjs.map +1 -1
- package/dist/authority/AuthorityType.mjs +1 -1
- package/dist/authority/CloudInstanceDiscoveryErrorResponse.mjs +1 -1
- package/dist/authority/CloudInstanceDiscoveryResponse.mjs +1 -1
- package/dist/authority/OpenIdConfigResponse.mjs +1 -1
- package/dist/authority/ProtocolMode.mjs +1 -1
- package/dist/authority/RegionDiscovery.mjs +1 -1
- package/dist/cache/CacheManager.d.ts +24 -19
- package/dist/cache/CacheManager.d.ts.map +1 -1
- package/dist/cache/CacheManager.mjs +51 -33
- package/dist/cache/CacheManager.mjs.map +1 -1
- package/dist/cache/entities/AccessTokenEntity.d.ts +12 -43
- package/dist/cache/entities/AccessTokenEntity.d.ts.map +1 -1
- package/dist/cache/entities/AccountEntity.mjs +1 -1
- package/dist/cache/entities/AppMetadataEntity.mjs +1 -1
- package/dist/cache/entities/AuthorityMetadataEntity.mjs +1 -1
- package/dist/cache/entities/CacheRecord.mjs +1 -1
- package/dist/cache/entities/CredentialEntity.d.ts +15 -73
- package/dist/cache/entities/CredentialEntity.d.ts.map +1 -1
- package/dist/cache/entities/IdTokenEntity.d.ts +4 -30
- package/dist/cache/entities/IdTokenEntity.d.ts.map +1 -1
- package/dist/cache/entities/RefreshTokenEntity.d.ts +2 -33
- package/dist/cache/entities/RefreshTokenEntity.d.ts.map +1 -1
- package/dist/cache/entities/ServerTelemetryEntity.d.ts +2 -9
- package/dist/cache/entities/ServerTelemetryEntity.d.ts.map +1 -1
- package/dist/cache/entities/ThrottlingEntity.mjs +1 -1
- package/dist/cache/persistence/TokenCacheContext.mjs +1 -1
- package/dist/cache/utils/CacheHelpers.d.ts +65 -0
- package/dist/cache/utils/CacheHelpers.d.ts.map +1 -0
- package/dist/cache/utils/CacheHelpers.mjs +242 -0
- package/dist/cache/utils/CacheHelpers.mjs.map +1 -0
- package/dist/client/AuthorizationCodeClient.d.ts +2 -1
- package/dist/client/AuthorizationCodeClient.d.ts.map +1 -1
- package/dist/client/AuthorizationCodeClient.mjs +4 -10
- package/dist/client/AuthorizationCodeClient.mjs.map +1 -1
- package/dist/client/BaseClient.d.ts +1 -1
- package/dist/client/BaseClient.d.ts.map +1 -1
- package/dist/client/BaseClient.mjs +8 -8
- package/dist/client/BaseClient.mjs.map +1 -1
- package/dist/client/RefreshTokenClient.d.ts.map +1 -1
- package/dist/client/RefreshTokenClient.mjs +2 -2
- package/dist/client/RefreshTokenClient.mjs.map +1 -1
- package/dist/client/SilentFlowClient.d.ts.map +1 -1
- package/dist/client/SilentFlowClient.mjs +5 -3
- package/dist/client/SilentFlowClient.mjs.map +1 -1
- package/dist/config/ClientConfiguration.mjs +1 -1
- package/dist/crypto/ICrypto.d.ts +3 -3
- package/dist/crypto/ICrypto.d.ts.map +1 -1
- package/dist/crypto/ICrypto.mjs +1 -1
- package/dist/crypto/ICrypto.mjs.map +1 -1
- package/dist/crypto/JoseHeader.d.ts +3 -3
- package/dist/crypto/JoseHeader.d.ts.map +1 -1
- package/dist/crypto/JoseHeader.mjs +3 -3
- package/dist/crypto/JoseHeader.mjs.map +1 -1
- package/dist/crypto/PopTokenGenerator.d.ts.map +1 -1
- package/dist/crypto/PopTokenGenerator.mjs +3 -3
- package/dist/crypto/PopTokenGenerator.mjs.map +1 -1
- package/dist/crypto/SignedHttpRequest.d.ts +4 -0
- package/dist/crypto/SignedHttpRequest.d.ts.map +1 -1
- package/dist/error/AuthError.mjs +1 -1
- package/dist/error/AuthErrorCodes.mjs +1 -1
- package/dist/error/ClientAuthError.mjs +1 -1
- package/dist/error/ClientAuthErrorCodes.mjs +1 -1
- package/dist/error/ClientConfigurationError.mjs +1 -1
- package/dist/error/ClientConfigurationErrorCodes.mjs +1 -1
- package/dist/error/InteractionRequiredAuthError.mjs +1 -1
- package/dist/error/InteractionRequiredAuthErrorCodes.mjs +1 -1
- package/dist/error/JoseHeaderError.mjs +1 -1
- package/dist/error/JoseHeaderErrorCodes.mjs +1 -1
- package/dist/error/ServerError.mjs +1 -1
- package/dist/index.cjs +2768 -3303
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +6 -7
- package/dist/index.mjs.map +1 -1
- package/dist/logger/Logger.mjs +1 -1
- package/dist/network/INetworkModule.mjs +1 -1
- package/dist/network/NetworkManager.mjs +1 -1
- package/dist/network/RequestThumbprint.d.ts +2 -0
- package/dist/network/RequestThumbprint.d.ts.map +1 -1
- package/dist/network/ThrottlingUtils.mjs +1 -1
- package/dist/packageMetadata.d.ts +1 -1
- package/dist/packageMetadata.mjs +2 -2
- package/dist/request/AuthenticationHeaderParser.mjs +1 -1
- package/dist/request/BaseAuthRequest.d.ts +3 -0
- package/dist/request/BaseAuthRequest.d.ts.map +1 -1
- package/dist/request/RequestParameterBuilder.mjs +1 -1
- package/dist/request/RequestValidator.mjs +1 -1
- package/dist/request/ScopeSet.mjs +1 -1
- package/dist/response/ResponseHandler.d.ts +2 -2
- package/dist/response/ResponseHandler.d.ts.map +1 -1
- package/dist/response/ResponseHandler.mjs +23 -29
- package/dist/response/ResponseHandler.mjs.map +1 -1
- package/dist/telemetry/performance/PerformanceClient.mjs +1 -1
- package/dist/telemetry/performance/PerformanceEvent.d.ts +8 -1
- package/dist/telemetry/performance/PerformanceEvent.d.ts.map +1 -1
- package/dist/telemetry/performance/PerformanceEvent.mjs +6 -2
- package/dist/telemetry/performance/PerformanceEvent.mjs.map +1 -1
- package/dist/telemetry/performance/StubPerformanceClient.mjs +1 -1
- package/dist/telemetry/server/ServerTelemetryManager.d.ts.map +1 -1
- package/dist/telemetry/server/ServerTelemetryManager.mjs +11 -8
- package/dist/telemetry/server/ServerTelemetryManager.mjs.map +1 -1
- package/dist/url/UrlString.d.ts +2 -37
- package/dist/url/UrlString.d.ts.map +1 -1
- package/dist/url/UrlString.mjs +7 -126
- package/dist/url/UrlString.mjs.map +1 -1
- package/dist/utils/Constants.d.ts +2 -3
- package/dist/utils/Constants.d.ts.map +1 -1
- package/dist/utils/Constants.mjs +3 -4
- package/dist/utils/Constants.mjs.map +1 -1
- package/dist/utils/FunctionWrappers.mjs +1 -1
- package/dist/utils/ProtocolUtils.mjs +1 -1
- package/dist/utils/StringUtils.mjs +1 -1
- package/dist/utils/TimeUtils.mjs +1 -1
- package/dist/utils/UrlUtils.d.ts +11 -0
- package/dist/utils/UrlUtils.d.ts.map +1 -0
- package/dist/utils/UrlUtils.mjs +52 -0
- package/dist/utils/UrlUtils.mjs.map +1 -0
- package/package.json +1 -1
- package/src/authority/Authority.ts +5 -8
- package/src/authority/AuthorityMetadata.ts +109 -435
- package/src/authority/AuthorityOptions.ts +2 -2
- package/src/cache/CacheManager.ts +79 -42
- package/src/cache/entities/AccessTokenEntity.ts +13 -149
- package/src/cache/entities/CredentialEntity.ts +16 -200
- package/src/cache/entities/IdTokenEntity.ts +4 -64
- package/src/cache/entities/RefreshTokenEntity.ts +2 -69
- package/src/cache/entities/ServerTelemetryEntity.ts +2 -30
- package/src/cache/utils/CacheHelpers.ts +327 -0
- package/src/client/AuthorizationCodeClient.ts +4 -15
- package/src/client/BaseClient.ts +21 -10
- package/src/client/RefreshTokenClient.ts +7 -1
- package/src/client/SilentFlowClient.ts +8 -4
- package/src/crypto/ICrypto.ts +7 -2
- package/src/crypto/JoseHeader.ts +4 -4
- package/src/crypto/PopTokenGenerator.ts +2 -0
- package/src/crypto/SignedHttpRequest.ts +6 -0
- package/src/index.ts +4 -1
- package/src/network/RequestThumbprint.ts +2 -0
- package/src/packageMetadata.ts +1 -1
- package/src/request/BaseAuthRequest.ts +3 -0
- package/src/response/ResponseHandler.ts +36 -41
- package/src/telemetry/performance/PerformanceEvent.ts +12 -1
- package/src/telemetry/server/ServerTelemetryManager.ts +12 -6
- package/src/url/UrlString.ts +6 -153
- package/src/utils/Constants.ts +3 -3
- package/src/utils/UrlUtils.ts +60 -0
- package/dist/cache/entities/AccessTokenEntity.mjs +0 -121
- package/dist/cache/entities/AccessTokenEntity.mjs.map +0 -1
- package/dist/cache/entities/CredentialEntity.mjs +0 -145
- package/dist/cache/entities/CredentialEntity.mjs.map +0 -1
- package/dist/cache/entities/IdTokenEntity.mjs +0 -64
- package/dist/cache/entities/IdTokenEntity.mjs.map +0 -1
- package/dist/cache/entities/RefreshTokenEntity.mjs +0 -67
- package/dist/cache/entities/RefreshTokenEntity.mjs.map +0 -1
- package/dist/cache/entities/ServerTelemetryEntity.mjs +0 -34
- package/dist/cache/entities/ServerTelemetryEntity.mjs.map +0 -1
package/src/crypto/JoseHeader.ts
CHANGED
|
@@ -7,17 +7,17 @@ import {
|
|
|
7
7
|
JoseHeaderErrorCodes,
|
|
8
8
|
createJoseHeaderError,
|
|
9
9
|
} from "../error/JoseHeaderError";
|
|
10
|
-
import {
|
|
10
|
+
import { JsonWebTokenTypes } from "../utils/Constants";
|
|
11
11
|
|
|
12
12
|
export type JoseHeaderOptions = {
|
|
13
|
-
typ?:
|
|
13
|
+
typ?: JsonWebTokenTypes;
|
|
14
14
|
alg?: string;
|
|
15
15
|
kid?: string;
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
/** @internal */
|
|
19
19
|
export class JoseHeader {
|
|
20
|
-
public typ?:
|
|
20
|
+
public typ?: JsonWebTokenTypes;
|
|
21
21
|
public alg?: string;
|
|
22
22
|
public kid?: string;
|
|
23
23
|
|
|
@@ -48,7 +48,7 @@ export class JoseHeader {
|
|
|
48
48
|
|
|
49
49
|
const shrHeader = new JoseHeader({
|
|
50
50
|
// Access Token PoP headers must have type pop, but the type header can be overriden for special cases
|
|
51
|
-
typ: shrHeaderOptions.typ ||
|
|
51
|
+
typ: shrHeaderOptions.typ || JsonWebTokenTypes.Pop,
|
|
52
52
|
kid: shrHeaderOptions.kid,
|
|
53
53
|
alg: shrHeaderOptions.alg,
|
|
54
54
|
});
|
|
@@ -133,6 +133,7 @@ export class PopTokenGenerator {
|
|
|
133
133
|
resourceRequestUri,
|
|
134
134
|
shrClaims,
|
|
135
135
|
shrNonce,
|
|
136
|
+
shrOptions,
|
|
136
137
|
} = request;
|
|
137
138
|
|
|
138
139
|
const resourceUrlString = resourceRequestUri
|
|
@@ -154,6 +155,7 @@ export class PopTokenGenerator {
|
|
|
154
155
|
...claims,
|
|
155
156
|
},
|
|
156
157
|
keyId,
|
|
158
|
+
shrOptions,
|
|
157
159
|
request.correlationId
|
|
158
160
|
);
|
|
159
161
|
}
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import { JoseHeaderOptions } from "./JoseHeader";
|
|
7
|
+
|
|
6
8
|
export type SignedHttpRequest = {
|
|
7
9
|
at?: string;
|
|
8
10
|
cnf?: object;
|
|
@@ -14,3 +16,7 @@ export type SignedHttpRequest = {
|
|
|
14
16
|
nonce?: string;
|
|
15
17
|
client_claims?: string;
|
|
16
18
|
};
|
|
19
|
+
|
|
20
|
+
export type ShrOptions = {
|
|
21
|
+
header: JoseHeaderOptions;
|
|
22
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -71,6 +71,7 @@ export {
|
|
|
71
71
|
} from "./cache/utils/CacheTypes";
|
|
72
72
|
export { CacheRecord } from "./cache/entities/CacheRecord";
|
|
73
73
|
export { CredentialEntity } from "./cache/entities/CredentialEntity";
|
|
74
|
+
export * as CacheHelpers from "./cache/utils/CacheHelpers";
|
|
74
75
|
export { AppMetadataEntity } from "./cache/entities/AppMetadataEntity";
|
|
75
76
|
export { AccountEntity } from "./cache/entities/AccountEntity";
|
|
76
77
|
export { IdTokenEntity } from "./cache/entities/IdTokenEntity";
|
|
@@ -104,7 +105,7 @@ export {
|
|
|
104
105
|
DEFAULT_CRYPTO_IMPLEMENTATION,
|
|
105
106
|
SignedHttpRequestParameters,
|
|
106
107
|
} from "./crypto/ICrypto";
|
|
107
|
-
export { SignedHttpRequest } from "./crypto/SignedHttpRequest";
|
|
108
|
+
export { SignedHttpRequest, ShrOptions } from "./crypto/SignedHttpRequest";
|
|
108
109
|
export { IGuidGenerator } from "./crypto/IGuidGenerator";
|
|
109
110
|
export { JoseHeader } from "./crypto/JoseHeader";
|
|
110
111
|
// Request
|
|
@@ -192,6 +193,7 @@ export {
|
|
|
192
193
|
GrantType,
|
|
193
194
|
AADAuthorityConstants,
|
|
194
195
|
HttpStatus,
|
|
196
|
+
JsonWebTokenTypes,
|
|
195
197
|
} from "./utils/Constants";
|
|
196
198
|
export { StringUtils } from "./utils/StringUtils";
|
|
197
199
|
export { StringDict } from "./utils/MsalTypes";
|
|
@@ -201,6 +203,7 @@ export {
|
|
|
201
203
|
LibraryStateObject,
|
|
202
204
|
} from "./utils/ProtocolUtils";
|
|
203
205
|
export { TimeUtils } from "./utils/TimeUtils";
|
|
206
|
+
export * as UrlUtils from "./utils/UrlUtils";
|
|
204
207
|
export * from "./utils/FunctionWrappers";
|
|
205
208
|
// Server Telemetry
|
|
206
209
|
export { ServerTelemetryManager } from "./telemetry/server/ServerTelemetryManager";
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import { ShrOptions } from "../crypto/SignedHttpRequest";
|
|
6
7
|
import { AuthenticationScheme } from "../utils/Constants";
|
|
7
8
|
|
|
8
9
|
/**
|
|
@@ -19,4 +20,5 @@ export type RequestThumbprint = {
|
|
|
19
20
|
resourceRequestUri?: string;
|
|
20
21
|
shrClaims?: string;
|
|
21
22
|
sshKid?: string;
|
|
23
|
+
shrOptions?: ShrOptions;
|
|
22
24
|
};
|
package/src/packageMetadata.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { AuthenticationScheme } from "../utils/Constants";
|
|
|
7
7
|
import { AzureCloudOptions } from "../config/ClientConfiguration";
|
|
8
8
|
import { StringDict } from "../utils/MsalTypes";
|
|
9
9
|
import { StoreInCache } from "./StoreInCache";
|
|
10
|
+
import { ShrOptions } from "../crypto/SignedHttpRequest";
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* BaseAuthRequest
|
|
@@ -17,6 +18,7 @@ import { StoreInCache } from "./StoreInCache";
|
|
|
17
18
|
* - claims - A stringified claims request which will be added to all /authorize and /token calls
|
|
18
19
|
* - shrClaims - A stringified claims object which will be added to a Signed HTTP Request
|
|
19
20
|
* - shrNonce - A server-generated timestamp that has been encrypted and base64URL encoded, which will be added to a Signed HTTP Request.
|
|
21
|
+
* - shrOptions - An object containing options for the Signed HTTP Request
|
|
20
22
|
* - resourceRequestMethod - HTTP Request type used to request data from the resource (i.e. "GET", "POST", etc.). Used for proof-of-possession flows.
|
|
21
23
|
* - resourceRequestUri - URI that token will be used for. Used for proof-of-possession flows.
|
|
22
24
|
* - sshJwk - A stringified JSON Web Key representing a public key that can be signed by an SSH certificate.
|
|
@@ -34,6 +36,7 @@ export type BaseAuthRequest = {
|
|
|
34
36
|
claims?: string;
|
|
35
37
|
shrClaims?: string;
|
|
36
38
|
shrNonce?: string;
|
|
39
|
+
shrOptions?: ShrOptions;
|
|
37
40
|
resourceRequestMethod?: string;
|
|
38
41
|
resourceRequestUri?: string;
|
|
39
42
|
sshJwk?: string;
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { ServerAuthorizationTokenResponse } from "./ServerAuthorizationTokenResponse";
|
|
7
|
-
import { buildClientInfo } from "../account/ClientInfo";
|
|
8
7
|
import { ICrypto } from "../crypto/ICrypto";
|
|
9
8
|
import {
|
|
10
9
|
ClientAuthErrorCodes,
|
|
@@ -45,6 +44,7 @@ import { PerformanceEvents } from "../telemetry/performance/PerformanceEvent";
|
|
|
45
44
|
import { checkMaxAge, extractTokenClaims } from "../account/AuthToken";
|
|
46
45
|
import { TokenClaims } from "../account/TokenClaims";
|
|
47
46
|
import { AccountInfo } from "../account/AccountInfo";
|
|
47
|
+
import * as CacheHelpers from "../cache/utils/CacheHelpers";
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
50
|
* Class that handles response parsing.
|
|
@@ -81,16 +81,15 @@ export class ResponseHandler {
|
|
|
81
81
|
/**
|
|
82
82
|
* Function which validates server authorization code response.
|
|
83
83
|
* @param serverResponseHash
|
|
84
|
-
* @param
|
|
84
|
+
* @param requestState
|
|
85
85
|
* @param cryptoObj
|
|
86
86
|
*/
|
|
87
87
|
validateServerAuthorizationCodeResponse(
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
cryptoObj: ICrypto
|
|
88
|
+
serverResponse: ServerAuthorizationCodeResponse,
|
|
89
|
+
requestState: string
|
|
91
90
|
): void {
|
|
92
|
-
if (!
|
|
93
|
-
throw
|
|
91
|
+
if (!serverResponse.state || !requestState) {
|
|
92
|
+
throw serverResponse.state
|
|
94
93
|
? createClientAuthError(
|
|
95
94
|
ClientAuthErrorCodes.stateNotFound,
|
|
96
95
|
"Cached State"
|
|
@@ -101,67 +100,63 @@ export class ResponseHandler {
|
|
|
101
100
|
);
|
|
102
101
|
}
|
|
103
102
|
|
|
104
|
-
let
|
|
105
|
-
let
|
|
103
|
+
let decodedServerResponseState: string;
|
|
104
|
+
let decodedRequestState: string;
|
|
106
105
|
|
|
107
106
|
try {
|
|
108
|
-
|
|
109
|
-
|
|
107
|
+
decodedServerResponseState = decodeURIComponent(
|
|
108
|
+
serverResponse.state
|
|
110
109
|
);
|
|
111
110
|
} catch (e) {
|
|
112
111
|
throw createClientAuthError(
|
|
113
112
|
ClientAuthErrorCodes.invalidState,
|
|
114
|
-
|
|
113
|
+
serverResponse.state
|
|
115
114
|
);
|
|
116
115
|
}
|
|
117
116
|
|
|
118
117
|
try {
|
|
119
|
-
|
|
118
|
+
decodedRequestState = decodeURIComponent(requestState);
|
|
120
119
|
} catch (e) {
|
|
121
120
|
throw createClientAuthError(
|
|
122
121
|
ClientAuthErrorCodes.invalidState,
|
|
123
|
-
|
|
122
|
+
serverResponse.state
|
|
124
123
|
);
|
|
125
124
|
}
|
|
126
125
|
|
|
127
|
-
if (
|
|
126
|
+
if (decodedServerResponseState !== decodedRequestState) {
|
|
128
127
|
throw createClientAuthError(ClientAuthErrorCodes.stateMismatch);
|
|
129
128
|
}
|
|
130
129
|
|
|
131
130
|
// Check for error
|
|
132
131
|
if (
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
132
|
+
serverResponse.error ||
|
|
133
|
+
serverResponse.error_description ||
|
|
134
|
+
serverResponse.suberror
|
|
136
135
|
) {
|
|
137
136
|
if (
|
|
138
137
|
isInteractionRequiredError(
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
138
|
+
serverResponse.error,
|
|
139
|
+
serverResponse.error_description,
|
|
140
|
+
serverResponse.suberror
|
|
142
141
|
)
|
|
143
142
|
) {
|
|
144
143
|
throw new InteractionRequiredAuthError(
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
144
|
+
serverResponse.error || "",
|
|
145
|
+
serverResponse.error_description,
|
|
146
|
+
serverResponse.suberror,
|
|
147
|
+
serverResponse.timestamp || "",
|
|
148
|
+
serverResponse.trace_id || "",
|
|
149
|
+
serverResponse.correlation_id || "",
|
|
150
|
+
serverResponse.claims || ""
|
|
152
151
|
);
|
|
153
152
|
}
|
|
154
153
|
|
|
155
154
|
throw new ServerError(
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
155
|
+
serverResponse.error || "",
|
|
156
|
+
serverResponse.error_description,
|
|
157
|
+
serverResponse.suberror
|
|
159
158
|
);
|
|
160
159
|
}
|
|
161
|
-
|
|
162
|
-
if (serverResponseHash.client_info) {
|
|
163
|
-
buildClientInfo(serverResponseHash.client_info, cryptoObj);
|
|
164
|
-
}
|
|
165
160
|
}
|
|
166
161
|
|
|
167
162
|
/**
|
|
@@ -415,7 +410,7 @@ export class ResponseHandler {
|
|
|
415
410
|
let cachedIdToken: IdTokenEntity | undefined;
|
|
416
411
|
let cachedAccount: AccountEntity | undefined;
|
|
417
412
|
if (serverTokenResponse.id_token && !!idTokenClaims) {
|
|
418
|
-
cachedIdToken =
|
|
413
|
+
cachedIdToken = CacheHelpers.createIdTokenEntity(
|
|
419
414
|
this.homeAccountIdentifier,
|
|
420
415
|
env,
|
|
421
416
|
serverTokenResponse.id_token,
|
|
@@ -468,16 +463,16 @@ export class ResponseHandler {
|
|
|
468
463
|
: undefined;
|
|
469
464
|
|
|
470
465
|
// non AAD scenarios can have empty realm
|
|
471
|
-
cachedAccessToken =
|
|
466
|
+
cachedAccessToken = CacheHelpers.createAccessTokenEntity(
|
|
472
467
|
this.homeAccountIdentifier,
|
|
473
468
|
env,
|
|
474
|
-
serverTokenResponse.access_token
|
|
469
|
+
serverTokenResponse.access_token,
|
|
475
470
|
this.clientId,
|
|
476
471
|
idTokenClaims?.tid || authority.tenant,
|
|
477
472
|
responseScopes.printScopes(),
|
|
478
473
|
tokenExpirationSeconds,
|
|
479
474
|
extendedTokenExpirationSeconds,
|
|
480
|
-
this.cryptoObj,
|
|
475
|
+
this.cryptoObj.base64Decode,
|
|
481
476
|
refreshOnSeconds,
|
|
482
477
|
serverTokenResponse.token_type,
|
|
483
478
|
userAssertionHash,
|
|
@@ -490,10 +485,10 @@ export class ResponseHandler {
|
|
|
490
485
|
// refreshToken
|
|
491
486
|
let cachedRefreshToken: RefreshTokenEntity | null = null;
|
|
492
487
|
if (serverTokenResponse.refresh_token) {
|
|
493
|
-
cachedRefreshToken =
|
|
488
|
+
cachedRefreshToken = CacheHelpers.createRefreshTokenEntity(
|
|
494
489
|
this.homeAccountIdentifier,
|
|
495
490
|
env,
|
|
496
|
-
serverTokenResponse.refresh_token
|
|
491
|
+
serverTokenResponse.refresh_token,
|
|
497
492
|
this.clientId,
|
|
498
493
|
serverTokenResponse.foci,
|
|
499
494
|
userAssertionHash
|
|
@@ -208,7 +208,7 @@ export const PerformanceEvents = {
|
|
|
208
208
|
* Functions from InteractionHandler (msal-browser)
|
|
209
209
|
*/
|
|
210
210
|
HandleCodeResponseFromServer: "handleCodeResponseFromServer",
|
|
211
|
-
|
|
211
|
+
HandleCodeResponse: "handleCodeResponse",
|
|
212
212
|
UpdateTokenEndpointAuthority: "updateTokenEndpointAuthority",
|
|
213
213
|
|
|
214
214
|
/**
|
|
@@ -229,6 +229,7 @@ export const PerformanceEvents = {
|
|
|
229
229
|
* handleServerTokenResponse API in ResponseHandler (msal-common)
|
|
230
230
|
*/
|
|
231
231
|
HandleServerTokenResponse: "handleServerTokenResponse",
|
|
232
|
+
DeserializeResponse: "deserializeResponse",
|
|
232
233
|
|
|
233
234
|
/**
|
|
234
235
|
* Authority functions
|
|
@@ -558,6 +559,13 @@ export type PerformanceEvent = {
|
|
|
558
559
|
* Nested App Auth Fields
|
|
559
560
|
*/
|
|
560
561
|
nestedAppAuthRequest?: boolean;
|
|
562
|
+
|
|
563
|
+
/**
|
|
564
|
+
* Multiple matched access/id/refresh tokens in the cache
|
|
565
|
+
*/
|
|
566
|
+
multiMatchedAT?: number;
|
|
567
|
+
multiMatchedID?: number;
|
|
568
|
+
multiMatchedRT?: number;
|
|
561
569
|
};
|
|
562
570
|
|
|
563
571
|
export const IntFields: ReadonlySet<string> = new Set([
|
|
@@ -570,4 +578,7 @@ export const IntFields: ReadonlySet<string> = new Set([
|
|
|
570
578
|
"queuedTimeMs",
|
|
571
579
|
"startTimeMs",
|
|
572
580
|
"status",
|
|
581
|
+
"multiMatchedAT",
|
|
582
|
+
"multiMatchedID",
|
|
583
|
+
"multiMatchedRT",
|
|
573
584
|
]);
|
|
@@ -160,7 +160,11 @@ export class ServerTelemetryManager {
|
|
|
160
160
|
* Get the server telemetry entity from cache or initialize a new one
|
|
161
161
|
*/
|
|
162
162
|
getLastRequests(): ServerTelemetryEntity {
|
|
163
|
-
const initialValue: ServerTelemetryEntity =
|
|
163
|
+
const initialValue: ServerTelemetryEntity = {
|
|
164
|
+
failedRequests: [],
|
|
165
|
+
errors: [],
|
|
166
|
+
cacheHits: 0,
|
|
167
|
+
};
|
|
164
168
|
const lastRequests = this.cacheManager.getServerTelemetry(
|
|
165
169
|
this.telemetryCacheKey
|
|
166
170
|
) as ServerTelemetryEntity;
|
|
@@ -181,11 +185,13 @@ export class ServerTelemetryManager {
|
|
|
181
185
|
this.cacheManager.removeItem(this.telemetryCacheKey);
|
|
182
186
|
} else {
|
|
183
187
|
// Partial data was flushed to server, construct a new telemetry cache item with errors that were not flushed
|
|
184
|
-
const serverTelemEntity =
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
lastRequests.errors.slice(numErrorsFlushed)
|
|
188
|
+
const serverTelemEntity: ServerTelemetryEntity = {
|
|
189
|
+
failedRequests: lastRequests.failedRequests.slice(
|
|
190
|
+
numErrorsFlushed * 2
|
|
191
|
+
), // failedRequests contains 2 items for each error
|
|
192
|
+
errors: lastRequests.errors.slice(numErrorsFlushed),
|
|
193
|
+
cacheHits: 0,
|
|
194
|
+
};
|
|
189
195
|
|
|
190
196
|
this.cacheManager.setServerTelemetry(
|
|
191
197
|
this.telemetryCacheKey,
|
package/src/url/UrlString.ts
CHANGED
|
@@ -3,22 +3,14 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { ServerAuthorizationCodeResponse } from "../response/ServerAuthorizationCodeResponse";
|
|
7
6
|
import {
|
|
8
7
|
createClientConfigurationError,
|
|
9
8
|
ClientConfigurationErrorCodes,
|
|
10
9
|
} from "../error/ClientConfigurationError";
|
|
11
|
-
import {
|
|
12
|
-
ClientAuthErrorCodes,
|
|
13
|
-
createClientAuthError,
|
|
14
|
-
} from "../error/ClientAuthError";
|
|
15
10
|
import { StringUtils } from "../utils/StringUtils";
|
|
16
11
|
import { IUri } from "./IUri";
|
|
17
|
-
import {
|
|
18
|
-
|
|
19
|
-
Constants,
|
|
20
|
-
ServerResponseType,
|
|
21
|
-
} from "../utils/Constants";
|
|
12
|
+
import { AADAuthorityConstants, Constants } from "../utils/Constants";
|
|
13
|
+
import * as UrlUtils from "../utils/UrlUtils";
|
|
22
14
|
|
|
23
15
|
/**
|
|
24
16
|
* Url object class which can perform various transformations on url strings.
|
|
@@ -39,7 +31,7 @@ export class UrlString {
|
|
|
39
31
|
);
|
|
40
32
|
}
|
|
41
33
|
|
|
42
|
-
if (!
|
|
34
|
+
if (!url.includes("#")) {
|
|
43
35
|
this._urlString = UrlString.canonicalizeUri(url);
|
|
44
36
|
}
|
|
45
37
|
}
|
|
@@ -142,13 +134,6 @@ export class UrlString {
|
|
|
142
134
|
return UrlString.constructAuthorityUriFromObject(urlObject);
|
|
143
135
|
}
|
|
144
136
|
|
|
145
|
-
/**
|
|
146
|
-
* Returns the anchor part(#) of the URL
|
|
147
|
-
*/
|
|
148
|
-
getHash(): string {
|
|
149
|
-
return UrlString.parseHash(this.urlString);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
137
|
/**
|
|
153
138
|
* Parses out the components from a url string.
|
|
154
139
|
* @returns An object with the various components. Please cache this value insted of calling this multiple times on the same url.
|
|
@@ -221,58 +206,6 @@ export class UrlString {
|
|
|
221
206
|
return relativeUrl;
|
|
222
207
|
}
|
|
223
208
|
|
|
224
|
-
/**
|
|
225
|
-
* Parses hash string from given string. Returns empty string if no hash symbol is found.
|
|
226
|
-
* @param hashString
|
|
227
|
-
*/
|
|
228
|
-
static parseHash(hashString: string): string {
|
|
229
|
-
const hashIndex1 = hashString.indexOf("#");
|
|
230
|
-
const hashIndex2 = hashString.indexOf("#/");
|
|
231
|
-
if (hashIndex2 > -1) {
|
|
232
|
-
return hashString.substring(hashIndex2 + 2);
|
|
233
|
-
} else if (hashIndex1 > -1) {
|
|
234
|
-
return hashString.substring(hashIndex1 + 1);
|
|
235
|
-
}
|
|
236
|
-
return Constants.EMPTY_STRING;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* Parses query string from given string. Returns empty string if no query symbol is found.
|
|
241
|
-
* @param queryString
|
|
242
|
-
*/
|
|
243
|
-
static parseQueryString(queryString: string): string {
|
|
244
|
-
const queryIndex1 = queryString.indexOf("?");
|
|
245
|
-
const queryIndex2 = queryString.indexOf("/?");
|
|
246
|
-
if (queryIndex2 > -1) {
|
|
247
|
-
return queryString.substring(queryIndex2 + 2);
|
|
248
|
-
} else if (queryIndex1 > -1) {
|
|
249
|
-
return queryString.substring(queryIndex1 + 1);
|
|
250
|
-
}
|
|
251
|
-
return Constants.EMPTY_STRING;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
/**
|
|
255
|
-
* Parses query server response string from given string.
|
|
256
|
-
* Extract hash between '?code=' and '#' if trailing '# is present.
|
|
257
|
-
* Returns empty string if no query symbol is found.
|
|
258
|
-
* @param queryString
|
|
259
|
-
*/
|
|
260
|
-
static parseQueryServerResponse(queryString: string): string {
|
|
261
|
-
const queryIndex1 = queryString.indexOf("?code");
|
|
262
|
-
const queryIndex2 = queryString.indexOf("/?code");
|
|
263
|
-
const hashIndex = queryString.indexOf("#");
|
|
264
|
-
if (queryIndex2 > -1 && hashIndex > -1) {
|
|
265
|
-
return queryString.substring(queryIndex2 + 2, hashIndex);
|
|
266
|
-
} else if (queryIndex2 > -1) {
|
|
267
|
-
return queryString.substring(queryIndex2 + 2);
|
|
268
|
-
} else if (queryIndex1 > -1 && hashIndex > -1) {
|
|
269
|
-
return queryString.substring(queryIndex1 + 1, hashIndex);
|
|
270
|
-
} else if (queryIndex1 > -1) {
|
|
271
|
-
return queryString.substring(queryIndex1 + 1);
|
|
272
|
-
}
|
|
273
|
-
return Constants.EMPTY_STRING;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
209
|
static constructAuthorityUriFromObject(urlObject: IUri): UrlString {
|
|
277
210
|
return new UrlString(
|
|
278
211
|
urlObject.Protocol +
|
|
@@ -283,91 +216,11 @@ export class UrlString {
|
|
|
283
216
|
);
|
|
284
217
|
}
|
|
285
218
|
|
|
286
|
-
/**
|
|
287
|
-
* Returns URL hash as server auth code response object.
|
|
288
|
-
*/
|
|
289
|
-
static getDeserializedHash(hash: string): ServerAuthorizationCodeResponse {
|
|
290
|
-
// Check if given hash is empty
|
|
291
|
-
if (!hash) {
|
|
292
|
-
return {};
|
|
293
|
-
}
|
|
294
|
-
// Strip the # symbol if present
|
|
295
|
-
const parsedHash = UrlString.parseHash(hash);
|
|
296
|
-
// If # symbol was not present, above will return empty string, so give original hash value
|
|
297
|
-
const deserializedHash: ServerAuthorizationCodeResponse =
|
|
298
|
-
StringUtils.queryStringToObject<ServerAuthorizationCodeResponse>(
|
|
299
|
-
parsedHash || hash
|
|
300
|
-
);
|
|
301
|
-
// Check if deserialization didn't work
|
|
302
|
-
if (!deserializedHash) {
|
|
303
|
-
throw createClientAuthError(
|
|
304
|
-
ClientAuthErrorCodes.hashNotDeserialized
|
|
305
|
-
);
|
|
306
|
-
}
|
|
307
|
-
return deserializedHash;
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
/**
|
|
311
|
-
* Returns URL query string as server auth code response object.
|
|
312
|
-
*/
|
|
313
|
-
static getDeserializedQueryString(
|
|
314
|
-
query: string
|
|
315
|
-
): ServerAuthorizationCodeResponse {
|
|
316
|
-
// Check if given query is empty
|
|
317
|
-
if (!query) {
|
|
318
|
-
return {};
|
|
319
|
-
}
|
|
320
|
-
// Strip the ? symbol if present
|
|
321
|
-
const parsedQueryString = UrlString.parseQueryString(query);
|
|
322
|
-
// If ? symbol was not present, above will return empty string, so give original query value
|
|
323
|
-
const deserializedQueryString: ServerAuthorizationCodeResponse =
|
|
324
|
-
StringUtils.queryStringToObject<ServerAuthorizationCodeResponse>(
|
|
325
|
-
parsedQueryString || query
|
|
326
|
-
);
|
|
327
|
-
// Check if deserialization didn't work
|
|
328
|
-
if (!deserializedQueryString) {
|
|
329
|
-
throw createClientAuthError(
|
|
330
|
-
ClientAuthErrorCodes.hashNotDeserialized
|
|
331
|
-
);
|
|
332
|
-
}
|
|
333
|
-
return deserializedQueryString;
|
|
334
|
-
}
|
|
335
|
-
/**
|
|
336
|
-
* Returns either deserialized query string or deserialized hash, depending on the serverResponseType
|
|
337
|
-
* as a server auth code response object.
|
|
338
|
-
*/
|
|
339
|
-
static getDeserializedCodeResponse(
|
|
340
|
-
serverResponseType: ServerResponseType | undefined,
|
|
341
|
-
hashFragment: string
|
|
342
|
-
): ServerAuthorizationCodeResponse {
|
|
343
|
-
const hashUrlString = new UrlString(hashFragment);
|
|
344
|
-
let serverParams: ServerAuthorizationCodeResponse;
|
|
345
|
-
if (serverResponseType === ServerResponseType.QUERY) {
|
|
346
|
-
serverParams = UrlString.getDeserializedQueryString(hashFragment);
|
|
347
|
-
} else {
|
|
348
|
-
serverParams = UrlString.getDeserializedHash(
|
|
349
|
-
hashUrlString.getHash()
|
|
350
|
-
);
|
|
351
|
-
}
|
|
352
|
-
return serverParams;
|
|
353
|
-
}
|
|
354
|
-
|
|
355
219
|
/**
|
|
356
220
|
* Check if the hash of the URL string contains known properties
|
|
221
|
+
* @deprecated This API will be removed in a future version
|
|
357
222
|
*/
|
|
358
|
-
static hashContainsKnownProperties(
|
|
359
|
-
|
|
360
|
-
// Hash doesn't contain key/value pairs
|
|
361
|
-
return false;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
const parameters: ServerAuthorizationCodeResponse =
|
|
365
|
-
UrlString.getDeserializedHash(hash);
|
|
366
|
-
return !!(
|
|
367
|
-
parameters.code ||
|
|
368
|
-
parameters.error_description ||
|
|
369
|
-
parameters.error ||
|
|
370
|
-
parameters.state
|
|
371
|
-
);
|
|
223
|
+
static hashContainsKnownProperties(response: string): boolean {
|
|
224
|
+
return !!UrlUtils.getDeserializedResponse(response);
|
|
372
225
|
}
|
|
373
226
|
}
|
package/src/utils/Constants.ts
CHANGED
|
@@ -51,7 +51,6 @@ export const Constants = {
|
|
|
51
51
|
IMDS_TIMEOUT: 2000,
|
|
52
52
|
AZURE_REGION_AUTO_DISCOVER_FLAG: "TryAutoDetect",
|
|
53
53
|
REGIONAL_AUTH_PUBLIC_CLOUD_SUFFIX: "login.microsoft.com",
|
|
54
|
-
REGIONAL_AUTH_NON_MSI_QUERY_STRING: "allowestsrnonmsi=true",
|
|
55
54
|
KNOWN_PUBLIC_CLOUDS: [
|
|
56
55
|
"login.microsoftonline.com",
|
|
57
56
|
"login.windows.net",
|
|
@@ -434,11 +433,12 @@ export const CacheOutcome = {
|
|
|
434
433
|
} as const;
|
|
435
434
|
export type CacheOutcome = (typeof CacheOutcome)[keyof typeof CacheOutcome];
|
|
436
435
|
|
|
437
|
-
export const
|
|
436
|
+
export const JsonWebTokenTypes = {
|
|
438
437
|
Jwt: "JWT",
|
|
439
438
|
Jwk: "JWK",
|
|
440
439
|
Pop: "pop",
|
|
441
440
|
} as const;
|
|
442
|
-
export type
|
|
441
|
+
export type JsonWebTokenTypes =
|
|
442
|
+
(typeof JsonWebTokenTypes)[keyof typeof JsonWebTokenTypes];
|
|
443
443
|
|
|
444
444
|
export const ONE_DAY_IN_MS = 86400000;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { ServerAuthorizationCodeResponse } from "../response/ServerAuthorizationCodeResponse";
|
|
7
|
+
import {
|
|
8
|
+
ClientAuthErrorCodes,
|
|
9
|
+
createClientAuthError,
|
|
10
|
+
} from "../error/ClientAuthError";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Parses hash string from given string. Returns empty string if no hash symbol is found.
|
|
14
|
+
* @param hashString
|
|
15
|
+
*/
|
|
16
|
+
export function stripLeadingHashOrQuery(responseString: string): string {
|
|
17
|
+
if (responseString.startsWith("#/")) {
|
|
18
|
+
return responseString.substring(2);
|
|
19
|
+
} else if (
|
|
20
|
+
responseString.startsWith("#") ||
|
|
21
|
+
responseString.startsWith("?")
|
|
22
|
+
) {
|
|
23
|
+
return responseString.substring(1);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return responseString;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Returns URL hash as server auth code response object.
|
|
31
|
+
*/
|
|
32
|
+
export function getDeserializedResponse(
|
|
33
|
+
responseString: string
|
|
34
|
+
): ServerAuthorizationCodeResponse | null {
|
|
35
|
+
// Check if given hash is empty
|
|
36
|
+
if (!responseString || responseString.indexOf("=") < 0) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
// Strip the # or ? symbol if present
|
|
41
|
+
const normalizedResponse = stripLeadingHashOrQuery(responseString);
|
|
42
|
+
// If # symbol was not present, above will return empty string, so give original hash value
|
|
43
|
+
const deserializedHash: ServerAuthorizationCodeResponse =
|
|
44
|
+
Object.fromEntries(new URLSearchParams(normalizedResponse));
|
|
45
|
+
|
|
46
|
+
// Check for known response properties
|
|
47
|
+
if (
|
|
48
|
+
deserializedHash.code ||
|
|
49
|
+
deserializedHash.error ||
|
|
50
|
+
deserializedHash.error_description ||
|
|
51
|
+
deserializedHash.state
|
|
52
|
+
) {
|
|
53
|
+
return deserializedHash;
|
|
54
|
+
}
|
|
55
|
+
} catch (e) {
|
|
56
|
+
throw createClientAuthError(ClientAuthErrorCodes.hashNotDeserialized);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return null;
|
|
60
|
+
}
|