@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
|
@@ -4,71 +4,11 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { CredentialEntity } from "./CredentialEntity";
|
|
7
|
-
import { CredentialType } from "../../utils/Constants";
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* Key:Value Schema:
|
|
13
|
-
*
|
|
14
|
-
* Key Example: uid.utid-login.microsoftonline.com-idtoken-clientId-contoso.com-
|
|
15
|
-
*
|
|
16
|
-
* Value Schema:
|
|
17
|
-
* {
|
|
18
|
-
* homeAccountId: home account identifier for the auth scheme,
|
|
19
|
-
* environment: entity that issued the token, represented as a full host
|
|
20
|
-
* credentialType: Type of credential as a string, can be one of the following: RefreshToken, AccessToken, IdToken, Password, Cookie, Certificate, Other
|
|
21
|
-
* clientId: client ID of the application
|
|
22
|
-
* secret: Actual credential as a string
|
|
23
|
-
* realm: Full tenant or organizational identifier that the account belongs to
|
|
24
|
-
* }
|
|
9
|
+
* Id Token Cache Type
|
|
25
10
|
*/
|
|
26
|
-
export
|
|
11
|
+
export type IdTokenEntity = CredentialEntity & {
|
|
12
|
+
/** Full tenant or organizational identifier that the account belongs to */
|
|
27
13
|
realm: string;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Create IdTokenEntity
|
|
31
|
-
* @param homeAccountId
|
|
32
|
-
* @param authenticationResult
|
|
33
|
-
* @param clientId
|
|
34
|
-
* @param authority
|
|
35
|
-
*/
|
|
36
|
-
static createIdTokenEntity(
|
|
37
|
-
homeAccountId: string,
|
|
38
|
-
environment: string,
|
|
39
|
-
idToken: string,
|
|
40
|
-
clientId: string,
|
|
41
|
-
tenantId: string
|
|
42
|
-
): IdTokenEntity {
|
|
43
|
-
const idTokenEntity = new IdTokenEntity();
|
|
44
|
-
|
|
45
|
-
idTokenEntity.credentialType = CredentialType.ID_TOKEN;
|
|
46
|
-
idTokenEntity.homeAccountId = homeAccountId;
|
|
47
|
-
idTokenEntity.environment = environment;
|
|
48
|
-
idTokenEntity.clientId = clientId;
|
|
49
|
-
idTokenEntity.secret = idToken;
|
|
50
|
-
idTokenEntity.realm = tenantId;
|
|
51
|
-
|
|
52
|
-
return idTokenEntity;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Validates an entity: checks for all expected params
|
|
57
|
-
* @param entity
|
|
58
|
-
*/
|
|
59
|
-
static isIdTokenEntity(entity: object): boolean {
|
|
60
|
-
if (!entity) {
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return (
|
|
65
|
-
entity.hasOwnProperty("homeAccountId") &&
|
|
66
|
-
entity.hasOwnProperty("environment") &&
|
|
67
|
-
entity.hasOwnProperty("credentialType") &&
|
|
68
|
-
entity.hasOwnProperty("realm") &&
|
|
69
|
-
entity.hasOwnProperty("clientId") &&
|
|
70
|
-
entity.hasOwnProperty("secret") &&
|
|
71
|
-
entity["credentialType"] === CredentialType.ID_TOKEN
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
14
|
+
};
|
|
@@ -4,75 +4,8 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { CredentialEntity } from "./CredentialEntity";
|
|
7
|
-
import { CredentialType } from "../../utils/Constants";
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* Key:Value Schema:
|
|
13
|
-
*
|
|
14
|
-
* Key Example: uid.utid-login.microsoftonline.com-refreshtoken-clientId--
|
|
15
|
-
*
|
|
16
|
-
* Value:
|
|
17
|
-
* {
|
|
18
|
-
* homeAccountId: home account identifier for the auth scheme,
|
|
19
|
-
* environment: entity that issued the token, represented as a full host
|
|
20
|
-
* credentialType: Type of credential as a string, can be one of the following: RefreshToken, AccessToken, IdToken, Password, Cookie, Certificate, Other
|
|
21
|
-
* clientId: client ID of the application
|
|
22
|
-
* secret: Actual credential as a string
|
|
23
|
-
* familyId: Family ID identifier, '1' represents Microsoft Family
|
|
24
|
-
* realm: Full tenant or organizational identifier that the account belongs to
|
|
25
|
-
* target: Permissions that are included in the token, or for refresh tokens, the resource identifier.
|
|
26
|
-
* }
|
|
9
|
+
* Refresh Token Cache Type
|
|
27
10
|
*/
|
|
28
|
-
export
|
|
29
|
-
familyId?: string;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Create RefreshTokenEntity
|
|
33
|
-
* @param homeAccountId
|
|
34
|
-
* @param authenticationResult
|
|
35
|
-
* @param clientId
|
|
36
|
-
* @param authority
|
|
37
|
-
*/
|
|
38
|
-
static createRefreshTokenEntity(
|
|
39
|
-
homeAccountId: string,
|
|
40
|
-
environment: string,
|
|
41
|
-
refreshToken: string,
|
|
42
|
-
clientId: string,
|
|
43
|
-
familyId?: string,
|
|
44
|
-
userAssertionHash?: string
|
|
45
|
-
): RefreshTokenEntity {
|
|
46
|
-
const rtEntity = new RefreshTokenEntity();
|
|
47
|
-
|
|
48
|
-
rtEntity.clientId = clientId;
|
|
49
|
-
rtEntity.credentialType = CredentialType.REFRESH_TOKEN;
|
|
50
|
-
rtEntity.environment = environment;
|
|
51
|
-
rtEntity.homeAccountId = homeAccountId;
|
|
52
|
-
rtEntity.secret = refreshToken;
|
|
53
|
-
rtEntity.userAssertionHash = userAssertionHash;
|
|
54
|
-
|
|
55
|
-
if (familyId) rtEntity.familyId = familyId;
|
|
56
|
-
|
|
57
|
-
return rtEntity;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Validates an entity: checks for all expected params
|
|
62
|
-
* @param entity
|
|
63
|
-
*/
|
|
64
|
-
static isRefreshTokenEntity(entity: object): boolean {
|
|
65
|
-
if (!entity) {
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return (
|
|
70
|
-
entity.hasOwnProperty("homeAccountId") &&
|
|
71
|
-
entity.hasOwnProperty("environment") &&
|
|
72
|
-
entity.hasOwnProperty("credentialType") &&
|
|
73
|
-
entity.hasOwnProperty("clientId") &&
|
|
74
|
-
entity.hasOwnProperty("secret") &&
|
|
75
|
-
entity["credentialType"] === CredentialType.REFRESH_TOKEN
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
11
|
+
export type RefreshTokenEntity = CredentialEntity;
|
|
@@ -3,36 +3,8 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export class ServerTelemetryEntity {
|
|
6
|
+
export type ServerTelemetryEntity = {
|
|
9
7
|
failedRequests: Array<string | number>;
|
|
10
8
|
errors: string[];
|
|
11
9
|
cacheHits: number;
|
|
12
|
-
|
|
13
|
-
constructor() {
|
|
14
|
-
this.failedRequests = [];
|
|
15
|
-
this.errors = [];
|
|
16
|
-
this.cacheHits = 0;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* validates if a given cache entry is "Telemetry", parses <key,value>
|
|
21
|
-
* @param key
|
|
22
|
-
* @param entity
|
|
23
|
-
*/
|
|
24
|
-
static isServerTelemetryEntity(key: string, entity?: object): boolean {
|
|
25
|
-
const validateKey: boolean =
|
|
26
|
-
key.indexOf(SERVER_TELEM_CONSTANTS.CACHE_KEY) === 0;
|
|
27
|
-
let validateEntity: boolean = true;
|
|
28
|
-
|
|
29
|
-
if (entity) {
|
|
30
|
-
validateEntity =
|
|
31
|
-
entity.hasOwnProperty("failedRequests") &&
|
|
32
|
-
entity.hasOwnProperty("errors") &&
|
|
33
|
-
entity.hasOwnProperty("cacheHits");
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return validateKey && validateEntity;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
10
|
+
};
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { extractTokenClaims } from "../../account/AuthToken";
|
|
7
|
+
import { TokenClaims } from "../../account/TokenClaims";
|
|
8
|
+
import {
|
|
9
|
+
ClientAuthErrorCodes,
|
|
10
|
+
createClientAuthError,
|
|
11
|
+
} from "../../error/ClientAuthError";
|
|
12
|
+
import {
|
|
13
|
+
AuthenticationScheme,
|
|
14
|
+
CredentialType,
|
|
15
|
+
SERVER_TELEM_CONSTANTS,
|
|
16
|
+
Separators,
|
|
17
|
+
} from "../../utils/Constants";
|
|
18
|
+
import { TimeUtils } from "../../utils/TimeUtils";
|
|
19
|
+
import { AccessTokenEntity } from "../entities/AccessTokenEntity";
|
|
20
|
+
import { CredentialEntity } from "../entities/CredentialEntity";
|
|
21
|
+
import { IdTokenEntity } from "../entities/IdTokenEntity";
|
|
22
|
+
import { RefreshTokenEntity } from "../entities/RefreshTokenEntity";
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Cache Key: <home_account_id>-<environment>-<credential_type>-<client_id or familyId>-<realm>-<scopes>-<claims hash>-<scheme>
|
|
26
|
+
* IdToken Example: uid.utid-login.microsoftonline.com-idtoken-app_client_id-contoso.com
|
|
27
|
+
* AccessToken Example: uid.utid-login.microsoftonline.com-accesstoken-app_client_id-contoso.com-scope1 scope2--pop
|
|
28
|
+
* RefreshToken Example: uid.utid-login.microsoftonline.com-refreshtoken-1-contoso.com
|
|
29
|
+
* @param credentialEntity
|
|
30
|
+
* @returns
|
|
31
|
+
*/
|
|
32
|
+
export function generateCredentialKey(
|
|
33
|
+
credentialEntity: CredentialEntity
|
|
34
|
+
): string {
|
|
35
|
+
const credentialKey = [
|
|
36
|
+
generateAccountId(credentialEntity),
|
|
37
|
+
generateCredentialId(credentialEntity),
|
|
38
|
+
generateTarget(credentialEntity),
|
|
39
|
+
generateClaimsHash(credentialEntity),
|
|
40
|
+
generateScheme(credentialEntity),
|
|
41
|
+
];
|
|
42
|
+
|
|
43
|
+
return credentialKey.join(Separators.CACHE_KEY_SEPARATOR).toLowerCase();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Create IdTokenEntity
|
|
48
|
+
* @param homeAccountId
|
|
49
|
+
* @param authenticationResult
|
|
50
|
+
* @param clientId
|
|
51
|
+
* @param authority
|
|
52
|
+
*/
|
|
53
|
+
export function createIdTokenEntity(
|
|
54
|
+
homeAccountId: string,
|
|
55
|
+
environment: string,
|
|
56
|
+
idToken: string,
|
|
57
|
+
clientId: string,
|
|
58
|
+
tenantId: string
|
|
59
|
+
): IdTokenEntity {
|
|
60
|
+
const idTokenEntity: IdTokenEntity = {
|
|
61
|
+
credentialType: CredentialType.ID_TOKEN,
|
|
62
|
+
homeAccountId: homeAccountId,
|
|
63
|
+
environment: environment,
|
|
64
|
+
clientId: clientId,
|
|
65
|
+
secret: idToken,
|
|
66
|
+
realm: tenantId,
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
return idTokenEntity;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Create AccessTokenEntity
|
|
74
|
+
* @param homeAccountId
|
|
75
|
+
* @param environment
|
|
76
|
+
* @param accessToken
|
|
77
|
+
* @param clientId
|
|
78
|
+
* @param tenantId
|
|
79
|
+
* @param scopes
|
|
80
|
+
* @param expiresOn
|
|
81
|
+
* @param extExpiresOn
|
|
82
|
+
*/
|
|
83
|
+
export function createAccessTokenEntity(
|
|
84
|
+
homeAccountId: string,
|
|
85
|
+
environment: string,
|
|
86
|
+
accessToken: string,
|
|
87
|
+
clientId: string,
|
|
88
|
+
tenantId: string,
|
|
89
|
+
scopes: string,
|
|
90
|
+
expiresOn: number,
|
|
91
|
+
extExpiresOn: number,
|
|
92
|
+
base64Decode: (input: string) => string,
|
|
93
|
+
refreshOn?: number,
|
|
94
|
+
tokenType?: AuthenticationScheme,
|
|
95
|
+
userAssertionHash?: string,
|
|
96
|
+
keyId?: string,
|
|
97
|
+
requestedClaims?: string,
|
|
98
|
+
requestedClaimsHash?: string
|
|
99
|
+
): AccessTokenEntity {
|
|
100
|
+
const atEntity: AccessTokenEntity = {
|
|
101
|
+
homeAccountId: homeAccountId,
|
|
102
|
+
credentialType: CredentialType.ACCESS_TOKEN,
|
|
103
|
+
secret: accessToken,
|
|
104
|
+
cachedAt: TimeUtils.nowSeconds().toString(),
|
|
105
|
+
expiresOn: expiresOn.toString(),
|
|
106
|
+
extendedExpiresOn: extExpiresOn.toString(),
|
|
107
|
+
environment: environment,
|
|
108
|
+
clientId: clientId,
|
|
109
|
+
realm: tenantId,
|
|
110
|
+
target: scopes,
|
|
111
|
+
tokenType: tokenType || AuthenticationScheme.BEARER,
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
if (userAssertionHash) {
|
|
115
|
+
atEntity.userAssertionHash = userAssertionHash;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (refreshOn) {
|
|
119
|
+
atEntity.refreshOn = refreshOn.toString();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (requestedClaims) {
|
|
123
|
+
atEntity.requestedClaims = requestedClaims;
|
|
124
|
+
atEntity.requestedClaimsHash = requestedClaimsHash;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/*
|
|
128
|
+
* Create Access Token With Auth Scheme instead of regular access token
|
|
129
|
+
* Cast to lower to handle "bearer" from ADFS
|
|
130
|
+
*/
|
|
131
|
+
if (
|
|
132
|
+
atEntity.tokenType?.toLowerCase() !==
|
|
133
|
+
AuthenticationScheme.BEARER.toLowerCase()
|
|
134
|
+
) {
|
|
135
|
+
atEntity.credentialType = CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME;
|
|
136
|
+
switch (atEntity.tokenType) {
|
|
137
|
+
case AuthenticationScheme.POP:
|
|
138
|
+
// Make sure keyId is present and add it to credential
|
|
139
|
+
const tokenClaims: TokenClaims | null = extractTokenClaims(
|
|
140
|
+
accessToken,
|
|
141
|
+
base64Decode
|
|
142
|
+
);
|
|
143
|
+
if (!tokenClaims?.cnf?.kid) {
|
|
144
|
+
throw createClientAuthError(
|
|
145
|
+
ClientAuthErrorCodes.tokenClaimsCnfRequiredForSignedJwt
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
atEntity.keyId = tokenClaims.cnf.kid;
|
|
149
|
+
break;
|
|
150
|
+
case AuthenticationScheme.SSH:
|
|
151
|
+
atEntity.keyId = keyId;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return atEntity;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Create RefreshTokenEntity
|
|
160
|
+
* @param homeAccountId
|
|
161
|
+
* @param authenticationResult
|
|
162
|
+
* @param clientId
|
|
163
|
+
* @param authority
|
|
164
|
+
*/
|
|
165
|
+
export function createRefreshTokenEntity(
|
|
166
|
+
homeAccountId: string,
|
|
167
|
+
environment: string,
|
|
168
|
+
refreshToken: string,
|
|
169
|
+
clientId: string,
|
|
170
|
+
familyId?: string,
|
|
171
|
+
userAssertionHash?: string
|
|
172
|
+
): RefreshTokenEntity {
|
|
173
|
+
const rtEntity: RefreshTokenEntity = {
|
|
174
|
+
credentialType: CredentialType.REFRESH_TOKEN,
|
|
175
|
+
homeAccountId: homeAccountId,
|
|
176
|
+
environment: environment,
|
|
177
|
+
clientId: clientId,
|
|
178
|
+
secret: refreshToken,
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
if (userAssertionHash) {
|
|
182
|
+
rtEntity.userAssertionHash = userAssertionHash;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (familyId) {
|
|
186
|
+
rtEntity.familyId = familyId;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return rtEntity;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export function isCredentialEntity(entity: object): boolean {
|
|
193
|
+
return (
|
|
194
|
+
entity.hasOwnProperty("homeAccountId") &&
|
|
195
|
+
entity.hasOwnProperty("environment") &&
|
|
196
|
+
entity.hasOwnProperty("credentialType") &&
|
|
197
|
+
entity.hasOwnProperty("clientId") &&
|
|
198
|
+
entity.hasOwnProperty("secret")
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Validates an entity: checks for all expected params
|
|
204
|
+
* @param entity
|
|
205
|
+
*/
|
|
206
|
+
export function isAccessTokenEntity(entity: object): boolean {
|
|
207
|
+
if (!entity) {
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return (
|
|
212
|
+
isCredentialEntity(entity) &&
|
|
213
|
+
entity.hasOwnProperty("realm") &&
|
|
214
|
+
entity.hasOwnProperty("target") &&
|
|
215
|
+
(entity["credentialType"] === CredentialType.ACCESS_TOKEN ||
|
|
216
|
+
entity["credentialType"] ===
|
|
217
|
+
CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME)
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Validates an entity: checks for all expected params
|
|
223
|
+
* @param entity
|
|
224
|
+
*/
|
|
225
|
+
export function isIdTokenEntity(entity: object): boolean {
|
|
226
|
+
if (!entity) {
|
|
227
|
+
return false;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return (
|
|
231
|
+
isCredentialEntity(entity) &&
|
|
232
|
+
entity.hasOwnProperty("realm") &&
|
|
233
|
+
entity["credentialType"] === CredentialType.ID_TOKEN
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Validates an entity: checks for all expected params
|
|
239
|
+
* @param entity
|
|
240
|
+
*/
|
|
241
|
+
export function isRefreshTokenEntity(entity: object): boolean {
|
|
242
|
+
if (!entity) {
|
|
243
|
+
return false;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
return (
|
|
247
|
+
isCredentialEntity(entity) &&
|
|
248
|
+
entity["credentialType"] === CredentialType.REFRESH_TOKEN
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Generate Account Id key component as per the schema: <home_account_id>-<environment>
|
|
254
|
+
*/
|
|
255
|
+
function generateAccountId(credentialEntity: CredentialEntity): string {
|
|
256
|
+
const accountId: Array<string> = [
|
|
257
|
+
credentialEntity.homeAccountId,
|
|
258
|
+
credentialEntity.environment,
|
|
259
|
+
];
|
|
260
|
+
return accountId.join(Separators.CACHE_KEY_SEPARATOR).toLowerCase();
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Generate Credential Id key component as per the schema: <credential_type>-<client_id>-<realm>
|
|
265
|
+
*/
|
|
266
|
+
function generateCredentialId(credentialEntity: CredentialEntity): string {
|
|
267
|
+
const clientOrFamilyId =
|
|
268
|
+
credentialEntity.credentialType === CredentialType.REFRESH_TOKEN
|
|
269
|
+
? credentialEntity.familyId || credentialEntity.clientId
|
|
270
|
+
: credentialEntity.clientId;
|
|
271
|
+
const credentialId: Array<string> = [
|
|
272
|
+
credentialEntity.credentialType,
|
|
273
|
+
clientOrFamilyId,
|
|
274
|
+
credentialEntity.realm || "",
|
|
275
|
+
];
|
|
276
|
+
|
|
277
|
+
return credentialId.join(Separators.CACHE_KEY_SEPARATOR).toLowerCase();
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Generate target key component as per schema: <target>
|
|
282
|
+
*/
|
|
283
|
+
function generateTarget(credentialEntity: CredentialEntity): string {
|
|
284
|
+
return (credentialEntity.target || "").toLowerCase();
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Generate requested claims key component as per schema: <requestedClaims>
|
|
289
|
+
*/
|
|
290
|
+
function generateClaimsHash(credentialEntity: CredentialEntity): string {
|
|
291
|
+
return (credentialEntity.requestedClaimsHash || "").toLowerCase();
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Generate scheme key componenet as per schema: <scheme>
|
|
296
|
+
*/
|
|
297
|
+
function generateScheme(credentialEntity: CredentialEntity): string {
|
|
298
|
+
/*
|
|
299
|
+
* PoP Tokens and SSH certs include scheme in cache key
|
|
300
|
+
* Cast to lowercase to handle "bearer" from ADFS
|
|
301
|
+
*/
|
|
302
|
+
return credentialEntity.tokenType &&
|
|
303
|
+
credentialEntity.tokenType.toLowerCase() !==
|
|
304
|
+
AuthenticationScheme.BEARER.toLowerCase()
|
|
305
|
+
? credentialEntity.tokenType.toLowerCase()
|
|
306
|
+
: "";
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* validates if a given cache entry is "Telemetry", parses <key,value>
|
|
311
|
+
* @param key
|
|
312
|
+
* @param entity
|
|
313
|
+
*/
|
|
314
|
+
export function isServerTelemetryEntity(key: string, entity?: object): boolean {
|
|
315
|
+
const validateKey: boolean =
|
|
316
|
+
key.indexOf(SERVER_TELEM_CONSTANTS.CACHE_KEY) === 0;
|
|
317
|
+
let validateEntity: boolean = true;
|
|
318
|
+
|
|
319
|
+
if (entity) {
|
|
320
|
+
validateEntity =
|
|
321
|
+
entity.hasOwnProperty("failedRequests") &&
|
|
322
|
+
entity.hasOwnProperty("errors") &&
|
|
323
|
+
entity.hasOwnProperty("cacheHits");
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
return validateKey && validateEntity;
|
|
327
|
+
}
|
|
@@ -171,7 +171,7 @@ export class AuthorizationCodeClient extends BaseClient {
|
|
|
171
171
|
* @param hashFragment
|
|
172
172
|
*/
|
|
173
173
|
handleFragmentResponse(
|
|
174
|
-
|
|
174
|
+
serverParams: ServerAuthorizationCodeResponse,
|
|
175
175
|
cachedState: string
|
|
176
176
|
): AuthorizationCodePayload {
|
|
177
177
|
// Handle responses.
|
|
@@ -184,18 +184,10 @@ export class AuthorizationCodeClient extends BaseClient {
|
|
|
184
184
|
null
|
|
185
185
|
);
|
|
186
186
|
|
|
187
|
-
const serverParams: ServerAuthorizationCodeResponse =
|
|
188
|
-
UrlString.getDeserializedCodeResponse(
|
|
189
|
-
this.config.authOptions.authority.options.OIDCOptions
|
|
190
|
-
?.serverResponseType,
|
|
191
|
-
hashFragment
|
|
192
|
-
);
|
|
193
|
-
|
|
194
187
|
// Get code response
|
|
195
188
|
responseHandler.validateServerAuthorizationCodeResponse(
|
|
196
189
|
serverParams,
|
|
197
|
-
cachedState
|
|
198
|
-
this.cryptoUtils
|
|
190
|
+
cachedState
|
|
199
191
|
);
|
|
200
192
|
|
|
201
193
|
// throw when there is no auth code in the response
|
|
@@ -204,11 +196,8 @@ export class AuthorizationCodeClient extends BaseClient {
|
|
|
204
196
|
ClientAuthErrorCodes.authorizationCodeMissingFromServerResponse
|
|
205
197
|
);
|
|
206
198
|
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
// Code param is optional in ServerAuthorizationCodeResponse but required in AuthorizationCodePaylod
|
|
210
|
-
code: serverParams.code,
|
|
211
|
-
};
|
|
199
|
+
|
|
200
|
+
return serverParams as AuthorizationCodePayload;
|
|
212
201
|
}
|
|
213
202
|
|
|
214
203
|
/**
|
package/src/client/BaseClient.ts
CHANGED
|
@@ -19,15 +19,13 @@ import { CacheManager } from "../cache/CacheManager";
|
|
|
19
19
|
import { ServerTelemetryManager } from "../telemetry/server/ServerTelemetryManager";
|
|
20
20
|
import { RequestThumbprint } from "../network/RequestThumbprint";
|
|
21
21
|
import { version, name } from "../packageMetadata";
|
|
22
|
-
import {
|
|
23
|
-
createClientAuthError,
|
|
24
|
-
ClientAuthErrorCodes,
|
|
25
|
-
} from "../error/ClientAuthError";
|
|
26
22
|
import { CcsCredential, CcsCredentialType } from "../account/CcsCredential";
|
|
27
23
|
import { buildClientInfoFromHomeAccountId } from "../account/ClientInfo";
|
|
28
24
|
import { IPerformanceClient } from "../telemetry/performance/IPerformanceClient";
|
|
29
25
|
import { RequestParameterBuilder } from "../request/RequestParameterBuilder";
|
|
30
26
|
import { BaseAuthRequest } from "../request/BaseAuthRequest";
|
|
27
|
+
import { AuthorityFactory } from "../authority/AuthorityFactory";
|
|
28
|
+
import { PerformanceEvents } from "../telemetry/performance/PerformanceEvent";
|
|
31
29
|
|
|
32
30
|
/**
|
|
33
31
|
* Base application class which will construct requests to send to and handle responses from the Microsoft STS using the authorization code flow.
|
|
@@ -184,13 +182,26 @@ export abstract class BaseClient {
|
|
|
184
182
|
* Updates the authority object of the client. Endpoint discovery must be completed.
|
|
185
183
|
* @param updatedAuthority
|
|
186
184
|
*/
|
|
187
|
-
updateAuthority(
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
185
|
+
async updateAuthority(
|
|
186
|
+
cloudInstanceHostname: string,
|
|
187
|
+
correlationId: string
|
|
188
|
+
): Promise<void> {
|
|
189
|
+
this.performanceClient?.addQueueMeasurement(
|
|
190
|
+
PerformanceEvents.UpdateTokenEndpointAuthority,
|
|
191
|
+
correlationId
|
|
192
|
+
);
|
|
193
|
+
const cloudInstanceAuthorityUri = `https://${cloudInstanceHostname}/${this.authority.tenant}/`;
|
|
194
|
+
const cloudInstanceAuthority =
|
|
195
|
+
await AuthorityFactory.createDiscoveredInstance(
|
|
196
|
+
cloudInstanceAuthorityUri,
|
|
197
|
+
this.networkClient,
|
|
198
|
+
this.cacheManager,
|
|
199
|
+
this.authority.options,
|
|
200
|
+
this.logger,
|
|
201
|
+
this.performanceClient,
|
|
202
|
+
correlationId
|
|
191
203
|
);
|
|
192
|
-
|
|
193
|
-
this.authority = updatedAuthority;
|
|
204
|
+
this.authority = cloudInstanceAuthority;
|
|
194
205
|
}
|
|
195
206
|
|
|
196
207
|
/**
|
|
@@ -202,7 +202,13 @@ export class RefreshTokenClient extends BaseClient {
|
|
|
202
202
|
this.logger,
|
|
203
203
|
this.performanceClient,
|
|
204
204
|
request.correlationId
|
|
205
|
-
)(
|
|
205
|
+
)(
|
|
206
|
+
request.account,
|
|
207
|
+
foci,
|
|
208
|
+
undefined,
|
|
209
|
+
this.performanceClient,
|
|
210
|
+
request.correlationId
|
|
211
|
+
);
|
|
206
212
|
|
|
207
213
|
if (!refreshToken) {
|
|
208
214
|
throw createInteractionRequiredAuthError(
|
|
@@ -124,7 +124,9 @@ export class SilentFlowClient extends BaseClient {
|
|
|
124
124
|
const cacheRecord = this.cacheManager.readCacheRecord(
|
|
125
125
|
request.account,
|
|
126
126
|
request,
|
|
127
|
-
environment
|
|
127
|
+
environment,
|
|
128
|
+
this.performanceClient,
|
|
129
|
+
request.correlationId
|
|
128
130
|
);
|
|
129
131
|
|
|
130
132
|
if (!cacheRecord.accessToken) {
|
|
@@ -190,9 +192,11 @@ export class SilentFlowClient extends BaseClient {
|
|
|
190
192
|
},
|
|
191
193
|
correlationId
|
|
192
194
|
);
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
195
|
+
if (cacheOutcome !== CacheOutcome.NOT_APPLICABLE) {
|
|
196
|
+
this.logger.info(
|
|
197
|
+
`Token refresh is required due to cache outcome: ${cacheOutcome}`
|
|
198
|
+
);
|
|
199
|
+
}
|
|
196
200
|
}
|
|
197
201
|
|
|
198
202
|
/**
|
package/src/crypto/ICrypto.ts
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
createClientAuthError,
|
|
9
9
|
} from "../error/ClientAuthError";
|
|
10
10
|
import { BaseAuthRequest } from "../request/BaseAuthRequest";
|
|
11
|
-
import { SignedHttpRequest } from "./SignedHttpRequest";
|
|
11
|
+
import { ShrOptions, SignedHttpRequest } from "./SignedHttpRequest";
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* The PkceCodes type describes the structure
|
|
@@ -22,7 +22,11 @@ export type PkceCodes = {
|
|
|
22
22
|
|
|
23
23
|
export type SignedHttpRequestParameters = Pick<
|
|
24
24
|
BaseAuthRequest,
|
|
25
|
-
|
|
25
|
+
| "resourceRequestMethod"
|
|
26
|
+
| "resourceRequestUri"
|
|
27
|
+
| "shrClaims"
|
|
28
|
+
| "shrNonce"
|
|
29
|
+
| "shrOptions"
|
|
26
30
|
> & {
|
|
27
31
|
correlationId?: string;
|
|
28
32
|
};
|
|
@@ -68,6 +72,7 @@ export interface ICrypto {
|
|
|
68
72
|
signJwt(
|
|
69
73
|
payload: SignedHttpRequest,
|
|
70
74
|
kid: string,
|
|
75
|
+
shrOptions?: ShrOptions,
|
|
71
76
|
correlationId?: string
|
|
72
77
|
): Promise<string>;
|
|
73
78
|
/**
|