Estructura inicial del proyecto
This commit is contained in:
46
backend/node_modules/@azure/msal-node/src/cache/CacheHelpers.ts
generated
vendored
Normal file
46
backend/node_modules/@azure/msal-node/src/cache/CacheHelpers.ts
generated
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import {
|
||||
AccountInfo,
|
||||
Constants,
|
||||
CredentialEntity,
|
||||
} from "@azure/msal-common/node";
|
||||
import { CACHE } from "../utils/Constants.js";
|
||||
|
||||
export function generateCredentialKey(credential: CredentialEntity): string {
|
||||
const familyId =
|
||||
(credential.credentialType === Constants.CredentialType.REFRESH_TOKEN &&
|
||||
credential.familyId) ||
|
||||
credential.clientId;
|
||||
const scheme =
|
||||
credential.tokenType &&
|
||||
credential.tokenType.toLowerCase() !==
|
||||
Constants.AuthenticationScheme.BEARER.toLowerCase()
|
||||
? credential.tokenType.toLowerCase()
|
||||
: "";
|
||||
const credentialKey = [
|
||||
credential.homeAccountId,
|
||||
credential.environment,
|
||||
credential.credentialType,
|
||||
familyId,
|
||||
credential.realm || "",
|
||||
credential.target || "",
|
||||
scheme,
|
||||
];
|
||||
|
||||
return credentialKey.join(CACHE.KEY_SEPARATOR).toLowerCase();
|
||||
}
|
||||
|
||||
export function generateAccountKey(account: AccountInfo): string {
|
||||
const homeTenantId = account.homeAccountId.split(".")[1];
|
||||
const accountKey = [
|
||||
account.homeAccountId,
|
||||
account.environment,
|
||||
homeTenantId || account.tenantId || "",
|
||||
];
|
||||
|
||||
return accountKey.join(CACHE.KEY_SEPARATOR).toLowerCase();
|
||||
}
|
||||
24
backend/node_modules/@azure/msal-node/src/cache/ITokenCache.ts
generated
vendored
Normal file
24
backend/node_modules/@azure/msal-node/src/cache/ITokenCache.ts
generated
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import { AccountInfo } from "@azure/msal-common/node";
|
||||
|
||||
/**
|
||||
* Token cache interface for the client, giving access to cache APIs
|
||||
* @public
|
||||
*/
|
||||
export interface ITokenCache {
|
||||
/** API that retrieves all accounts currently in cache to the user */
|
||||
getAllAccounts(): Promise<AccountInfo[]>;
|
||||
|
||||
/** Returns the signed in account matching homeAccountId */
|
||||
getAccountByHomeId(homeAccountId: string): Promise<AccountInfo | null>;
|
||||
|
||||
/** Returns the signed in account matching localAccountId */
|
||||
getAccountByLocalId(localAccountId: string): Promise<AccountInfo | null>;
|
||||
|
||||
/** API to remove a specific account and the relevant data from cache */
|
||||
removeAccount(account: AccountInfo): Promise<void>;
|
||||
}
|
||||
568
backend/node_modules/@azure/msal-node/src/cache/NodeStorage.ts
generated
vendored
Normal file
568
backend/node_modules/@azure/msal-node/src/cache/NodeStorage.ts
generated
vendored
Normal file
@ -0,0 +1,568 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import {
|
||||
TokenKeys,
|
||||
AccountEntity,
|
||||
IdTokenEntity,
|
||||
AccessTokenEntity,
|
||||
RefreshTokenEntity,
|
||||
AppMetadataEntity,
|
||||
ServerTelemetryEntity,
|
||||
ThrottlingEntity,
|
||||
CacheManager,
|
||||
Logger,
|
||||
ValidCacheType,
|
||||
ICrypto,
|
||||
AuthorityMetadataEntity,
|
||||
ValidCredentialType,
|
||||
StaticAuthorityOptions,
|
||||
CacheHelpers,
|
||||
AccountEntityUtils,
|
||||
CredentialEntity,
|
||||
AccountInfo,
|
||||
StubPerformanceClient,
|
||||
} from "@azure/msal-common/node";
|
||||
|
||||
import { Deserializer } from "./serializer/Deserializer.js";
|
||||
import { Serializer } from "./serializer/Serializer.js";
|
||||
import {
|
||||
InMemoryCache,
|
||||
JsonCache,
|
||||
CacheKVStore,
|
||||
} from "./serializer/SerializerTypes.js";
|
||||
import { generateAccountKey, generateCredentialKey } from "./CacheHelpers.js";
|
||||
|
||||
/**
|
||||
* This class implements Storage for node, reading cache from user specified storage location or an extension library
|
||||
* @public
|
||||
*/
|
||||
export class NodeStorage extends CacheManager {
|
||||
// Cache configuration, either set by user or default values.
|
||||
private logger: Logger;
|
||||
private cache: CacheKVStore = {};
|
||||
private changeEmitters: Array<Function> = [];
|
||||
|
||||
constructor(
|
||||
logger: Logger,
|
||||
clientId: string,
|
||||
cryptoImpl: ICrypto,
|
||||
staticAuthorityOptions?: StaticAuthorityOptions
|
||||
) {
|
||||
super(
|
||||
clientId,
|
||||
cryptoImpl,
|
||||
logger,
|
||||
new StubPerformanceClient(),
|
||||
staticAuthorityOptions
|
||||
);
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Queue up callbacks
|
||||
* @param func - a callback function for cache change indication
|
||||
*/
|
||||
registerChangeEmitter(func: () => void): void {
|
||||
this.changeEmitters.push(func);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke the callback when cache changes
|
||||
*/
|
||||
emitChange(): void {
|
||||
this.changeEmitters.forEach((func) => func.call(null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts cacheKVStore to InMemoryCache
|
||||
* @param cache - key value store
|
||||
*/
|
||||
cacheToInMemoryCache(cache: CacheKVStore): InMemoryCache {
|
||||
const inMemoryCache: InMemoryCache = {
|
||||
accounts: {},
|
||||
idTokens: {},
|
||||
accessTokens: {},
|
||||
refreshTokens: {},
|
||||
appMetadata: {},
|
||||
};
|
||||
|
||||
for (const key in cache) {
|
||||
const value = cache[key];
|
||||
if (typeof value !== "object") {
|
||||
continue;
|
||||
}
|
||||
if (AccountEntityUtils.isAccountEntity(value)) {
|
||||
inMemoryCache.accounts[key] = value as AccountEntity;
|
||||
} else if (CacheHelpers.isIdTokenEntity(value)) {
|
||||
inMemoryCache.idTokens[key] = value as IdTokenEntity;
|
||||
} else if (CacheHelpers.isAccessTokenEntity(value)) {
|
||||
inMemoryCache.accessTokens[key] = value as AccessTokenEntity;
|
||||
} else if (CacheHelpers.isRefreshTokenEntity(value)) {
|
||||
inMemoryCache.refreshTokens[key] = value as RefreshTokenEntity;
|
||||
} else if (CacheHelpers.isAppMetadataEntity(key, value)) {
|
||||
inMemoryCache.appMetadata[key] = value as AppMetadataEntity;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return inMemoryCache;
|
||||
}
|
||||
|
||||
/**
|
||||
* converts inMemoryCache to CacheKVStore
|
||||
* @param inMemoryCache - kvstore map for inmemory
|
||||
*/
|
||||
inMemoryCacheToCache(inMemoryCache: InMemoryCache): CacheKVStore {
|
||||
// convert in memory cache to a flat Key-Value map
|
||||
let cache = this.getCache();
|
||||
|
||||
cache = {
|
||||
...cache,
|
||||
...inMemoryCache.accounts,
|
||||
...inMemoryCache.idTokens,
|
||||
...inMemoryCache.accessTokens,
|
||||
...inMemoryCache.refreshTokens,
|
||||
...inMemoryCache.appMetadata,
|
||||
};
|
||||
|
||||
// convert in memory cache to a flat Key-Value map
|
||||
return cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the current in memory cache for the client
|
||||
*/
|
||||
getInMemoryCache(): InMemoryCache {
|
||||
this.logger.trace("Getting in-memory cache", "");
|
||||
|
||||
// convert the cache key value store to inMemoryCache
|
||||
const inMemoryCache = this.cacheToInMemoryCache(this.getCache());
|
||||
return inMemoryCache;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the current in memory cache for the client
|
||||
* @param inMemoryCache - key value map in memory
|
||||
*/
|
||||
setInMemoryCache(inMemoryCache: InMemoryCache): void {
|
||||
this.logger.trace("Setting in-memory cache", "");
|
||||
|
||||
// convert and append the inMemoryCache to cacheKVStore
|
||||
const cache = this.inMemoryCacheToCache(inMemoryCache);
|
||||
this.setCache(cache);
|
||||
|
||||
this.emitChange();
|
||||
}
|
||||
|
||||
/**
|
||||
* get the current cache key-value store
|
||||
*/
|
||||
getCache(): CacheKVStore {
|
||||
this.logger.trace("Getting cache key-value store", "");
|
||||
return this.cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the current cache (key value store)
|
||||
* @param cacheMap - key value map
|
||||
*/
|
||||
setCache(cache: CacheKVStore): void {
|
||||
this.logger.trace("Setting cache key value store", "");
|
||||
this.cache = cache;
|
||||
|
||||
// mark change in cache
|
||||
this.emitChange();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets cache item with given key.
|
||||
* @param key - lookup key for the cache entry
|
||||
*/
|
||||
getItem(key: string): ValidCacheType {
|
||||
this.logger.tracePii(`Item key: ${key}`, "");
|
||||
|
||||
// read cache
|
||||
const cache = this.getCache();
|
||||
return cache[key];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets cache item with given key-value
|
||||
* @param key - lookup key for the cache entry
|
||||
* @param value - value of the cache entry
|
||||
*/
|
||||
setItem(key: string, value: ValidCacheType): void {
|
||||
this.logger.tracePii(`Item key: ${key}`, "");
|
||||
|
||||
// read cache
|
||||
const cache = this.getCache();
|
||||
cache[key] = value;
|
||||
|
||||
// write to cache
|
||||
this.setCache(cache);
|
||||
}
|
||||
|
||||
generateCredentialKey(credential: CredentialEntity): string {
|
||||
return generateCredentialKey(credential);
|
||||
}
|
||||
|
||||
generateAccountKey(account: AccountInfo): string {
|
||||
return generateAccountKey(account);
|
||||
}
|
||||
|
||||
getAccountKeys(): string[] {
|
||||
const inMemoryCache = this.getInMemoryCache();
|
||||
const accountKeys = Object.keys(inMemoryCache.accounts);
|
||||
|
||||
return accountKeys;
|
||||
}
|
||||
|
||||
getTokenKeys(): TokenKeys {
|
||||
const inMemoryCache = this.getInMemoryCache();
|
||||
const tokenKeys = {
|
||||
idToken: Object.keys(inMemoryCache.idTokens),
|
||||
accessToken: Object.keys(inMemoryCache.accessTokens),
|
||||
refreshToken: Object.keys(inMemoryCache.refreshTokens),
|
||||
};
|
||||
|
||||
return tokenKeys;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads account from cache, builds it into an account entity and returns it.
|
||||
* @param accountKey - lookup key to fetch cache type AccountEntity
|
||||
* @returns
|
||||
*/
|
||||
getAccount(accountKey: string): AccountEntity | null {
|
||||
const cachedAccount = this.getItem(accountKey);
|
||||
return cachedAccount && typeof cachedAccount === "object"
|
||||
? ({ ...cachedAccount } as AccountEntity)
|
||||
: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* set account entity
|
||||
* @param account - cache value to be set of type AccountEntity
|
||||
*/
|
||||
async setAccount(account: AccountEntity): Promise<void> {
|
||||
const accountKey = this.generateAccountKey(
|
||||
AccountEntityUtils.getAccountInfo(account)
|
||||
);
|
||||
this.setItem(accountKey, account);
|
||||
}
|
||||
|
||||
/**
|
||||
* fetch the idToken credential
|
||||
* @param idTokenKey - lookup key to fetch cache type IdTokenEntity
|
||||
*/
|
||||
getIdTokenCredential(idTokenKey: string): IdTokenEntity | null {
|
||||
const idToken = this.getItem(idTokenKey) as IdTokenEntity;
|
||||
if (CacheHelpers.isIdTokenEntity(idToken)) {
|
||||
return idToken;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* set idToken credential
|
||||
* @param idToken - cache value to be set of type IdTokenEntity
|
||||
*/
|
||||
async setIdTokenCredential(idToken: IdTokenEntity): Promise<void> {
|
||||
const idTokenKey = this.generateCredentialKey(idToken);
|
||||
this.setItem(idTokenKey, idToken);
|
||||
}
|
||||
|
||||
/**
|
||||
* fetch the accessToken credential
|
||||
* @param accessTokenKey - lookup key to fetch cache type AccessTokenEntity
|
||||
*/
|
||||
getAccessTokenCredential(accessTokenKey: string): AccessTokenEntity | null {
|
||||
const accessToken = this.getItem(accessTokenKey) as AccessTokenEntity;
|
||||
if (CacheHelpers.isAccessTokenEntity(accessToken)) {
|
||||
return accessToken;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* set accessToken credential
|
||||
* @param accessToken - cache value to be set of type AccessTokenEntity
|
||||
*/
|
||||
async setAccessTokenCredential(
|
||||
accessToken: AccessTokenEntity
|
||||
): Promise<void> {
|
||||
const accessTokenKey = this.generateCredentialKey(accessToken);
|
||||
this.setItem(accessTokenKey, accessToken);
|
||||
}
|
||||
|
||||
/**
|
||||
* fetch the refreshToken credential
|
||||
* @param refreshTokenKey - lookup key to fetch cache type RefreshTokenEntity
|
||||
*/
|
||||
getRefreshTokenCredential(
|
||||
refreshTokenKey: string
|
||||
): RefreshTokenEntity | null {
|
||||
const refreshToken = this.getItem(
|
||||
refreshTokenKey
|
||||
) as RefreshTokenEntity;
|
||||
if (CacheHelpers.isRefreshTokenEntity(refreshToken)) {
|
||||
return refreshToken as RefreshTokenEntity;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* set refreshToken credential
|
||||
* @param refreshToken - cache value to be set of type RefreshTokenEntity
|
||||
*/
|
||||
async setRefreshTokenCredential(
|
||||
refreshToken: RefreshTokenEntity
|
||||
): Promise<void> {
|
||||
const refreshTokenKey = this.generateCredentialKey(refreshToken);
|
||||
this.setItem(refreshTokenKey, refreshToken);
|
||||
}
|
||||
|
||||
/**
|
||||
* fetch appMetadata entity from the platform cache
|
||||
* @param appMetadataKey - lookup key to fetch cache type AppMetadataEntity
|
||||
*/
|
||||
getAppMetadata(appMetadataKey: string): AppMetadataEntity | null {
|
||||
const appMetadata: AppMetadataEntity = this.getItem(
|
||||
appMetadataKey
|
||||
) as AppMetadataEntity;
|
||||
if (CacheHelpers.isAppMetadataEntity(appMetadataKey, appMetadata)) {
|
||||
return appMetadata;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* set appMetadata entity to the platform cache
|
||||
* @param appMetadata - cache value to be set of type AppMetadataEntity
|
||||
*/
|
||||
setAppMetadata(appMetadata: AppMetadataEntity): void {
|
||||
const appMetadataKey = CacheHelpers.generateAppMetadataKey(appMetadata);
|
||||
this.setItem(appMetadataKey, appMetadata);
|
||||
}
|
||||
|
||||
/**
|
||||
* fetch server telemetry entity from the platform cache
|
||||
* @param serverTelemetrykey - lookup key to fetch cache type ServerTelemetryEntity
|
||||
*/
|
||||
getServerTelemetry(
|
||||
serverTelemetrykey: string
|
||||
): ServerTelemetryEntity | null {
|
||||
const serverTelemetryEntity: ServerTelemetryEntity = this.getItem(
|
||||
serverTelemetrykey
|
||||
) as ServerTelemetryEntity;
|
||||
if (
|
||||
serverTelemetryEntity &&
|
||||
CacheHelpers.isServerTelemetryEntity(
|
||||
serverTelemetrykey,
|
||||
serverTelemetryEntity
|
||||
)
|
||||
) {
|
||||
return serverTelemetryEntity;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* set server telemetry entity to the platform cache
|
||||
* @param serverTelemetryKey - lookup key to fetch cache type ServerTelemetryEntity
|
||||
* @param serverTelemetry - cache value to be set of type ServerTelemetryEntity
|
||||
*/
|
||||
setServerTelemetry(
|
||||
serverTelemetryKey: string,
|
||||
serverTelemetry: ServerTelemetryEntity
|
||||
): void {
|
||||
this.setItem(serverTelemetryKey, serverTelemetry);
|
||||
}
|
||||
|
||||
/**
|
||||
* fetch authority metadata entity from the platform cache
|
||||
* @param key - lookup key to fetch cache type AuthorityMetadataEntity
|
||||
*/
|
||||
getAuthorityMetadata(key: string): AuthorityMetadataEntity | null {
|
||||
const authorityMetadataEntity: AuthorityMetadataEntity = this.getItem(
|
||||
key
|
||||
) as AuthorityMetadataEntity;
|
||||
if (
|
||||
authorityMetadataEntity &&
|
||||
CacheHelpers.isAuthorityMetadataEntity(key, authorityMetadataEntity)
|
||||
) {
|
||||
return authorityMetadataEntity;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all authority metadata keys
|
||||
*/
|
||||
getAuthorityMetadataKeys(): Array<string> {
|
||||
return this.getKeys().filter((key) => {
|
||||
return this.isAuthorityMetadata(key);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* set authority metadata entity to the platform cache
|
||||
* @param key - lookup key to fetch cache type AuthorityMetadataEntity
|
||||
* @param metadata - cache value to be set of type AuthorityMetadataEntity
|
||||
*/
|
||||
setAuthorityMetadata(key: string, metadata: AuthorityMetadataEntity): void {
|
||||
this.setItem(key, metadata);
|
||||
}
|
||||
|
||||
/**
|
||||
* fetch throttling entity from the platform cache
|
||||
* @param throttlingCacheKey - lookup key to fetch cache type ThrottlingEntity
|
||||
*/
|
||||
getThrottlingCache(throttlingCacheKey: string): ThrottlingEntity | null {
|
||||
const throttlingCache: ThrottlingEntity = this.getItem(
|
||||
throttlingCacheKey
|
||||
) as ThrottlingEntity;
|
||||
if (
|
||||
throttlingCache &&
|
||||
CacheHelpers.isThrottlingEntity(throttlingCacheKey, throttlingCache)
|
||||
) {
|
||||
return throttlingCache;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* set throttling entity to the platform cache
|
||||
* @param throttlingCacheKey - lookup key to fetch cache type ThrottlingEntity
|
||||
* @param throttlingCache - cache value to be set of type ThrottlingEntity
|
||||
*/
|
||||
setThrottlingCache(
|
||||
throttlingCacheKey: string,
|
||||
throttlingCache: ThrottlingEntity
|
||||
): void {
|
||||
this.setItem(throttlingCacheKey, throttlingCache);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the cache item from memory with the given key.
|
||||
* @param key - lookup key to remove a cache entity
|
||||
* @param inMemory - key value map of the cache
|
||||
*/
|
||||
removeItem(key: string): boolean {
|
||||
this.logger.tracePii(`Item key: ${key}`, "");
|
||||
|
||||
// read inMemoryCache
|
||||
let result: boolean = false;
|
||||
const cache = this.getCache();
|
||||
|
||||
if (!!cache[key]) {
|
||||
delete cache[key];
|
||||
result = true;
|
||||
}
|
||||
|
||||
// write to the cache after removal
|
||||
if (result) {
|
||||
this.setCache(cache);
|
||||
this.emitChange();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove account entity from the platform cache if it's outdated
|
||||
* @param accountKey - lookup key to fetch cache type AccountEntity
|
||||
*/
|
||||
removeOutdatedAccount(accountKey: string): void {
|
||||
this.removeItem(accountKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether key is in cache.
|
||||
* @param key - look up key for a cache entity
|
||||
*/
|
||||
containsKey(key: string): boolean {
|
||||
return this.getKeys().includes(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all keys in window.
|
||||
*/
|
||||
getKeys(): string[] {
|
||||
this.logger.trace("Retrieving all cache keys", "");
|
||||
|
||||
// read cache
|
||||
const cache = this.getCache();
|
||||
return [...Object.keys(cache)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all cache entries created by MSAL except authority metadata..
|
||||
*/
|
||||
clear(): void {
|
||||
this.logger.trace("Clearing cache entries created by MSAL", "");
|
||||
|
||||
// read inMemoryCache
|
||||
const cacheKeys = this.getKeys();
|
||||
|
||||
// delete each element
|
||||
cacheKeys.forEach((key) => {
|
||||
if (this.isAuthorityMetadata(key)) {
|
||||
return;
|
||||
}
|
||||
this.removeItem(key);
|
||||
});
|
||||
this.emitChange();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize in memory cache from an exisiting cache vault
|
||||
* @param cache - blob formatted cache (JSON)
|
||||
*/
|
||||
static generateInMemoryCache(cache: string): InMemoryCache {
|
||||
return Deserializer.deserializeAllCache(
|
||||
Deserializer.deserializeJSONBlob(cache)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* retrieves the final JSON
|
||||
* @param inMemoryCache - itemised cache read from the JSON
|
||||
*/
|
||||
static generateJsonCache(inMemoryCache: InMemoryCache): JsonCache {
|
||||
return Serializer.serializeAllCache(inMemoryCache);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a credential's cache key if the current cache key is outdated
|
||||
*/
|
||||
updateCredentialCacheKey(
|
||||
currentCacheKey: string,
|
||||
credential: ValidCredentialType
|
||||
): string {
|
||||
const updatedCacheKey = this.generateCredentialKey(credential);
|
||||
|
||||
if (currentCacheKey !== updatedCacheKey) {
|
||||
const cacheItem = this.getItem(currentCacheKey);
|
||||
if (cacheItem) {
|
||||
this.removeItem(currentCacheKey);
|
||||
this.setItem(updatedCacheKey, cacheItem);
|
||||
this.logger.verbose(
|
||||
`Updated an outdated ${credential.credentialType} cache key`,
|
||||
""
|
||||
);
|
||||
return updatedCacheKey;
|
||||
} else {
|
||||
this.logger.error(
|
||||
`Attempted to update an outdated ${credential.credentialType} cache key but no item matching the outdated key was found in storage`,
|
||||
""
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return currentCacheKey;
|
||||
}
|
||||
}
|
||||
398
backend/node_modules/@azure/msal-node/src/cache/TokenCache.ts
generated
vendored
Normal file
398
backend/node_modules/@azure/msal-node/src/cache/TokenCache.ts
generated
vendored
Normal file
@ -0,0 +1,398 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import { NodeStorage } from "./NodeStorage.js";
|
||||
import {
|
||||
AccountInfo,
|
||||
Logger,
|
||||
ISerializableTokenCache,
|
||||
ICachePlugin,
|
||||
TokenCacheContext,
|
||||
} from "@azure/msal-common/node";
|
||||
import {
|
||||
InMemoryCache,
|
||||
JsonCache,
|
||||
SerializedAccountEntity,
|
||||
SerializedAccessTokenEntity,
|
||||
SerializedRefreshTokenEntity,
|
||||
SerializedIdTokenEntity,
|
||||
SerializedAppMetadataEntity,
|
||||
CacheKVStore,
|
||||
} from "./serializer/SerializerTypes.js";
|
||||
import { Deserializer } from "./serializer/Deserializer.js";
|
||||
import { Serializer } from "./serializer/Serializer.js";
|
||||
import { ITokenCache } from "./ITokenCache.js";
|
||||
import { GuidGenerator } from "../crypto/GuidGenerator.js";
|
||||
import { CryptoProvider } from "../crypto/CryptoProvider.js";
|
||||
|
||||
const defaultSerializedCache: JsonCache = {
|
||||
Account: {},
|
||||
IdToken: {},
|
||||
AccessToken: {},
|
||||
RefreshToken: {},
|
||||
AppMetadata: {},
|
||||
};
|
||||
|
||||
/**
|
||||
* In-memory token cache manager
|
||||
* @public
|
||||
*/
|
||||
export class TokenCache implements ISerializableTokenCache, ITokenCache {
|
||||
private storage: NodeStorage;
|
||||
private cacheHasChanged: boolean;
|
||||
private cacheSnapshot: string;
|
||||
public readonly persistence: ICachePlugin;
|
||||
private logger: Logger;
|
||||
|
||||
constructor(
|
||||
storage: NodeStorage,
|
||||
logger: Logger,
|
||||
cachePlugin?: ICachePlugin
|
||||
) {
|
||||
this.cacheHasChanged = false;
|
||||
this.storage = storage;
|
||||
this.storage.registerChangeEmitter(this.handleChangeEvent.bind(this));
|
||||
if (cachePlugin) {
|
||||
this.persistence = cachePlugin;
|
||||
}
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set to true if cache state has changed since last time serialize or writeToPersistence was called
|
||||
*/
|
||||
hasChanged(): boolean {
|
||||
return this.cacheHasChanged;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes in memory cache to JSON
|
||||
*/
|
||||
serialize(): string {
|
||||
this.logger.trace("Serializing in-memory cache", "");
|
||||
let finalState = Serializer.serializeAllCache(
|
||||
this.storage.getInMemoryCache() as InMemoryCache
|
||||
);
|
||||
|
||||
// if cacheSnapshot not null or empty, merge
|
||||
if (this.cacheSnapshot) {
|
||||
this.logger.trace("Reading cache snapshot from disk", "");
|
||||
finalState = this.mergeState(
|
||||
JSON.parse(this.cacheSnapshot),
|
||||
finalState
|
||||
);
|
||||
} else {
|
||||
this.logger.trace("No cache snapshot to merge", "");
|
||||
}
|
||||
this.cacheHasChanged = false;
|
||||
|
||||
return JSON.stringify(finalState);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes JSON to in-memory cache. JSON should be in MSAL cache schema format
|
||||
* @param cache - blob formatted cache
|
||||
*/
|
||||
deserialize(cache: string): void {
|
||||
this.logger.trace("Deserializing JSON to in-memory cache", "");
|
||||
this.cacheSnapshot = cache;
|
||||
|
||||
if (this.cacheSnapshot) {
|
||||
this.logger.trace("Reading cache snapshot from disk", "");
|
||||
const deserializedCache = Deserializer.deserializeAllCache(
|
||||
this.overlayDefaults(JSON.parse(this.cacheSnapshot))
|
||||
);
|
||||
this.storage.setInMemoryCache(deserializedCache);
|
||||
} else {
|
||||
this.logger.trace("No cache snapshot to deserialize", "");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the cache key-value map
|
||||
*/
|
||||
getKVStore(): CacheKVStore {
|
||||
return this.storage.getCache();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets cache snapshot in CacheKVStore format
|
||||
*/
|
||||
getCacheSnapshot(): CacheKVStore {
|
||||
const deserializedPersistentStorage = NodeStorage.generateInMemoryCache(
|
||||
this.cacheSnapshot
|
||||
);
|
||||
return this.storage.inMemoryCacheToCache(deserializedPersistentStorage);
|
||||
}
|
||||
|
||||
/**
|
||||
* API that retrieves all accounts currently in cache to the user
|
||||
*/
|
||||
async getAllAccounts(
|
||||
correlationId: string = new CryptoProvider().createNewGuid()
|
||||
): Promise<AccountInfo[]> {
|
||||
this.logger.trace("getAllAccounts called", correlationId);
|
||||
let cacheContext;
|
||||
try {
|
||||
if (this.persistence) {
|
||||
cacheContext = new TokenCacheContext(this, false);
|
||||
await this.persistence.beforeCacheAccess(cacheContext);
|
||||
}
|
||||
return this.storage.getAllAccounts({}, correlationId);
|
||||
} finally {
|
||||
if (this.persistence && cacheContext) {
|
||||
await this.persistence.afterCacheAccess(cacheContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the signed in account matching homeAccountId.
|
||||
* (the account object is created at the time of successful login)
|
||||
* or null when no matching account is found
|
||||
* @param homeAccountId - unique identifier for an account (uid.utid)
|
||||
*/
|
||||
async getAccountByHomeId(
|
||||
homeAccountId: string
|
||||
): Promise<AccountInfo | null> {
|
||||
const allAccounts = await this.getAllAccounts();
|
||||
if (homeAccountId && allAccounts && allAccounts.length) {
|
||||
return (
|
||||
allAccounts.filter(
|
||||
(accountObj) => accountObj.homeAccountId === homeAccountId
|
||||
)[0] || null
|
||||
);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the signed in account matching localAccountId.
|
||||
* (the account object is created at the time of successful login)
|
||||
* or null when no matching account is found
|
||||
* @param localAccountId - unique identifier of an account (sub/obj when homeAccountId cannot be populated)
|
||||
*/
|
||||
async getAccountByLocalId(
|
||||
localAccountId: string
|
||||
): Promise<AccountInfo | null> {
|
||||
const allAccounts = await this.getAllAccounts();
|
||||
if (localAccountId && allAccounts && allAccounts.length) {
|
||||
return (
|
||||
allAccounts.filter(
|
||||
(accountObj) => accountObj.localAccountId === localAccountId
|
||||
)[0] || null
|
||||
);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* API to remove a specific account and the relevant data from cache
|
||||
* @param account - AccountInfo passed by the user
|
||||
*/
|
||||
async removeAccount(
|
||||
account: AccountInfo,
|
||||
correlationId?: string
|
||||
): Promise<void> {
|
||||
this.logger.trace("removeAccount called", correlationId || "");
|
||||
let cacheContext;
|
||||
try {
|
||||
if (this.persistence) {
|
||||
cacheContext = new TokenCacheContext(this, true);
|
||||
await this.persistence.beforeCacheAccess(cacheContext);
|
||||
}
|
||||
this.storage.removeAccount(
|
||||
account,
|
||||
correlationId || new GuidGenerator().generateGuid()
|
||||
);
|
||||
} finally {
|
||||
if (this.persistence && cacheContext) {
|
||||
await this.persistence.afterCacheAccess(cacheContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrites in-memory cache with persistent cache
|
||||
*/
|
||||
async overwriteCache(): Promise<void> {
|
||||
if (!this.persistence) {
|
||||
this.logger.info(
|
||||
"No persistence layer specified, cache cannot be overwritten",
|
||||
""
|
||||
);
|
||||
return;
|
||||
}
|
||||
this.logger.info(
|
||||
"Overwriting in-memory cache with persistent cache",
|
||||
""
|
||||
);
|
||||
this.storage.clear();
|
||||
const cacheContext = new TokenCacheContext(this, false);
|
||||
await this.persistence.beforeCacheAccess(cacheContext);
|
||||
const cacheSnapshot = this.getCacheSnapshot();
|
||||
this.storage.setCache(cacheSnapshot);
|
||||
await this.persistence.afterCacheAccess(cacheContext);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the cache has changed state.
|
||||
*/
|
||||
private handleChangeEvent() {
|
||||
this.cacheHasChanged = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge in memory cache with the cache snapshot.
|
||||
* @param oldState - cache before changes
|
||||
* @param currentState - current cache state in the library
|
||||
*/
|
||||
private mergeState(
|
||||
oldState: JsonCache,
|
||||
currentState: JsonCache
|
||||
): JsonCache {
|
||||
this.logger.trace("Merging in-memory cache with cache snapshot", "");
|
||||
const stateAfterRemoval = this.mergeRemovals(oldState, currentState);
|
||||
return this.mergeUpdates(stateAfterRemoval, currentState);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deep update of oldState based on newState values
|
||||
* @param oldState - cache before changes
|
||||
* @param newState - updated cache
|
||||
*/
|
||||
private mergeUpdates(oldState: object, newState: object): JsonCache {
|
||||
Object.keys(newState).forEach((newKey: string) => {
|
||||
const newValue = newState[newKey];
|
||||
|
||||
// if oldState does not contain value but newValue does, add it
|
||||
if (!oldState.hasOwnProperty(newKey)) {
|
||||
if (newValue !== null) {
|
||||
oldState[newKey] = newValue;
|
||||
}
|
||||
} else {
|
||||
// both oldState and newState contain the key, do deep update
|
||||
const newValueNotNull = newValue !== null;
|
||||
const newValueIsObject = typeof newValue === "object";
|
||||
const newValueIsNotArray = !Array.isArray(newValue);
|
||||
const oldStateNotUndefinedOrNull =
|
||||
typeof oldState[newKey] !== "undefined" &&
|
||||
oldState[newKey] !== null;
|
||||
|
||||
if (
|
||||
newValueNotNull &&
|
||||
newValueIsObject &&
|
||||
newValueIsNotArray &&
|
||||
oldStateNotUndefinedOrNull
|
||||
) {
|
||||
this.mergeUpdates(oldState[newKey], newValue);
|
||||
} else {
|
||||
oldState[newKey] = newValue;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return oldState as JsonCache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes entities in oldState that the were removed from newState. If there are any unknown values in root of
|
||||
* oldState that are not recognized, they are left untouched.
|
||||
* @param oldState - cache before changes
|
||||
* @param newState - updated cache
|
||||
*/
|
||||
private mergeRemovals(oldState: JsonCache, newState: JsonCache): JsonCache {
|
||||
this.logger.trace("Remove updated entries in cache", "");
|
||||
const accounts = oldState.Account
|
||||
? this.mergeRemovalsDict<SerializedAccountEntity>(
|
||||
oldState.Account,
|
||||
newState.Account
|
||||
)
|
||||
: oldState.Account;
|
||||
const accessTokens = oldState.AccessToken
|
||||
? this.mergeRemovalsDict<SerializedAccessTokenEntity>(
|
||||
oldState.AccessToken,
|
||||
newState.AccessToken
|
||||
)
|
||||
: oldState.AccessToken;
|
||||
const refreshTokens = oldState.RefreshToken
|
||||
? this.mergeRemovalsDict<SerializedRefreshTokenEntity>(
|
||||
oldState.RefreshToken,
|
||||
newState.RefreshToken
|
||||
)
|
||||
: oldState.RefreshToken;
|
||||
const idTokens = oldState.IdToken
|
||||
? this.mergeRemovalsDict<SerializedIdTokenEntity>(
|
||||
oldState.IdToken,
|
||||
newState.IdToken
|
||||
)
|
||||
: oldState.IdToken;
|
||||
const appMetadata = oldState.AppMetadata
|
||||
? this.mergeRemovalsDict<SerializedAppMetadataEntity>(
|
||||
oldState.AppMetadata,
|
||||
newState.AppMetadata
|
||||
)
|
||||
: oldState.AppMetadata;
|
||||
|
||||
return {
|
||||
...oldState,
|
||||
Account: accounts,
|
||||
AccessToken: accessTokens,
|
||||
RefreshToken: refreshTokens,
|
||||
IdToken: idTokens,
|
||||
AppMetadata: appMetadata,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to merge new cache with the old one
|
||||
* @param oldState - cache before changes
|
||||
* @param newState - updated cache
|
||||
*/
|
||||
private mergeRemovalsDict<T>(
|
||||
oldState: Record<string, T>,
|
||||
newState?: Record<string, T>
|
||||
): Record<string, T> {
|
||||
const finalState = { ...oldState };
|
||||
Object.keys(oldState).forEach((oldKey) => {
|
||||
if (!newState || !newState.hasOwnProperty(oldKey)) {
|
||||
delete finalState[oldKey];
|
||||
}
|
||||
});
|
||||
return finalState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to overlay as a part of cache merge
|
||||
* @param passedInCache - cache read from the blob
|
||||
*/
|
||||
private overlayDefaults(passedInCache: JsonCache): JsonCache {
|
||||
this.logger.trace("Overlaying input cache with the default cache", "");
|
||||
return {
|
||||
Account: {
|
||||
...defaultSerializedCache.Account,
|
||||
...passedInCache.Account,
|
||||
},
|
||||
IdToken: {
|
||||
...defaultSerializedCache.IdToken,
|
||||
...passedInCache.IdToken,
|
||||
},
|
||||
AccessToken: {
|
||||
...defaultSerializedCache.AccessToken,
|
||||
...passedInCache.AccessToken,
|
||||
},
|
||||
RefreshToken: {
|
||||
...defaultSerializedCache.RefreshToken,
|
||||
...passedInCache.RefreshToken,
|
||||
},
|
||||
AppMetadata: {
|
||||
...defaultSerializedCache.AppMetadata,
|
||||
...passedInCache.AppMetadata,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
72
backend/node_modules/@azure/msal-node/src/cache/distributed/DistributedCachePlugin.ts
generated
vendored
Normal file
72
backend/node_modules/@azure/msal-node/src/cache/distributed/DistributedCachePlugin.ts
generated
vendored
Normal file
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import {
|
||||
AccountEntity,
|
||||
ICachePlugin,
|
||||
AccountEntityUtils,
|
||||
TokenCacheContext,
|
||||
} from "@azure/msal-common/node";
|
||||
import { TokenCache } from "../TokenCache.js";
|
||||
import { IPartitionManager } from "./IPartitionManager.js";
|
||||
import { ICacheClient } from "./ICacheClient.js";
|
||||
|
||||
/**
|
||||
* Cache plugin that serializes data to the cache and deserializes data from the cache
|
||||
* @public
|
||||
*/
|
||||
export class DistributedCachePlugin implements ICachePlugin {
|
||||
private client: ICacheClient;
|
||||
private partitionManager: IPartitionManager;
|
||||
|
||||
constructor(client: ICacheClient, partitionManager: IPartitionManager) {
|
||||
this.client = client;
|
||||
this.partitionManager = partitionManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the cache before accessing it
|
||||
* @param cacheContext - TokenCacheContext
|
||||
*/
|
||||
public async beforeCacheAccess(
|
||||
cacheContext: TokenCacheContext
|
||||
): Promise<void> {
|
||||
const partitionKey = await this.partitionManager.getKey();
|
||||
const cacheData = await this.client.get(partitionKey);
|
||||
cacheContext.tokenCache.deserialize(cacheData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes the cache after accessing it
|
||||
* @param cacheContext - TokenCacheContext
|
||||
*/
|
||||
public async afterCacheAccess(
|
||||
cacheContext: TokenCacheContext
|
||||
): Promise<void> {
|
||||
if (cacheContext.cacheHasChanged) {
|
||||
const kvStore = (
|
||||
cacheContext.tokenCache as TokenCache
|
||||
).getKVStore();
|
||||
const accountEntities = Object.values(kvStore).filter((value) =>
|
||||
AccountEntityUtils.isAccountEntity(value as object)
|
||||
);
|
||||
|
||||
let partitionKey: string;
|
||||
if (accountEntities.length > 0) {
|
||||
const accountEntity = accountEntities[0] as AccountEntity;
|
||||
partitionKey = await this.partitionManager.extractKey(
|
||||
accountEntity
|
||||
);
|
||||
} else {
|
||||
partitionKey = await this.partitionManager.getKey();
|
||||
}
|
||||
|
||||
await this.client.set(
|
||||
partitionKey,
|
||||
cacheContext.tokenCache.serialize()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
27
backend/node_modules/@azure/msal-node/src/cache/distributed/ICacheClient.ts
generated
vendored
Normal file
27
backend/node_modules/@azure/msal-node/src/cache/distributed/ICacheClient.ts
generated
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Interface for the cache that defines a getter and setter
|
||||
* @public
|
||||
*/
|
||||
export interface ICacheClient {
|
||||
/**
|
||||
* Retrieve the value from the cache
|
||||
*
|
||||
* @param key - key of item in the cache
|
||||
* @returns Promise<string>
|
||||
*/
|
||||
get(key: string): Promise<string>;
|
||||
|
||||
/**
|
||||
* Save the required value using the provided key to cache
|
||||
*
|
||||
* @param key - key of item in the cache
|
||||
* @param value - value of item to be saved in the cache
|
||||
* @returns Promise<string>
|
||||
*/
|
||||
set(key: string, value: string): Promise<string>;
|
||||
}
|
||||
39
backend/node_modules/@azure/msal-node/src/cache/distributed/IPartitionManager.ts
generated
vendored
Normal file
39
backend/node_modules/@azure/msal-node/src/cache/distributed/IPartitionManager.ts
generated
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import { AccountEntity } from "@azure/msal-common/node";
|
||||
|
||||
/**
|
||||
* Interface that defines getter methods to get keys used to identity data in the cache
|
||||
* @public
|
||||
*/
|
||||
export interface IPartitionManager {
|
||||
/**
|
||||
* This function should return the correct key from which to read
|
||||
* the specific user's information from cache.
|
||||
*
|
||||
* Example: Your application may be partitioning the user's cache
|
||||
* information for each user using the homeAccountId and thus
|
||||
* this function would return the homeAccountId for
|
||||
* the user in question
|
||||
*
|
||||
* @returns Promise<string>
|
||||
*/
|
||||
getKey(): Promise<string>;
|
||||
|
||||
/**
|
||||
* This function should return the correct key being used to save each
|
||||
* user's cache information to cache - given an AccountEntity
|
||||
*
|
||||
* Example: Your application may be partitioning the user's cache
|
||||
* information for each user using the homeAccountId thus
|
||||
* this function would return the homeAccountId from
|
||||
* the provided AccountEntity
|
||||
*
|
||||
* @param accountEntity - AccountEntity
|
||||
* @returns Promise<string>
|
||||
*/
|
||||
extractKey(accountEntity: AccountEntity): Promise<string>;
|
||||
}
|
||||
221
backend/node_modules/@azure/msal-node/src/cache/serializer/Deserializer.ts
generated
vendored
Normal file
221
backend/node_modules/@azure/msal-node/src/cache/serializer/Deserializer.ts
generated
vendored
Normal file
@ -0,0 +1,221 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import {
|
||||
AccountCache,
|
||||
IdTokenCache,
|
||||
AccessTokenCache,
|
||||
RefreshTokenCache,
|
||||
AppMetadataCache,
|
||||
AccountEntity,
|
||||
IdTokenEntity,
|
||||
AccessTokenEntity,
|
||||
RefreshTokenEntity,
|
||||
CacheManager,
|
||||
Constants,
|
||||
} from "@azure/msal-common/node";
|
||||
import {
|
||||
JsonCache,
|
||||
InMemoryCache,
|
||||
SerializedAccountEntity,
|
||||
SerializedIdTokenEntity,
|
||||
SerializedAccessTokenEntity,
|
||||
SerializedRefreshTokenEntity,
|
||||
SerializedAppMetadataEntity,
|
||||
} from "./SerializerTypes.js";
|
||||
|
||||
/**
|
||||
* This class deserializes cache entities read from the file into in-memory object types defined internally
|
||||
* @internal
|
||||
*/
|
||||
export class Deserializer {
|
||||
/**
|
||||
* Parse the JSON blob in memory and deserialize the content
|
||||
* @param cachedJson - JSON blob cache
|
||||
*/
|
||||
static deserializeJSONBlob(jsonFile: string): JsonCache {
|
||||
const deserializedCache = !jsonFile ? {} : JSON.parse(jsonFile);
|
||||
return deserializedCache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes accounts to AccountEntity objects
|
||||
* @param accounts - accounts of type SerializedAccountEntity
|
||||
*/
|
||||
static deserializeAccounts(
|
||||
accounts: Record<string, SerializedAccountEntity>
|
||||
): AccountCache {
|
||||
const accountObjects: AccountCache = {};
|
||||
if (accounts) {
|
||||
Object.keys(accounts).map(function (key) {
|
||||
const serializedAcc = accounts[key];
|
||||
const mappedAcc = {
|
||||
homeAccountId: serializedAcc.home_account_id,
|
||||
environment: serializedAcc.environment,
|
||||
realm: serializedAcc.realm,
|
||||
localAccountId: serializedAcc.local_account_id,
|
||||
username: serializedAcc.username,
|
||||
authorityType: serializedAcc.authority_type,
|
||||
name: serializedAcc.name,
|
||||
clientInfo: serializedAcc.client_info,
|
||||
lastModificationTime: serializedAcc.last_modification_time,
|
||||
lastModificationApp: serializedAcc.last_modification_app,
|
||||
tenantProfiles: serializedAcc.tenantProfiles?.map(
|
||||
(serializedTenantProfile) => {
|
||||
return JSON.parse(serializedTenantProfile);
|
||||
}
|
||||
),
|
||||
lastUpdatedAt: Date.now().toString(),
|
||||
};
|
||||
const account: AccountEntity = {} as AccountEntity;
|
||||
CacheManager.toObject(account, mappedAcc);
|
||||
accountObjects[key] = account;
|
||||
});
|
||||
}
|
||||
|
||||
return accountObjects;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes id tokens to IdTokenEntity objects
|
||||
* @param idTokens - credentials of type SerializedIdTokenEntity
|
||||
*/
|
||||
static deserializeIdTokens(
|
||||
idTokens: Record<string, SerializedIdTokenEntity>
|
||||
): IdTokenCache {
|
||||
const idObjects: IdTokenCache = {};
|
||||
if (idTokens) {
|
||||
Object.keys(idTokens).map(function (key) {
|
||||
const serializedIdT = idTokens[key];
|
||||
const idToken: IdTokenEntity = {
|
||||
homeAccountId: serializedIdT.home_account_id,
|
||||
environment: serializedIdT.environment,
|
||||
credentialType:
|
||||
serializedIdT.credential_type as Constants.CredentialType,
|
||||
clientId: serializedIdT.client_id,
|
||||
secret: serializedIdT.secret,
|
||||
realm: serializedIdT.realm,
|
||||
lastUpdatedAt: Date.now().toString(),
|
||||
};
|
||||
idObjects[key] = idToken;
|
||||
});
|
||||
}
|
||||
return idObjects;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes access tokens to AccessTokenEntity objects
|
||||
* @param accessTokens - access tokens of type SerializedAccessTokenEntity
|
||||
*/
|
||||
static deserializeAccessTokens(
|
||||
accessTokens: Record<string, SerializedAccessTokenEntity>
|
||||
): AccessTokenCache {
|
||||
const atObjects: AccessTokenCache = {};
|
||||
if (accessTokens) {
|
||||
Object.keys(accessTokens).map(function (key) {
|
||||
const serializedAT = accessTokens[key];
|
||||
const accessToken: AccessTokenEntity = {
|
||||
homeAccountId: serializedAT.home_account_id,
|
||||
environment: serializedAT.environment,
|
||||
credentialType:
|
||||
serializedAT.credential_type as Constants.CredentialType,
|
||||
clientId: serializedAT.client_id,
|
||||
secret: serializedAT.secret,
|
||||
realm: serializedAT.realm,
|
||||
target: serializedAT.target,
|
||||
cachedAt: serializedAT.cached_at,
|
||||
expiresOn: serializedAT.expires_on,
|
||||
extendedExpiresOn: serializedAT.extended_expires_on,
|
||||
refreshOn: serializedAT.refresh_on,
|
||||
keyId: serializedAT.key_id,
|
||||
tokenType:
|
||||
serializedAT.token_type as Constants.AuthenticationScheme,
|
||||
userAssertionHash: serializedAT.userAssertionHash,
|
||||
resource: serializedAT.resource,
|
||||
lastUpdatedAt: Date.now().toString(),
|
||||
};
|
||||
atObjects[key] = accessToken;
|
||||
});
|
||||
}
|
||||
|
||||
return atObjects;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes refresh tokens to RefreshTokenEntity objects
|
||||
* @param refreshTokens - refresh tokens of type SerializedRefreshTokenEntity
|
||||
*/
|
||||
static deserializeRefreshTokens(
|
||||
refreshTokens: Record<string, SerializedRefreshTokenEntity>
|
||||
): RefreshTokenCache {
|
||||
const rtObjects: RefreshTokenCache = {};
|
||||
if (refreshTokens) {
|
||||
Object.keys(refreshTokens).map(function (key) {
|
||||
const serializedRT = refreshTokens[key];
|
||||
const refreshToken: RefreshTokenEntity = {
|
||||
homeAccountId: serializedRT.home_account_id,
|
||||
environment: serializedRT.environment,
|
||||
credentialType:
|
||||
serializedRT.credential_type as Constants.CredentialType,
|
||||
clientId: serializedRT.client_id,
|
||||
secret: serializedRT.secret,
|
||||
familyId: serializedRT.family_id,
|
||||
target: serializedRT.target,
|
||||
realm: serializedRT.realm,
|
||||
lastUpdatedAt: Date.now().toString(),
|
||||
};
|
||||
rtObjects[key] = refreshToken;
|
||||
});
|
||||
}
|
||||
|
||||
return rtObjects;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes appMetadata to AppMetaData objects
|
||||
* @param appMetadata - app metadata of type SerializedAppMetadataEntity
|
||||
*/
|
||||
static deserializeAppMetadata(
|
||||
appMetadata: Record<string, SerializedAppMetadataEntity>
|
||||
): AppMetadataCache {
|
||||
const appMetadataObjects: AppMetadataCache = {};
|
||||
if (appMetadata) {
|
||||
Object.keys(appMetadata).map(function (key) {
|
||||
const serializedAmdt = appMetadata[key];
|
||||
appMetadataObjects[key] = {
|
||||
clientId: serializedAmdt.client_id,
|
||||
environment: serializedAmdt.environment,
|
||||
familyId: serializedAmdt.family_id,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
return appMetadataObjects;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialize an inMemory Cache
|
||||
* @param jsonCache - JSON blob cache
|
||||
*/
|
||||
static deserializeAllCache(jsonCache: JsonCache): InMemoryCache {
|
||||
return {
|
||||
accounts: jsonCache.Account
|
||||
? this.deserializeAccounts(jsonCache.Account)
|
||||
: {},
|
||||
idTokens: jsonCache.IdToken
|
||||
? this.deserializeIdTokens(jsonCache.IdToken)
|
||||
: {},
|
||||
accessTokens: jsonCache.AccessToken
|
||||
? this.deserializeAccessTokens(jsonCache.AccessToken)
|
||||
: {},
|
||||
refreshTokens: jsonCache.RefreshToken
|
||||
? this.deserializeRefreshTokens(jsonCache.RefreshToken)
|
||||
: {},
|
||||
appMetadata: jsonCache.AppMetadata
|
||||
? this.deserializeAppMetadata(jsonCache.AppMetadata)
|
||||
: {},
|
||||
};
|
||||
}
|
||||
}
|
||||
181
backend/node_modules/@azure/msal-node/src/cache/serializer/Serializer.ts
generated
vendored
Normal file
181
backend/node_modules/@azure/msal-node/src/cache/serializer/Serializer.ts
generated
vendored
Normal file
@ -0,0 +1,181 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import {
|
||||
AccountCache,
|
||||
IdTokenCache,
|
||||
AccessTokenCache,
|
||||
RefreshTokenCache,
|
||||
AppMetadataCache,
|
||||
} from "@azure/msal-common/node";
|
||||
import {
|
||||
InMemoryCache,
|
||||
JsonCache,
|
||||
SerializedAccountEntity,
|
||||
SerializedIdTokenEntity,
|
||||
SerializedAccessTokenEntity,
|
||||
SerializedRefreshTokenEntity,
|
||||
SerializedAppMetadataEntity,
|
||||
} from "./SerializerTypes.js";
|
||||
|
||||
/**
|
||||
* This class serializes cache entities to be saved into in-memory object types defined internally
|
||||
* @internal
|
||||
*/
|
||||
export class Serializer {
|
||||
/**
|
||||
* serialize the JSON blob
|
||||
* @param data - JSON blob cache
|
||||
*/
|
||||
static serializeJSONBlob(data: JsonCache): string {
|
||||
return JSON.stringify(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize Accounts
|
||||
* @param accCache - cache of accounts
|
||||
*/
|
||||
static serializeAccounts(
|
||||
accCache: AccountCache
|
||||
): Record<string, SerializedAccountEntity> {
|
||||
const accounts: Record<string, SerializedAccountEntity> = {};
|
||||
Object.keys(accCache).map(function (key) {
|
||||
const accountEntity = accCache[key];
|
||||
accounts[key] = {
|
||||
home_account_id: accountEntity.homeAccountId,
|
||||
environment: accountEntity.environment,
|
||||
realm: accountEntity.realm,
|
||||
local_account_id: accountEntity.localAccountId,
|
||||
username: accountEntity.username,
|
||||
authority_type: accountEntity.authorityType,
|
||||
name: accountEntity.name,
|
||||
client_info: accountEntity.clientInfo,
|
||||
last_modification_time: accountEntity.lastModificationTime,
|
||||
last_modification_app: accountEntity.lastModificationApp,
|
||||
tenantProfiles: accountEntity.tenantProfiles?.map(
|
||||
(tenantProfile) => {
|
||||
return JSON.stringify(tenantProfile);
|
||||
}
|
||||
),
|
||||
};
|
||||
});
|
||||
|
||||
return accounts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize IdTokens
|
||||
* @param idTCache - cache of ID tokens
|
||||
*/
|
||||
static serializeIdTokens(
|
||||
idTCache: IdTokenCache
|
||||
): Record<string, SerializedIdTokenEntity> {
|
||||
const idTokens: Record<string, SerializedIdTokenEntity> = {};
|
||||
Object.keys(idTCache).map(function (key) {
|
||||
const idTEntity = idTCache[key];
|
||||
idTokens[key] = {
|
||||
home_account_id: idTEntity.homeAccountId,
|
||||
environment: idTEntity.environment,
|
||||
credential_type: idTEntity.credentialType,
|
||||
client_id: idTEntity.clientId,
|
||||
secret: idTEntity.secret,
|
||||
realm: idTEntity.realm,
|
||||
};
|
||||
});
|
||||
|
||||
return idTokens;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes AccessTokens
|
||||
* @param atCache - cache of access tokens
|
||||
*/
|
||||
static serializeAccessTokens(
|
||||
atCache: AccessTokenCache
|
||||
): Record<string, SerializedAccessTokenEntity> {
|
||||
const accessTokens: Record<string, SerializedAccessTokenEntity> = {};
|
||||
Object.keys(atCache).map(function (key) {
|
||||
const atEntity = atCache[key];
|
||||
accessTokens[key] = {
|
||||
home_account_id: atEntity.homeAccountId,
|
||||
environment: atEntity.environment,
|
||||
credential_type: atEntity.credentialType,
|
||||
client_id: atEntity.clientId,
|
||||
secret: atEntity.secret,
|
||||
realm: atEntity.realm,
|
||||
target: atEntity.target,
|
||||
cached_at: atEntity.cachedAt,
|
||||
expires_on: atEntity.expiresOn,
|
||||
extended_expires_on: atEntity.extendedExpiresOn,
|
||||
refresh_on: atEntity.refreshOn,
|
||||
key_id: atEntity.keyId,
|
||||
token_type: atEntity.tokenType,
|
||||
userAssertionHash: atEntity.userAssertionHash,
|
||||
resource: atEntity.resource,
|
||||
};
|
||||
});
|
||||
|
||||
return accessTokens;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize refreshTokens
|
||||
* @param rtCache - cache of refresh tokens
|
||||
*/
|
||||
static serializeRefreshTokens(
|
||||
rtCache: RefreshTokenCache
|
||||
): Record<string, SerializedRefreshTokenEntity> {
|
||||
const refreshTokens: Record<string, SerializedRefreshTokenEntity> = {};
|
||||
Object.keys(rtCache).map(function (key) {
|
||||
const rtEntity = rtCache[key];
|
||||
refreshTokens[key] = {
|
||||
home_account_id: rtEntity.homeAccountId,
|
||||
environment: rtEntity.environment,
|
||||
credential_type: rtEntity.credentialType,
|
||||
client_id: rtEntity.clientId,
|
||||
secret: rtEntity.secret,
|
||||
family_id: rtEntity.familyId,
|
||||
target: rtEntity.target,
|
||||
realm: rtEntity.realm,
|
||||
};
|
||||
});
|
||||
|
||||
return refreshTokens;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize amdtCache
|
||||
* @param amdtCache - cache of app metadata
|
||||
*/
|
||||
static serializeAppMetadata(
|
||||
amdtCache: AppMetadataCache
|
||||
): Record<string, SerializedAppMetadataEntity> {
|
||||
const appMetadata: Record<string, SerializedAppMetadataEntity> = {};
|
||||
Object.keys(amdtCache).map(function (key) {
|
||||
const amdtEntity = amdtCache[key];
|
||||
appMetadata[key] = {
|
||||
client_id: amdtEntity.clientId,
|
||||
environment: amdtEntity.environment,
|
||||
family_id: amdtEntity.familyId,
|
||||
};
|
||||
});
|
||||
|
||||
return appMetadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize the cache
|
||||
* @param inMemCache - itemised cache read from the JSON
|
||||
*/
|
||||
static serializeAllCache(inMemCache: InMemoryCache): JsonCache {
|
||||
return {
|
||||
Account: this.serializeAccounts(inMemCache.accounts),
|
||||
IdToken: this.serializeIdTokens(inMemCache.idTokens),
|
||||
AccessToken: this.serializeAccessTokens(inMemCache.accessTokens),
|
||||
RefreshToken: this.serializeRefreshTokens(inMemCache.refreshTokens),
|
||||
AppMetadata: this.serializeAppMetadata(inMemCache.appMetadata),
|
||||
};
|
||||
}
|
||||
}
|
||||
121
backend/node_modules/@azure/msal-node/src/cache/serializer/SerializerTypes.ts
generated
vendored
Normal file
121
backend/node_modules/@azure/msal-node/src/cache/serializer/SerializerTypes.ts
generated
vendored
Normal file
@ -0,0 +1,121 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import {
|
||||
AccountCache,
|
||||
IdTokenCache,
|
||||
AccessTokenCache,
|
||||
RefreshTokenCache,
|
||||
AppMetadataCache,
|
||||
ValidCacheType,
|
||||
} from "@azure/msal-common/node";
|
||||
|
||||
/**
|
||||
* Key value store for in-memory cache
|
||||
* @public
|
||||
*/
|
||||
export type CacheKVStore = Record<string, ValidCacheType>;
|
||||
|
||||
/**
|
||||
* Cache format read from the cache blob provided to the configuration during app instantiation
|
||||
* @public
|
||||
*/
|
||||
export type JsonCache = {
|
||||
Account: Record<string, SerializedAccountEntity>;
|
||||
IdToken: Record<string, SerializedIdTokenEntity>;
|
||||
AccessToken: Record<string, SerializedAccessTokenEntity>;
|
||||
RefreshToken: Record<string, SerializedRefreshTokenEntity>;
|
||||
AppMetadata: Record<string, SerializedAppMetadataEntity>;
|
||||
};
|
||||
|
||||
/**
|
||||
* Intermittent type to handle in-memory data objects with defined types
|
||||
* @public
|
||||
*/
|
||||
export type InMemoryCache = {
|
||||
accounts: AccountCache;
|
||||
idTokens: IdTokenCache;
|
||||
accessTokens: AccessTokenCache;
|
||||
refreshTokens: RefreshTokenCache;
|
||||
appMetadata: AppMetadataCache;
|
||||
};
|
||||
|
||||
/**
|
||||
* Account type
|
||||
* @public
|
||||
*/
|
||||
export type SerializedAccountEntity = {
|
||||
home_account_id: string;
|
||||
environment: string;
|
||||
realm: string;
|
||||
local_account_id: string;
|
||||
username: string;
|
||||
authority_type: string;
|
||||
name?: string;
|
||||
client_info?: string;
|
||||
last_modification_time?: string;
|
||||
last_modification_app?: string;
|
||||
tenantProfiles?: string[];
|
||||
};
|
||||
|
||||
/**
|
||||
* Idtoken credential type
|
||||
* @public
|
||||
*/
|
||||
export type SerializedIdTokenEntity = {
|
||||
home_account_id: string;
|
||||
environment: string;
|
||||
credential_type: string;
|
||||
client_id: string;
|
||||
secret: string;
|
||||
realm: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* Access token credential type
|
||||
* @public
|
||||
*/
|
||||
export type SerializedAccessTokenEntity = {
|
||||
home_account_id: string;
|
||||
environment: string;
|
||||
credential_type: string;
|
||||
client_id: string;
|
||||
secret: string;
|
||||
realm: string;
|
||||
target: string;
|
||||
cached_at: string;
|
||||
expires_on: string;
|
||||
extended_expires_on?: string;
|
||||
refresh_on?: string;
|
||||
key_id?: string;
|
||||
token_type?: string;
|
||||
userAssertionHash?: string;
|
||||
resource?: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* Refresh token credential type
|
||||
* @public
|
||||
*/
|
||||
export type SerializedRefreshTokenEntity = {
|
||||
home_account_id: string;
|
||||
environment: string;
|
||||
credential_type: string;
|
||||
client_id: string;
|
||||
secret: string;
|
||||
family_id?: string;
|
||||
target?: string;
|
||||
realm?: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* AppMetadata type
|
||||
* @public
|
||||
*/
|
||||
export type SerializedAppMetadataEntity = {
|
||||
client_id: string;
|
||||
environment: string;
|
||||
family_id?: string;
|
||||
};
|
||||
158
backend/node_modules/@azure/msal-node/src/client/BaseClient.ts
generated
vendored
Normal file
158
backend/node_modules/@azure/msal-node/src/client/BaseClient.ts
generated
vendored
Normal file
@ -0,0 +1,158 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import {
|
||||
ClientConfiguration,
|
||||
buildClientConfiguration,
|
||||
CommonClientConfiguration,
|
||||
INetworkModule,
|
||||
NetworkRequestOptions,
|
||||
Logger,
|
||||
ICrypto,
|
||||
CacheManager,
|
||||
ServerTelemetryManager,
|
||||
Authority,
|
||||
CcsCredential,
|
||||
TokenProtocol,
|
||||
RequestThumbprint,
|
||||
ServerAuthorizationTokenResponse,
|
||||
NetworkResponse,
|
||||
BaseAuthRequest,
|
||||
StubPerformanceClient,
|
||||
} from "@azure/msal-common/node";
|
||||
import { version, name } from "../packageMetadata.js";
|
||||
|
||||
/**
|
||||
* Base application class which will construct requests to send to and handle responses from the Microsoft STS using the authorization code flow.
|
||||
* @internal
|
||||
*/
|
||||
export abstract class BaseClient {
|
||||
// Logger object
|
||||
public logger: Logger;
|
||||
|
||||
// Application config
|
||||
protected config: CommonClientConfiguration;
|
||||
|
||||
// Crypto Interface
|
||||
protected cryptoUtils: ICrypto;
|
||||
|
||||
// Storage Interface
|
||||
protected cacheManager: CacheManager;
|
||||
|
||||
// Network Interface
|
||||
protected networkClient: INetworkModule;
|
||||
|
||||
// Server Telemetry Manager
|
||||
protected serverTelemetryManager: ServerTelemetryManager | null;
|
||||
|
||||
// Default authority object
|
||||
public authority: Authority;
|
||||
|
||||
protected performanceClient: StubPerformanceClient;
|
||||
|
||||
protected constructor(configuration: ClientConfiguration) {
|
||||
// Set the configuration
|
||||
this.config = buildClientConfiguration(configuration);
|
||||
|
||||
// Initialize the logger
|
||||
this.logger = new Logger(this.config.loggerOptions, name, version);
|
||||
|
||||
// Initialize crypto
|
||||
this.cryptoUtils = this.config.cryptoInterface;
|
||||
|
||||
// Initialize storage interface
|
||||
this.cacheManager = this.config.storageInterface;
|
||||
|
||||
// Set the network interface
|
||||
this.networkClient = this.config.networkInterface;
|
||||
|
||||
// Set TelemetryManager
|
||||
this.serverTelemetryManager = this.config.serverTelemetryManager;
|
||||
|
||||
// set Authority
|
||||
this.authority = this.config.authOptions.authority;
|
||||
|
||||
this.performanceClient = new StubPerformanceClient();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates default headers for requests to token endpoint
|
||||
*/
|
||||
protected createTokenRequestHeaders(
|
||||
ccsCred?: CcsCredential
|
||||
): Record<string, string> {
|
||||
return TokenProtocol.createTokenRequestHeaders(
|
||||
this.logger,
|
||||
false,
|
||||
ccsCred
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Http post to token endpoint
|
||||
* @param tokenEndpoint
|
||||
* @param queryString
|
||||
* @param headers
|
||||
* @param thumbprint
|
||||
*/
|
||||
protected async executePostToTokenEndpoint(
|
||||
tokenEndpoint: string,
|
||||
queryString: string,
|
||||
headers: Record<string, string>,
|
||||
thumbprint: RequestThumbprint,
|
||||
correlationId: string
|
||||
): Promise<NetworkResponse<ServerAuthorizationTokenResponse>> {
|
||||
return TokenProtocol.executePostToTokenEndpoint(
|
||||
tokenEndpoint,
|
||||
queryString,
|
||||
headers,
|
||||
thumbprint,
|
||||
correlationId,
|
||||
this.cacheManager,
|
||||
this.networkClient,
|
||||
this.logger,
|
||||
this.performanceClient,
|
||||
this.serverTelemetryManager
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps sendPostRequestAsync with necessary preflight and postflight logic
|
||||
* @param thumbprint - Request thumbprint for throttling
|
||||
* @param tokenEndpoint - Endpoint to make the POST to
|
||||
* @param options - Body and Headers to include on the POST request
|
||||
* @param correlationId - CorrelationId for telemetry
|
||||
*/
|
||||
async sendPostRequest<T extends ServerAuthorizationTokenResponse>(
|
||||
thumbprint: RequestThumbprint,
|
||||
tokenEndpoint: string,
|
||||
options: NetworkRequestOptions,
|
||||
correlationId: string
|
||||
): Promise<NetworkResponse<T>> {
|
||||
return TokenProtocol.sendPostRequest<T>(
|
||||
thumbprint,
|
||||
tokenEndpoint,
|
||||
options,
|
||||
correlationId,
|
||||
this.cacheManager,
|
||||
this.networkClient,
|
||||
this.logger,
|
||||
this.performanceClient
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates query string for the /token request
|
||||
* @param request
|
||||
*/
|
||||
createTokenQueryParameters(request: BaseAuthRequest): string {
|
||||
return TokenProtocol.createTokenQueryParameters(
|
||||
request,
|
||||
this.config.authOptions.clientId,
|
||||
this.config.authOptions.redirectUri,
|
||||
this.performanceClient
|
||||
);
|
||||
}
|
||||
}
|
||||
683
backend/node_modules/@azure/msal-node/src/client/ClientApplication.ts
generated
vendored
Normal file
683
backend/node_modules/@azure/msal-node/src/client/ClientApplication.ts
generated
vendored
Normal file
@ -0,0 +1,683 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import {
|
||||
AuthorizationCodeClient,
|
||||
ClientConfiguration,
|
||||
RefreshTokenClient,
|
||||
AuthenticationResult,
|
||||
Authority,
|
||||
AuthorityFactory,
|
||||
BaseAuthRequest,
|
||||
SilentFlowClient,
|
||||
Logger,
|
||||
ServerTelemetryManager,
|
||||
ServerTelemetryRequest,
|
||||
CommonSilentFlowRequest,
|
||||
CommonRefreshTokenRequest,
|
||||
CommonAuthorizationCodeRequest,
|
||||
CommonAuthorizationUrlRequest,
|
||||
AuthorityOptions,
|
||||
AzureRegionConfiguration,
|
||||
AuthError,
|
||||
AzureCloudOptions,
|
||||
AuthorizationCodePayload,
|
||||
createClientAuthError,
|
||||
ClientAuthErrorCodes,
|
||||
buildStaticAuthorityOptions,
|
||||
ClientAssertion as ClientAssertionType,
|
||||
getClientAssertion,
|
||||
ClientAssertionCallback,
|
||||
Constants,
|
||||
ClientAuthError,
|
||||
StubPerformanceClient,
|
||||
} from "@azure/msal-common/node";
|
||||
import {
|
||||
Configuration,
|
||||
buildAppConfiguration,
|
||||
NodeConfiguration,
|
||||
} from "../config/Configuration.js";
|
||||
import { CryptoProvider } from "../crypto/CryptoProvider.js";
|
||||
import { NodeStorage } from "../cache/NodeStorage.js";
|
||||
import { Constants as NodeConstants, ApiId } from "../utils/Constants.js";
|
||||
import { TokenCache } from "../cache/TokenCache.js";
|
||||
import { ClientAssertion } from "./ClientAssertion.js";
|
||||
import { AuthorizationUrlRequest } from "../request/AuthorizationUrlRequest.js";
|
||||
import { AuthorizationCodeRequest } from "../request/AuthorizationCodeRequest.js";
|
||||
import { RefreshTokenRequest } from "../request/RefreshTokenRequest.js";
|
||||
import { SilentFlowRequest } from "../request/SilentFlowRequest.js";
|
||||
import { version, name } from "../packageMetadata.js";
|
||||
import { UsernamePasswordRequest } from "../request/UsernamePasswordRequest.js";
|
||||
import { CommonUsernamePasswordRequest } from "../request/CommonUsernamePasswordRequest.js";
|
||||
import { NodeAuthError } from "../error/NodeAuthError.js";
|
||||
import { UsernamePasswordClient } from "./UsernamePasswordClient.js";
|
||||
import { getAuthCodeRequestUrl } from "../protocol/Authorize.js";
|
||||
|
||||
/**
|
||||
* Base abstract class for all ClientApplications - public and confidential
|
||||
* @public
|
||||
*/
|
||||
export abstract class ClientApplication {
|
||||
protected readonly cryptoProvider: CryptoProvider;
|
||||
private tokenCache: TokenCache;
|
||||
|
||||
/**
|
||||
* Platform storage object
|
||||
*/
|
||||
protected storage: NodeStorage;
|
||||
/**
|
||||
* Logger object to log the application flow
|
||||
*/
|
||||
protected logger: Logger;
|
||||
/**
|
||||
* Platform configuration initialized by the application
|
||||
*/
|
||||
protected config: NodeConfiguration;
|
||||
/**
|
||||
* Client assertion passed by the user for confidential client flows
|
||||
*/
|
||||
protected clientAssertion: ClientAssertion;
|
||||
protected developerProvidedClientAssertion:
|
||||
| string
|
||||
| ClientAssertionCallback;
|
||||
/**
|
||||
* Client secret passed by the user for confidential client flows
|
||||
*/
|
||||
protected clientSecret: string;
|
||||
|
||||
/**
|
||||
* Constructor for the ClientApplication
|
||||
*/
|
||||
protected constructor(configuration: Configuration) {
|
||||
this.config = buildAppConfiguration(configuration);
|
||||
this.cryptoProvider = new CryptoProvider();
|
||||
this.logger = new Logger(
|
||||
this.config.system.loggerOptions,
|
||||
name,
|
||||
version
|
||||
);
|
||||
this.storage = new NodeStorage(
|
||||
this.logger,
|
||||
this.config.auth.clientId,
|
||||
this.cryptoProvider,
|
||||
buildStaticAuthorityOptions(this.config.auth)
|
||||
);
|
||||
this.tokenCache = new TokenCache(
|
||||
this.storage,
|
||||
this.logger,
|
||||
this.config.cache.cachePlugin
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the URL of the authorization request, letting the user input credentials and consent to the
|
||||
* application. The URL targets the /authorize endpoint of the authority configured in the
|
||||
* application object.
|
||||
*
|
||||
* Once the user inputs their credentials and consents, the authority will send a response to the redirect URI
|
||||
* sent in the request and should contain an authorization code, which can then be used to acquire tokens via
|
||||
* `acquireTokenByCode(AuthorizationCodeRequest)`.
|
||||
*/
|
||||
async getAuthCodeUrl(request: AuthorizationUrlRequest): Promise<string> {
|
||||
this.logger.info("getAuthCodeUrl called", request.correlationId || "");
|
||||
const validRequest: CommonAuthorizationUrlRequest = {
|
||||
...request,
|
||||
...(await this.initializeBaseRequest(request)),
|
||||
responseMode: request.responseMode || Constants.ResponseMode.QUERY,
|
||||
authenticationScheme: Constants.AuthenticationScheme.BEARER,
|
||||
state: request.state || "",
|
||||
nonce: request.nonce || "",
|
||||
};
|
||||
|
||||
const discoveredAuthority = await this.createAuthority(
|
||||
validRequest.authority,
|
||||
validRequest.correlationId,
|
||||
undefined,
|
||||
request.azureCloudOptions
|
||||
);
|
||||
return getAuthCodeRequestUrl(
|
||||
this.config,
|
||||
discoveredAuthority,
|
||||
validRequest,
|
||||
this.logger
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Acquires a token by exchanging the Authorization Code received from the first step of OAuth2.0
|
||||
* Authorization Code flow.
|
||||
*
|
||||
* `getAuthCodeUrl(AuthorizationCodeUrlRequest)` can be used to create the URL for the first step of OAuth2.0
|
||||
* Authorization Code flow. Ensure that values for redirectUri and scopes in AuthorizationCodeUrlRequest and
|
||||
* AuthorizationCodeRequest are the same.
|
||||
*/
|
||||
async acquireTokenByCode(
|
||||
request: AuthorizationCodeRequest,
|
||||
authCodePayLoad?: AuthorizationCodePayload
|
||||
): Promise<AuthenticationResult> {
|
||||
this.logger.info(
|
||||
"acquireTokenByCode called",
|
||||
request.correlationId || ""
|
||||
);
|
||||
if (request.state && authCodePayLoad) {
|
||||
this.logger.info(
|
||||
"acquireTokenByCode - validating state",
|
||||
request.correlationId || ""
|
||||
);
|
||||
this.validateState(request.state, authCodePayLoad.state || "");
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
authCodePayLoad = { ...authCodePayLoad, state: "" };
|
||||
}
|
||||
const validRequest: CommonAuthorizationCodeRequest = {
|
||||
...request,
|
||||
...(await this.initializeBaseRequest(request)),
|
||||
authenticationScheme: Constants.AuthenticationScheme.BEARER,
|
||||
};
|
||||
|
||||
const serverTelemetryManager = this.initializeServerTelemetryManager(
|
||||
ApiId.acquireTokenByCode,
|
||||
validRequest.correlationId
|
||||
);
|
||||
try {
|
||||
const discoveredAuthority = await this.createAuthority(
|
||||
validRequest.authority,
|
||||
validRequest.correlationId,
|
||||
undefined,
|
||||
request.azureCloudOptions
|
||||
);
|
||||
const authClientConfig = await this.buildOauthClientConfiguration(
|
||||
discoveredAuthority,
|
||||
validRequest.correlationId,
|
||||
validRequest.redirectUri,
|
||||
serverTelemetryManager
|
||||
);
|
||||
const authorizationCodeClient = new AuthorizationCodeClient(
|
||||
authClientConfig,
|
||||
new StubPerformanceClient()
|
||||
);
|
||||
this.logger.verbose(
|
||||
"Auth code client created",
|
||||
validRequest.correlationId
|
||||
);
|
||||
return await authorizationCodeClient.acquireToken(
|
||||
validRequest,
|
||||
ApiId.acquireTokenByCode,
|
||||
authCodePayLoad
|
||||
);
|
||||
} catch (e) {
|
||||
if (e instanceof AuthError) {
|
||||
e.setCorrelationId(validRequest.correlationId);
|
||||
}
|
||||
serverTelemetryManager.cacheFailedRequest(e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Acquires a token by exchanging the refresh token provided for a new set of tokens.
|
||||
*
|
||||
* This API is provided only for scenarios where you would like to migrate from ADAL to MSAL. Otherwise, it is
|
||||
* recommended that you use `acquireTokenSilent()` for silent scenarios. When using `acquireTokenSilent()`, MSAL will
|
||||
* handle the caching and refreshing of tokens automatically.
|
||||
*/
|
||||
async acquireTokenByRefreshToken(
|
||||
request: RefreshTokenRequest
|
||||
): Promise<AuthenticationResult | null> {
|
||||
this.logger.info(
|
||||
"acquireTokenByRefreshToken called",
|
||||
request.correlationId || ""
|
||||
);
|
||||
const validRequest: CommonRefreshTokenRequest = {
|
||||
...request,
|
||||
...(await this.initializeBaseRequest(request)),
|
||||
authenticationScheme: Constants.AuthenticationScheme.BEARER,
|
||||
};
|
||||
|
||||
const serverTelemetryManager = this.initializeServerTelemetryManager(
|
||||
ApiId.acquireTokenByRefreshToken,
|
||||
validRequest.correlationId
|
||||
);
|
||||
try {
|
||||
const discoveredAuthority = await this.createAuthority(
|
||||
validRequest.authority,
|
||||
validRequest.correlationId,
|
||||
undefined,
|
||||
request.azureCloudOptions
|
||||
);
|
||||
const refreshTokenClientConfig =
|
||||
await this.buildOauthClientConfiguration(
|
||||
discoveredAuthority,
|
||||
validRequest.correlationId,
|
||||
validRequest.redirectUri || "",
|
||||
serverTelemetryManager
|
||||
);
|
||||
const refreshTokenClient = new RefreshTokenClient(
|
||||
refreshTokenClientConfig,
|
||||
new StubPerformanceClient()
|
||||
);
|
||||
this.logger.verbose(
|
||||
"Refresh token client created",
|
||||
validRequest.correlationId
|
||||
);
|
||||
return await refreshTokenClient.acquireToken(
|
||||
validRequest,
|
||||
ApiId.acquireTokenByRefreshToken
|
||||
);
|
||||
} catch (e) {
|
||||
if (e instanceof AuthError) {
|
||||
e.setCorrelationId(validRequest.correlationId);
|
||||
}
|
||||
serverTelemetryManager.cacheFailedRequest(e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Acquires a token silently when a user specifies the account the token is requested for.
|
||||
*
|
||||
* This API expects the user to provide an account object and looks into the cache to retrieve the token if present.
|
||||
* There is also an optional "forceRefresh" boolean the user can send to bypass the cache for access_token and id_token.
|
||||
* In case the refresh_token is expired or not found, an error is thrown
|
||||
* and the guidance is for the user to call any interactive token acquisition API (eg: `acquireTokenByCode()`).
|
||||
*/
|
||||
async acquireTokenSilent(
|
||||
request: SilentFlowRequest
|
||||
): Promise<AuthenticationResult> {
|
||||
const validRequest: CommonSilentFlowRequest = {
|
||||
...request,
|
||||
...(await this.initializeBaseRequest(request)),
|
||||
forceRefresh: request.forceRefresh || false,
|
||||
};
|
||||
|
||||
const serverTelemetryManager = this.initializeServerTelemetryManager(
|
||||
ApiId.acquireTokenSilent,
|
||||
validRequest.correlationId,
|
||||
validRequest.forceRefresh
|
||||
);
|
||||
|
||||
try {
|
||||
const discoveredAuthority = await this.createAuthority(
|
||||
validRequest.authority,
|
||||
validRequest.correlationId,
|
||||
undefined,
|
||||
request.azureCloudOptions
|
||||
);
|
||||
const clientConfiguration =
|
||||
await this.buildOauthClientConfiguration(
|
||||
discoveredAuthority,
|
||||
validRequest.correlationId,
|
||||
validRequest.redirectUri || "",
|
||||
serverTelemetryManager
|
||||
);
|
||||
const silentFlowClient = new SilentFlowClient(
|
||||
clientConfiguration,
|
||||
new StubPerformanceClient()
|
||||
);
|
||||
this.logger.verbose(
|
||||
"Silent flow client created",
|
||||
validRequest.correlationId
|
||||
);
|
||||
try {
|
||||
// always overwrite the in-memory cache with the persistence cache (if it exists) before a cache lookup
|
||||
await this.tokenCache.overwriteCache();
|
||||
return await this.acquireCachedTokenSilent(
|
||||
validRequest,
|
||||
silentFlowClient,
|
||||
clientConfiguration
|
||||
);
|
||||
} catch (error) {
|
||||
if (
|
||||
error instanceof ClientAuthError &&
|
||||
error.errorCode ===
|
||||
ClientAuthErrorCodes.tokenRefreshRequired
|
||||
) {
|
||||
const refreshTokenClient = new RefreshTokenClient(
|
||||
clientConfiguration,
|
||||
new StubPerformanceClient()
|
||||
);
|
||||
return refreshTokenClient.acquireTokenByRefreshToken(
|
||||
validRequest,
|
||||
ApiId.acquireTokenSilent
|
||||
);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
} catch (error) {
|
||||
if (error instanceof AuthError) {
|
||||
error.setCorrelationId(validRequest.correlationId);
|
||||
}
|
||||
serverTelemetryManager.cacheFailedRequest(error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
private async acquireCachedTokenSilent(
|
||||
validRequest: CommonSilentFlowRequest,
|
||||
silentFlowClient: SilentFlowClient,
|
||||
clientConfiguration: ClientConfiguration
|
||||
): Promise<AuthenticationResult> {
|
||||
const [authResponse, cacheOutcome] =
|
||||
await silentFlowClient.acquireCachedToken({
|
||||
...validRequest,
|
||||
scopes: validRequest.scopes?.length
|
||||
? validRequest.scopes
|
||||
: [...Constants.OIDC_DEFAULT_SCOPES],
|
||||
});
|
||||
|
||||
if (cacheOutcome === Constants.CacheOutcome.PROACTIVELY_REFRESHED) {
|
||||
this.logger.info(
|
||||
"ClientApplication:acquireCachedTokenSilent - Cached access token's refreshOn property has been exceeded'. It's not expired, but must be refreshed.",
|
||||
validRequest.correlationId
|
||||
);
|
||||
// refresh the access token in the background
|
||||
const refreshTokenClient = new RefreshTokenClient(
|
||||
clientConfiguration,
|
||||
new StubPerformanceClient()
|
||||
);
|
||||
|
||||
try {
|
||||
await refreshTokenClient.acquireTokenByRefreshToken(
|
||||
validRequest,
|
||||
ApiId.acquireTokenSilent
|
||||
);
|
||||
} catch {
|
||||
// do nothing, this is running in the background and no action is to be taken upon success or failure
|
||||
}
|
||||
}
|
||||
|
||||
// return the cached token
|
||||
return authResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Acquires tokens with password grant by exchanging client applications username and password for credentials
|
||||
*
|
||||
* The latest OAuth 2.0 Security Best Current Practice disallows the password grant entirely.
|
||||
* More details on this recommendation at https://tools.ietf.org/html/draft-ietf-oauth-security-topics-13#section-3.4
|
||||
* Microsoft's documentation and recommendations are at:
|
||||
* https://docs.microsoft.com/en-us/azure/active-directory/develop/msal-authentication-flows#usernamepassword
|
||||
*
|
||||
* @param request - UsenamePasswordRequest
|
||||
* @deprecated - Use a more secure flow instead
|
||||
*/
|
||||
async acquireTokenByUsernamePassword(
|
||||
request: UsernamePasswordRequest
|
||||
): Promise<AuthenticationResult | null> {
|
||||
this.logger.info(
|
||||
"acquireTokenByUsernamePassword called",
|
||||
request.correlationId || ""
|
||||
);
|
||||
const validRequest: CommonUsernamePasswordRequest = {
|
||||
...request,
|
||||
...(await this.initializeBaseRequest(request)),
|
||||
};
|
||||
const serverTelemetryManager = this.initializeServerTelemetryManager(
|
||||
ApiId.acquireTokenByUsernamePassword,
|
||||
validRequest.correlationId
|
||||
);
|
||||
try {
|
||||
const discoveredAuthority = await this.createAuthority(
|
||||
validRequest.authority,
|
||||
validRequest.correlationId,
|
||||
undefined,
|
||||
request.azureCloudOptions
|
||||
);
|
||||
const usernamePasswordClientConfig =
|
||||
await this.buildOauthClientConfiguration(
|
||||
discoveredAuthority,
|
||||
validRequest.correlationId,
|
||||
"",
|
||||
serverTelemetryManager
|
||||
);
|
||||
const usernamePasswordClient = new UsernamePasswordClient(
|
||||
usernamePasswordClientConfig
|
||||
);
|
||||
this.logger.verbose(
|
||||
"Username password client created",
|
||||
validRequest.correlationId
|
||||
);
|
||||
return await usernamePasswordClient.acquireToken(validRequest);
|
||||
} catch (e) {
|
||||
if (e instanceof AuthError) {
|
||||
e.setCorrelationId(validRequest.correlationId);
|
||||
}
|
||||
serverTelemetryManager.cacheFailedRequest(e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the token cache for the application.
|
||||
*/
|
||||
getTokenCache(): TokenCache {
|
||||
this.logger.info("getTokenCache called", "");
|
||||
return this.tokenCache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates OIDC state by comparing the user cached state with the state received from the server.
|
||||
*
|
||||
* This API is provided for scenarios where you would use OAuth2.0 state parameter to mitigate against
|
||||
* CSRF attacks.
|
||||
* For more information about state, visit https://datatracker.ietf.org/doc/html/rfc6819#section-3.6.
|
||||
* @param state - Unique GUID generated by the user that is cached by the user and sent to the server during the first leg of the flow
|
||||
* @param cachedState - This string is sent back by the server with the authorization code
|
||||
*/
|
||||
protected validateState(state: string, cachedState: string): void {
|
||||
if (!state) {
|
||||
throw NodeAuthError.createStateNotFoundError();
|
||||
}
|
||||
|
||||
if (state !== cachedState) {
|
||||
throw createClientAuthError(ClientAuthErrorCodes.stateMismatch);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the logger instance
|
||||
*/
|
||||
getLogger(): Logger {
|
||||
return this.logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces the default logger set in configurations with new Logger with new configurations
|
||||
* @param logger - Logger instance
|
||||
*/
|
||||
setLogger(logger: Logger): void {
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the common configuration to be passed to the common component based on the platform configurarion
|
||||
* @param authority - user passed authority in configuration
|
||||
* @param serverTelemetryManager - initializes servertelemetry if passed
|
||||
*/
|
||||
protected async buildOauthClientConfiguration(
|
||||
discoveredAuthority: Authority,
|
||||
requestCorrelationId: string,
|
||||
redirectUri: string,
|
||||
serverTelemetryManager?: ServerTelemetryManager
|
||||
): Promise<ClientConfiguration> {
|
||||
this.logger.verbose(
|
||||
"buildOauthClientConfiguration called",
|
||||
requestCorrelationId
|
||||
);
|
||||
|
||||
this.logger.info(
|
||||
`Building oauth client configuration with the following authority: ${discoveredAuthority.tokenEndpoint}.`,
|
||||
requestCorrelationId
|
||||
);
|
||||
|
||||
serverTelemetryManager?.updateRegionDiscoveryMetadata(
|
||||
discoveredAuthority.regionDiscoveryMetadata
|
||||
);
|
||||
|
||||
const clientConfiguration: ClientConfiguration = {
|
||||
authOptions: {
|
||||
clientId: this.config.auth.clientId,
|
||||
authority: discoveredAuthority,
|
||||
clientCapabilities: this.config.auth.clientCapabilities,
|
||||
redirectUri,
|
||||
isMcp: this.config.auth.isMcp,
|
||||
},
|
||||
loggerOptions: {
|
||||
logLevel: this.config.system.loggerOptions.logLevel,
|
||||
loggerCallback: this.config.system.loggerOptions.loggerCallback,
|
||||
piiLoggingEnabled:
|
||||
this.config.system.loggerOptions.piiLoggingEnabled,
|
||||
correlationId: requestCorrelationId,
|
||||
},
|
||||
cryptoInterface: this.cryptoProvider,
|
||||
networkInterface: this.config.system.networkClient,
|
||||
storageInterface: this.storage,
|
||||
serverTelemetryManager: serverTelemetryManager,
|
||||
clientCredentials: {
|
||||
clientSecret: this.clientSecret,
|
||||
clientAssertion: await this.getClientAssertion(
|
||||
discoveredAuthority
|
||||
),
|
||||
},
|
||||
libraryInfo: {
|
||||
sku: NodeConstants.MSAL_SKU,
|
||||
version: version,
|
||||
cpu: process.arch || "",
|
||||
os: process.platform || "",
|
||||
},
|
||||
telemetry: this.config.telemetry,
|
||||
persistencePlugin: this.config.cache.cachePlugin,
|
||||
serializableCache: this.tokenCache,
|
||||
};
|
||||
|
||||
return clientConfiguration;
|
||||
}
|
||||
|
||||
private async getClientAssertion(
|
||||
authority: Authority
|
||||
): Promise<ClientAssertionType> {
|
||||
if (this.developerProvidedClientAssertion) {
|
||||
this.clientAssertion = ClientAssertion.fromAssertion(
|
||||
await getClientAssertion(
|
||||
this.developerProvidedClientAssertion,
|
||||
this.config.auth.clientId,
|
||||
authority.tokenEndpoint
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
this.clientAssertion && {
|
||||
assertion: this.clientAssertion.getJwt(
|
||||
this.cryptoProvider,
|
||||
this.config.auth.clientId,
|
||||
authority.tokenEndpoint
|
||||
),
|
||||
assertionType: NodeConstants.JWT_BEARER_ASSERTION_TYPE,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a request with the default scopes & generates a correlationId.
|
||||
* @param authRequest - BaseAuthRequest for initialization
|
||||
*/
|
||||
protected async initializeBaseRequest(
|
||||
authRequest: Partial<BaseAuthRequest>
|
||||
): Promise<BaseAuthRequest> {
|
||||
const correlationId =
|
||||
authRequest.correlationId || this.cryptoProvider.createNewGuid();
|
||||
this.logger.verbose("initializeRequestScopes called", correlationId);
|
||||
// Default authenticationScheme to Bearer, log that POP isn't supported yet
|
||||
if (
|
||||
authRequest.authenticationScheme &&
|
||||
authRequest.authenticationScheme ===
|
||||
Constants.AuthenticationScheme.POP
|
||||
) {
|
||||
this.logger.verbose(
|
||||
"Authentication Scheme 'pop' is not supported yet, setting Authentication Scheme to 'Bearer' for request",
|
||||
correlationId
|
||||
);
|
||||
}
|
||||
|
||||
authRequest.authenticationScheme =
|
||||
Constants.AuthenticationScheme.BEARER;
|
||||
|
||||
return {
|
||||
...authRequest,
|
||||
scopes: [
|
||||
...((authRequest && authRequest.scopes) || []),
|
||||
...Constants.OIDC_DEFAULT_SCOPES,
|
||||
],
|
||||
correlationId,
|
||||
authority: authRequest.authority || this.config.auth.authority,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the server telemetry payload
|
||||
* @param apiId - Id for a specific request
|
||||
* @param correlationId - GUID
|
||||
* @param forceRefresh - boolean to indicate network call
|
||||
*/
|
||||
protected initializeServerTelemetryManager(
|
||||
apiId: number,
|
||||
correlationId: string,
|
||||
forceRefresh?: boolean
|
||||
): ServerTelemetryManager {
|
||||
const telemetryPayload: ServerTelemetryRequest = {
|
||||
clientId: this.config.auth.clientId,
|
||||
correlationId: correlationId,
|
||||
apiId: apiId,
|
||||
forceRefresh: forceRefresh || false,
|
||||
};
|
||||
|
||||
return new ServerTelemetryManager(telemetryPayload, this.storage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create authority instance. If authority not passed in request, default to authority set on the application
|
||||
* object. If no authority set in application object, then default to common authority.
|
||||
* @param authorityString - authority from user configuration
|
||||
*/
|
||||
protected async createAuthority(
|
||||
authorityString: string,
|
||||
requestCorrelationId: string,
|
||||
azureRegionConfiguration?: AzureRegionConfiguration,
|
||||
azureCloudOptions?: AzureCloudOptions
|
||||
): Promise<Authority> {
|
||||
this.logger.verbose("createAuthority called", requestCorrelationId);
|
||||
|
||||
// build authority string based on auth params - azureCloudInstance is prioritized if provided
|
||||
const authorityUrl = Authority.generateAuthority(
|
||||
authorityString,
|
||||
azureCloudOptions || this.config.auth.azureCloudOptions
|
||||
);
|
||||
|
||||
const authorityOptions: AuthorityOptions = {
|
||||
protocolMode: this.config.system.protocolMode,
|
||||
knownAuthorities: this.config.auth.knownAuthorities,
|
||||
cloudDiscoveryMetadata: this.config.auth.cloudDiscoveryMetadata,
|
||||
authorityMetadata: this.config.auth.authorityMetadata,
|
||||
azureRegionConfiguration,
|
||||
};
|
||||
|
||||
return AuthorityFactory.createDiscoveredInstance(
|
||||
authorityUrl,
|
||||
this.config.system.networkClient,
|
||||
this.storage,
|
||||
authorityOptions,
|
||||
this.logger,
|
||||
requestCorrelationId,
|
||||
new StubPerformanceClient()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the cache except for authority metadata.
|
||||
*/
|
||||
clearCache(): void {
|
||||
this.storage.clear();
|
||||
}
|
||||
}
|
||||
202
backend/node_modules/@azure/msal-node/src/client/ClientAssertion.ts
generated
vendored
Normal file
202
backend/node_modules/@azure/msal-node/src/client/ClientAssertion.ts
generated
vendored
Normal file
@ -0,0 +1,202 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import jwt from "jsonwebtoken";
|
||||
import {
|
||||
TimeUtils,
|
||||
createClientAuthError,
|
||||
Constants,
|
||||
} from "@azure/msal-common/node";
|
||||
import { CryptoProvider } from "../crypto/CryptoProvider.js";
|
||||
import { EncodingUtils } from "../utils/EncodingUtils.js";
|
||||
import { JwtConstants } from "../utils/Constants.js";
|
||||
import * as NodeClientAuthErrorCodes from "../error/ClientAuthErrorCodes.js";
|
||||
|
||||
/**
|
||||
* Client assertion of type jwt-bearer used in confidential client flows
|
||||
* @public
|
||||
*/
|
||||
export class ClientAssertion {
|
||||
private jwt: string;
|
||||
private privateKey: string;
|
||||
private thumbprint: string;
|
||||
private useSha256: boolean;
|
||||
private expirationTime: number;
|
||||
private issuer: string;
|
||||
private jwtAudience: string;
|
||||
private publicCertificate: Array<string>;
|
||||
|
||||
/**
|
||||
* Initialize the ClientAssertion class from the clientAssertion passed by the user
|
||||
* @param assertion - refer https://tools.ietf.org/html/rfc7521
|
||||
*/
|
||||
public static fromAssertion(assertion: string): ClientAssertion {
|
||||
const clientAssertion = new ClientAssertion();
|
||||
clientAssertion.jwt = assertion;
|
||||
return clientAssertion;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use fromCertificateWithSha256Thumbprint instead, with a SHA-256 thumprint
|
||||
* Initialize the ClientAssertion class from the certificate passed by the user
|
||||
* @param thumbprint - identifier of a certificate
|
||||
* @param privateKey - secret key
|
||||
* @param publicCertificate - electronic document provided to prove the ownership of the public key
|
||||
*/
|
||||
public static fromCertificate(
|
||||
thumbprint: string,
|
||||
privateKey: string,
|
||||
publicCertificate?: string
|
||||
): ClientAssertion {
|
||||
const clientAssertion = new ClientAssertion();
|
||||
clientAssertion.privateKey = privateKey;
|
||||
clientAssertion.thumbprint = thumbprint;
|
||||
clientAssertion.useSha256 = false;
|
||||
if (publicCertificate) {
|
||||
clientAssertion.publicCertificate =
|
||||
this.parseCertificate(publicCertificate);
|
||||
}
|
||||
return clientAssertion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the ClientAssertion class from the certificate passed by the user
|
||||
* @param thumbprint - identifier of a certificate
|
||||
* @param privateKey - secret key
|
||||
* @param publicCertificate - electronic document provided to prove the ownership of the public key
|
||||
*/
|
||||
public static fromCertificateWithSha256Thumbprint(
|
||||
thumbprint: string,
|
||||
privateKey: string,
|
||||
publicCertificate?: string
|
||||
): ClientAssertion {
|
||||
const clientAssertion = new ClientAssertion();
|
||||
clientAssertion.privateKey = privateKey;
|
||||
clientAssertion.thumbprint = thumbprint;
|
||||
clientAssertion.useSha256 = true;
|
||||
if (publicCertificate) {
|
||||
clientAssertion.publicCertificate =
|
||||
this.parseCertificate(publicCertificate);
|
||||
}
|
||||
return clientAssertion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update JWT for certificate based clientAssertion, if passed by the user, uses it as is
|
||||
* @param cryptoProvider - library's crypto helper
|
||||
* @param issuer - iss claim
|
||||
* @param jwtAudience - aud claim
|
||||
*/
|
||||
public getJwt(
|
||||
cryptoProvider: CryptoProvider,
|
||||
issuer: string,
|
||||
jwtAudience: string
|
||||
): string {
|
||||
// if assertion was created from certificate, check if jwt is expired and create new one.
|
||||
if (this.privateKey && this.thumbprint) {
|
||||
if (
|
||||
this.jwt &&
|
||||
!this.isExpired() &&
|
||||
issuer === this.issuer &&
|
||||
jwtAudience === this.jwtAudience
|
||||
) {
|
||||
return this.jwt;
|
||||
}
|
||||
|
||||
return this.createJwt(cryptoProvider, issuer, jwtAudience);
|
||||
}
|
||||
|
||||
/*
|
||||
* if assertion was created by caller, then we just append it. It is up to the caller to
|
||||
* ensure that it contains necessary claims and that it is not expired.
|
||||
*/
|
||||
if (this.jwt) {
|
||||
return this.jwt;
|
||||
}
|
||||
|
||||
throw createClientAuthError(NodeClientAuthErrorCodes.invalidAssertion);
|
||||
}
|
||||
|
||||
/**
|
||||
* JWT format and required claims specified: https://tools.ietf.org/html/rfc7523#section-3
|
||||
*/
|
||||
private createJwt(
|
||||
cryptoProvider: CryptoProvider,
|
||||
issuer: string,
|
||||
jwtAudience: string
|
||||
): string {
|
||||
this.issuer = issuer;
|
||||
this.jwtAudience = jwtAudience;
|
||||
const issuedAt = TimeUtils.nowSeconds();
|
||||
this.expirationTime = issuedAt + 600;
|
||||
|
||||
const algorithm = this.useSha256
|
||||
? JwtConstants.PSS_256
|
||||
: JwtConstants.RSA_256;
|
||||
const header: jwt.JwtHeader = {
|
||||
alg: algorithm,
|
||||
};
|
||||
|
||||
const thumbprintHeader = this.useSha256
|
||||
? JwtConstants.X5T_256
|
||||
: JwtConstants.X5T;
|
||||
Object.assign(header, {
|
||||
[thumbprintHeader]: EncodingUtils.base64EncodeUrl(
|
||||
this.thumbprint,
|
||||
Constants.EncodingTypes.HEX
|
||||
),
|
||||
} as Partial<jwt.JwtHeader>);
|
||||
|
||||
if (this.publicCertificate) {
|
||||
Object.assign(header, {
|
||||
[JwtConstants.X5C]: this.publicCertificate,
|
||||
} as Partial<jwt.JwtHeader>);
|
||||
}
|
||||
|
||||
const payload = {
|
||||
[JwtConstants.AUDIENCE]: this.jwtAudience,
|
||||
[JwtConstants.EXPIRATION_TIME]: this.expirationTime,
|
||||
[JwtConstants.ISSUER]: this.issuer,
|
||||
[JwtConstants.SUBJECT]: this.issuer,
|
||||
[JwtConstants.NOT_BEFORE]: issuedAt,
|
||||
[JwtConstants.JWT_ID]: cryptoProvider.createNewGuid(),
|
||||
};
|
||||
|
||||
this.jwt = jwt.sign(payload, this.privateKey, { header });
|
||||
return this.jwt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility API to check expiration
|
||||
*/
|
||||
private isExpired(): boolean {
|
||||
return this.expirationTime < TimeUtils.nowSeconds();
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts the raw certs from a given certificate string and returns them in an array.
|
||||
* @param publicCertificate - electronic document provided to prove the ownership of the public key
|
||||
*/
|
||||
public static parseCertificate(publicCertificate: string): Array<string> {
|
||||
/**
|
||||
* This is regex to identify the certs in a given certificate string.
|
||||
* We want to look for the contents between the BEGIN and END certificate strings, without the associated newlines.
|
||||
* The information in parens "(.+?)" is the capture group to represent the cert we want isolated.
|
||||
* "." means any string character, "+" means match 1 or more times, and "?" means the shortest match.
|
||||
* The "g" at the end of the regex means search the string globally, and the "s" enables the "." to match newlines.
|
||||
*/
|
||||
const regexToFindCerts =
|
||||
/-----BEGIN CERTIFICATE-----\r*\n(.+?)\r*\n-----END CERTIFICATE-----/gs;
|
||||
const certs: string[] = [];
|
||||
|
||||
let matches;
|
||||
while ((matches = regexToFindCerts.exec(publicCertificate)) !== null) {
|
||||
// matches[1] represents the first parens capture group in the regex.
|
||||
certs.push(matches[1].replace(/\r*\n/g, ""));
|
||||
}
|
||||
|
||||
return certs;
|
||||
}
|
||||
}
|
||||
431
backend/node_modules/@azure/msal-node/src/client/ClientCredentialClient.ts
generated
vendored
Normal file
431
backend/node_modules/@azure/msal-node/src/client/ClientCredentialClient.ts
generated
vendored
Normal file
@ -0,0 +1,431 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import {
|
||||
AccessTokenEntity,
|
||||
AuthenticationResult,
|
||||
Authority,
|
||||
CacheManager,
|
||||
ClientAuthErrorCodes,
|
||||
ClientConfiguration,
|
||||
Constants,
|
||||
CredentialFilter,
|
||||
IAppTokenProvider,
|
||||
ICrypto,
|
||||
RequestParameterBuilder,
|
||||
RequestThumbprint,
|
||||
ResponseHandler,
|
||||
ScopeSet,
|
||||
ServerAuthorizationTokenResponse,
|
||||
ServerTelemetryManager,
|
||||
StringUtils,
|
||||
TimeUtils,
|
||||
TokenCacheContext,
|
||||
UrlString,
|
||||
createClientAuthError,
|
||||
ClientAssertion,
|
||||
getClientAssertion,
|
||||
UrlUtils,
|
||||
} from "@azure/msal-common/node";
|
||||
import { ApiId } from "../utils/Constants.js";
|
||||
import {
|
||||
ManagedIdentityConfiguration,
|
||||
ManagedIdentityNodeConfiguration,
|
||||
} from "../config/Configuration.js";
|
||||
import { CommonClientCredentialRequest } from "../request/CommonClientCredentialRequest.js";
|
||||
import { BaseClient } from "./BaseClient.js";
|
||||
|
||||
/**
|
||||
* OAuth2.0 client credential grant
|
||||
* @public
|
||||
*/
|
||||
export class ClientCredentialClient extends BaseClient {
|
||||
private readonly appTokenProvider?: IAppTokenProvider;
|
||||
|
||||
constructor(
|
||||
configuration: ClientConfiguration,
|
||||
appTokenProvider?: IAppTokenProvider
|
||||
) {
|
||||
super(configuration);
|
||||
this.appTokenProvider = appTokenProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Public API to acquire a token with ClientCredential Flow for Confidential clients
|
||||
* @param request - CommonClientCredentialRequest provided by the developer
|
||||
*/
|
||||
public async acquireToken(
|
||||
request: CommonClientCredentialRequest
|
||||
): Promise<AuthenticationResult | null> {
|
||||
if (request.skipCache || request.claims) {
|
||||
return this.executeTokenRequest(request, this.authority);
|
||||
}
|
||||
|
||||
const [cachedAuthenticationResult, lastCacheOutcome] =
|
||||
await this.getCachedAuthenticationResult(
|
||||
request,
|
||||
this.config,
|
||||
this.cryptoUtils,
|
||||
this.authority,
|
||||
this.cacheManager,
|
||||
this.serverTelemetryManager
|
||||
);
|
||||
|
||||
if (cachedAuthenticationResult) {
|
||||
// if the token is not expired but must be refreshed; get a new one in the background
|
||||
if (
|
||||
lastCacheOutcome ===
|
||||
Constants.CacheOutcome.PROACTIVELY_REFRESHED
|
||||
) {
|
||||
this.logger.info(
|
||||
"ClientCredentialClient:getCachedAuthenticationResult - Cached access token's refreshOn property has been exceeded'. It's not expired, but must be refreshed.",
|
||||
request.correlationId
|
||||
);
|
||||
|
||||
// refresh the access token in the background
|
||||
const refreshAccessToken = true;
|
||||
await this.executeTokenRequest(
|
||||
request,
|
||||
this.authority,
|
||||
refreshAccessToken
|
||||
);
|
||||
}
|
||||
|
||||
// return the cached token
|
||||
return cachedAuthenticationResult;
|
||||
} else {
|
||||
return this.executeTokenRequest(request, this.authority);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* looks up cache if the tokens are cached already
|
||||
*/
|
||||
public async getCachedAuthenticationResult(
|
||||
request: CommonClientCredentialRequest,
|
||||
config: ClientConfiguration | ManagedIdentityConfiguration,
|
||||
cryptoUtils: ICrypto,
|
||||
authority: Authority,
|
||||
cacheManager: CacheManager,
|
||||
serverTelemetryManager?: ServerTelemetryManager | null
|
||||
): Promise<[AuthenticationResult | null, Constants.CacheOutcome]> {
|
||||
const clientConfiguration = config as ClientConfiguration;
|
||||
const managedIdentityConfiguration =
|
||||
config as ManagedIdentityNodeConfiguration;
|
||||
|
||||
let lastCacheOutcome: Constants.CacheOutcome =
|
||||
Constants.CacheOutcome.NOT_APPLICABLE;
|
||||
|
||||
// read the user-supplied cache into memory, if applicable
|
||||
let cacheContext;
|
||||
if (
|
||||
clientConfiguration.serializableCache &&
|
||||
clientConfiguration.persistencePlugin
|
||||
) {
|
||||
cacheContext = new TokenCacheContext(
|
||||
clientConfiguration.serializableCache,
|
||||
false
|
||||
);
|
||||
await clientConfiguration.persistencePlugin.beforeCacheAccess(
|
||||
cacheContext
|
||||
);
|
||||
}
|
||||
|
||||
const cachedAccessToken = this.readAccessTokenFromCache(
|
||||
authority,
|
||||
managedIdentityConfiguration.managedIdentityId?.id ||
|
||||
clientConfiguration.authOptions.clientId,
|
||||
new ScopeSet(request.scopes || []),
|
||||
cacheManager,
|
||||
request.correlationId
|
||||
);
|
||||
|
||||
if (
|
||||
clientConfiguration.serializableCache &&
|
||||
clientConfiguration.persistencePlugin &&
|
||||
cacheContext
|
||||
) {
|
||||
await clientConfiguration.persistencePlugin.afterCacheAccess(
|
||||
cacheContext
|
||||
);
|
||||
}
|
||||
|
||||
// must refresh due to non-existent access_token
|
||||
if (!cachedAccessToken) {
|
||||
serverTelemetryManager?.setCacheOutcome(
|
||||
Constants.CacheOutcome.NO_CACHED_ACCESS_TOKEN
|
||||
);
|
||||
return [null, Constants.CacheOutcome.NO_CACHED_ACCESS_TOKEN];
|
||||
}
|
||||
|
||||
// must refresh due to the expires_in value
|
||||
if (
|
||||
TimeUtils.isTokenExpired(
|
||||
cachedAccessToken.expiresOn,
|
||||
clientConfiguration.systemOptions?.tokenRenewalOffsetSeconds ||
|
||||
Constants.DEFAULT_TOKEN_RENEWAL_OFFSET_SEC
|
||||
)
|
||||
) {
|
||||
serverTelemetryManager?.setCacheOutcome(
|
||||
Constants.CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED
|
||||
);
|
||||
return [null, Constants.CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED];
|
||||
}
|
||||
|
||||
// must refresh (in the background) due to the refresh_in value
|
||||
if (
|
||||
cachedAccessToken.refreshOn &&
|
||||
TimeUtils.isTokenExpired(cachedAccessToken.refreshOn.toString(), 0)
|
||||
) {
|
||||
lastCacheOutcome = Constants.CacheOutcome.PROACTIVELY_REFRESHED;
|
||||
serverTelemetryManager?.setCacheOutcome(
|
||||
Constants.CacheOutcome.PROACTIVELY_REFRESHED
|
||||
);
|
||||
}
|
||||
|
||||
return [
|
||||
await ResponseHandler.generateAuthenticationResult(
|
||||
cryptoUtils,
|
||||
authority,
|
||||
{
|
||||
account: null,
|
||||
idToken: null,
|
||||
accessToken: cachedAccessToken,
|
||||
refreshToken: null,
|
||||
appMetadata: null,
|
||||
},
|
||||
true,
|
||||
request,
|
||||
this.performanceClient
|
||||
),
|
||||
lastCacheOutcome,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads access token from the cache
|
||||
*/
|
||||
private readAccessTokenFromCache(
|
||||
authority: Authority,
|
||||
id: string,
|
||||
scopeSet: ScopeSet,
|
||||
cacheManager: CacheManager,
|
||||
correlationId: string
|
||||
): AccessTokenEntity | null {
|
||||
const accessTokenFilter: CredentialFilter = {
|
||||
homeAccountId: "",
|
||||
environment:
|
||||
authority.canonicalAuthorityUrlComponents.HostNameAndPort,
|
||||
credentialType: Constants.CredentialType.ACCESS_TOKEN,
|
||||
clientId: id,
|
||||
realm: authority.tenant,
|
||||
target: ScopeSet.createSearchScopes(scopeSet.asArray()),
|
||||
};
|
||||
|
||||
const accessTokens = cacheManager.getAccessTokensByFilter(
|
||||
accessTokenFilter,
|
||||
correlationId
|
||||
);
|
||||
if (accessTokens.length < 1) {
|
||||
return null;
|
||||
} else if (accessTokens.length > 1) {
|
||||
throw createClientAuthError(
|
||||
ClientAuthErrorCodes.multipleMatchingTokens
|
||||
);
|
||||
}
|
||||
return accessTokens[0] as AccessTokenEntity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes a network call to request the token from the service
|
||||
* @param request - CommonClientCredentialRequest provided by the developer
|
||||
* @param authority - authority object
|
||||
*/
|
||||
private async executeTokenRequest(
|
||||
request: CommonClientCredentialRequest,
|
||||
authority: Authority,
|
||||
refreshAccessToken?: boolean
|
||||
): Promise<AuthenticationResult | null> {
|
||||
let serverTokenResponse: ServerAuthorizationTokenResponse;
|
||||
let reqTimestamp: number;
|
||||
|
||||
if (this.appTokenProvider) {
|
||||
this.logger.info(
|
||||
"Using appTokenProvider extensibility.",
|
||||
request.correlationId
|
||||
);
|
||||
|
||||
const appTokenPropviderParameters = {
|
||||
correlationId: request.correlationId,
|
||||
tenantId: this.config.authOptions.authority.tenant,
|
||||
scopes: request.scopes,
|
||||
claims: request.claims,
|
||||
};
|
||||
|
||||
reqTimestamp = TimeUtils.nowSeconds();
|
||||
const appTokenProviderResult = await this.appTokenProvider(
|
||||
appTokenPropviderParameters
|
||||
);
|
||||
|
||||
serverTokenResponse = {
|
||||
access_token: appTokenProviderResult.accessToken,
|
||||
expires_in: appTokenProviderResult.expiresInSeconds,
|
||||
refresh_in: appTokenProviderResult.refreshInSeconds,
|
||||
token_type: Constants.AuthenticationScheme.BEARER,
|
||||
};
|
||||
} else {
|
||||
const queryParametersString =
|
||||
this.createTokenQueryParameters(request);
|
||||
const endpoint = UrlString.appendQueryString(
|
||||
authority.tokenEndpoint,
|
||||
queryParametersString
|
||||
);
|
||||
|
||||
const requestBody = await this.createTokenRequestBody(request);
|
||||
const headers: Record<string, string> =
|
||||
this.createTokenRequestHeaders();
|
||||
const thumbprint: RequestThumbprint = {
|
||||
clientId: this.config.authOptions.clientId,
|
||||
authority: request.authority,
|
||||
scopes: request.scopes,
|
||||
claims: request.claims,
|
||||
authenticationScheme: request.authenticationScheme,
|
||||
resourceRequestMethod: request.resourceRequestMethod,
|
||||
resourceRequestUri: request.resourceRequestUri,
|
||||
shrClaims: request.shrClaims,
|
||||
sshKid: request.sshKid,
|
||||
};
|
||||
|
||||
this.logger.info(
|
||||
"Sending token request to endpoint: " + authority.tokenEndpoint,
|
||||
request.correlationId
|
||||
);
|
||||
|
||||
reqTimestamp = TimeUtils.nowSeconds();
|
||||
const response = await this.executePostToTokenEndpoint(
|
||||
endpoint,
|
||||
requestBody,
|
||||
headers,
|
||||
thumbprint,
|
||||
request.correlationId
|
||||
);
|
||||
|
||||
serverTokenResponse = response.body;
|
||||
serverTokenResponse.status = response.status;
|
||||
}
|
||||
|
||||
const responseHandler = new ResponseHandler(
|
||||
this.config.authOptions.clientId,
|
||||
this.cacheManager,
|
||||
this.cryptoUtils,
|
||||
this.logger,
|
||||
this.performanceClient,
|
||||
this.config.serializableCache,
|
||||
this.config.persistencePlugin
|
||||
);
|
||||
|
||||
responseHandler.validateTokenResponse(
|
||||
serverTokenResponse,
|
||||
request.correlationId,
|
||||
refreshAccessToken
|
||||
);
|
||||
|
||||
const tokenResponse = await responseHandler.handleServerTokenResponse(
|
||||
serverTokenResponse,
|
||||
this.authority,
|
||||
reqTimestamp,
|
||||
request,
|
||||
ApiId.acquireTokenByClientCredential
|
||||
);
|
||||
|
||||
return tokenResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* generate the request to the server in the acceptable format
|
||||
* @param request - CommonClientCredentialRequest provided by the developer
|
||||
*/
|
||||
private async createTokenRequestBody(
|
||||
request: CommonClientCredentialRequest
|
||||
): Promise<string> {
|
||||
const parameters = new Map<string, string>();
|
||||
|
||||
RequestParameterBuilder.addClientId(
|
||||
parameters,
|
||||
this.config.authOptions.clientId
|
||||
);
|
||||
|
||||
RequestParameterBuilder.addScopes(parameters, request.scopes, false);
|
||||
|
||||
RequestParameterBuilder.addGrantType(
|
||||
parameters,
|
||||
Constants.GrantType.CLIENT_CREDENTIALS_GRANT
|
||||
);
|
||||
|
||||
RequestParameterBuilder.addLibraryInfo(
|
||||
parameters,
|
||||
this.config.libraryInfo
|
||||
);
|
||||
RequestParameterBuilder.addApplicationTelemetry(
|
||||
parameters,
|
||||
this.config.telemetry.application
|
||||
);
|
||||
|
||||
RequestParameterBuilder.addThrottling(parameters);
|
||||
|
||||
if (this.serverTelemetryManager) {
|
||||
RequestParameterBuilder.addServerTelemetry(
|
||||
parameters,
|
||||
this.serverTelemetryManager
|
||||
);
|
||||
}
|
||||
|
||||
const correlationId =
|
||||
request.correlationId ||
|
||||
this.config.cryptoInterface.createNewGuid();
|
||||
RequestParameterBuilder.addCorrelationId(parameters, correlationId);
|
||||
|
||||
if (this.config.clientCredentials.clientSecret) {
|
||||
RequestParameterBuilder.addClientSecret(
|
||||
parameters,
|
||||
this.config.clientCredentials.clientSecret
|
||||
);
|
||||
}
|
||||
|
||||
// Use clientAssertion from request, fallback to client assertion in base configuration
|
||||
const clientAssertion: ClientAssertion | undefined =
|
||||
request.clientAssertion ||
|
||||
this.config.clientCredentials.clientAssertion;
|
||||
|
||||
if (clientAssertion) {
|
||||
RequestParameterBuilder.addClientAssertion(
|
||||
parameters,
|
||||
await getClientAssertion(
|
||||
clientAssertion.assertion,
|
||||
this.config.authOptions.clientId,
|
||||
request.resourceRequestUri
|
||||
)
|
||||
);
|
||||
RequestParameterBuilder.addClientAssertionType(
|
||||
parameters,
|
||||
clientAssertion.assertionType
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
!StringUtils.isEmptyObj(request.claims) ||
|
||||
(this.config.authOptions.clientCapabilities &&
|
||||
this.config.authOptions.clientCapabilities.length > 0)
|
||||
) {
|
||||
RequestParameterBuilder.addClaims(
|
||||
parameters,
|
||||
request.claims,
|
||||
this.config.authOptions.clientCapabilities
|
||||
);
|
||||
}
|
||||
|
||||
return UrlUtils.mapToQueryString(parameters);
|
||||
}
|
||||
}
|
||||
303
backend/node_modules/@azure/msal-node/src/client/ConfidentialClientApplication.ts
generated
vendored
Normal file
303
backend/node_modules/@azure/msal-node/src/client/ConfidentialClientApplication.ts
generated
vendored
Normal file
@ -0,0 +1,303 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
// AADAuthorityConstants
|
||||
|
||||
import { ClientApplication } from "./ClientApplication.js";
|
||||
import { Configuration } from "../config/Configuration.js";
|
||||
import { ClientAssertion } from "./ClientAssertion.js";
|
||||
import {
|
||||
Constants as NodeConstants,
|
||||
ApiId,
|
||||
REGION_ENVIRONMENT_VARIABLE,
|
||||
MSAL_FORCE_REGION,
|
||||
} from "../utils/Constants.js";
|
||||
import {
|
||||
AuthenticationResult,
|
||||
AzureRegionConfiguration,
|
||||
AuthError,
|
||||
IAppTokenProvider,
|
||||
Constants,
|
||||
UrlString,
|
||||
createClientAuthError,
|
||||
ClientAssertion as ClientAssertionType,
|
||||
getClientAssertion,
|
||||
AzureRegion,
|
||||
} from "@azure/msal-common/node";
|
||||
import { IConfidentialClientApplication } from "./IConfidentialClientApplication.js";
|
||||
import { OnBehalfOfRequest } from "../request/OnBehalfOfRequest.js";
|
||||
import { CommonOnBehalfOfRequest } from "../request/CommonOnBehalfOfRequest.js";
|
||||
import { CommonClientCredentialRequest } from "../request/CommonClientCredentialRequest.js";
|
||||
import { ClientCredentialRequest } from "../request/ClientCredentialRequest.js";
|
||||
import { ClientCredentialClient } from "./ClientCredentialClient.js";
|
||||
import { OnBehalfOfClient } from "./OnBehalfOfClient.js";
|
||||
import * as NodeClientAuthErrorCodes from "../error/ClientAuthErrorCodes.js";
|
||||
|
||||
/**
|
||||
* This class is to be used to acquire tokens for confidential client applications (webApp, webAPI). Confidential client applications
|
||||
* will configure application secrets, client certificates/assertions as applicable
|
||||
* @public
|
||||
*/
|
||||
export class ConfidentialClientApplication
|
||||
extends ClientApplication
|
||||
implements IConfidentialClientApplication
|
||||
{
|
||||
private appTokenProvider?: IAppTokenProvider;
|
||||
|
||||
/**
|
||||
* Constructor for the ConfidentialClientApplication
|
||||
*
|
||||
* Required attributes in the Configuration object are:
|
||||
* - clientID: the application ID of your application. You can obtain one by registering your application with our application registration portal
|
||||
* - authority: the authority URL for your application.
|
||||
* - client credential: Must set either client secret, certificate, or assertion for confidential clients. You can obtain a client secret from the application registration portal.
|
||||
*
|
||||
* In Azure AD, authority is a URL indicating of the form https://login.microsoftonline.com/\{Enter_the_Tenant_Info_Here\}.
|
||||
* If your application supports Accounts in one organizational directory, replace "Enter_the_Tenant_Info_Here" value with the Tenant Id or Tenant name (for example, contoso.microsoft.com).
|
||||
* If your application supports Accounts in any organizational directory, replace "Enter_the_Tenant_Info_Here" value with organizations.
|
||||
* If your application supports Accounts in any organizational directory and personal Microsoft accounts, replace "Enter_the_Tenant_Info_Here" value with common.
|
||||
* To restrict support to Personal Microsoft accounts only, replace "Enter_the_Tenant_Info_Here" value with consumers.
|
||||
*
|
||||
* In Azure B2C, authority is of the form https://\{instance\}/tfp/\{tenant\}/\{policyName\}/
|
||||
* Full B2C functionality will be available in this library in future versions.
|
||||
*
|
||||
* @param Configuration - configuration object for the MSAL ConfidentialClientApplication instance
|
||||
*/
|
||||
constructor(configuration: Configuration) {
|
||||
super(configuration);
|
||||
|
||||
const clientSecretNotEmpty = !!this.config.auth.clientSecret;
|
||||
const clientAssertionNotEmpty = !!this.config.auth.clientAssertion;
|
||||
const certificateNotEmpty =
|
||||
(!!this.config.auth.clientCertificate?.thumbprint ||
|
||||
!!this.config.auth.clientCertificate?.thumbprintSha256) &&
|
||||
!!this.config.auth.clientCertificate?.privateKey;
|
||||
|
||||
/*
|
||||
* If app developer configures this callback, they don't need a credential
|
||||
* i.e. AzureSDK can get token from Managed Identity without a cert / secret
|
||||
*/
|
||||
if (this.appTokenProvider) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check that at most one credential is set on the application
|
||||
if (
|
||||
(clientSecretNotEmpty && clientAssertionNotEmpty) ||
|
||||
(clientAssertionNotEmpty && certificateNotEmpty) ||
|
||||
(clientSecretNotEmpty && certificateNotEmpty)
|
||||
) {
|
||||
throw createClientAuthError(
|
||||
NodeClientAuthErrorCodes.invalidClientCredential
|
||||
);
|
||||
}
|
||||
|
||||
if (this.config.auth.clientSecret) {
|
||||
this.clientSecret = this.config.auth.clientSecret;
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.config.auth.clientAssertion) {
|
||||
this.developerProvidedClientAssertion =
|
||||
this.config.auth.clientAssertion;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!certificateNotEmpty) {
|
||||
throw createClientAuthError(
|
||||
NodeClientAuthErrorCodes.invalidClientCredential
|
||||
);
|
||||
} else {
|
||||
this.clientAssertion = !!this.config.auth.clientCertificate
|
||||
.thumbprintSha256
|
||||
? ClientAssertion.fromCertificateWithSha256Thumbprint(
|
||||
this.config.auth.clientCertificate.thumbprintSha256,
|
||||
this.config.auth.clientCertificate.privateKey,
|
||||
this.config.auth.clientCertificate.x5c
|
||||
)
|
||||
: ClientAssertion.fromCertificate(
|
||||
// guaranteed to be a string, due to prior error checking in this function
|
||||
this.config.auth.clientCertificate.thumbprint as string,
|
||||
this.config.auth.clientCertificate.privateKey,
|
||||
this.config.auth.clientCertificate.x5c
|
||||
);
|
||||
}
|
||||
this.appTokenProvider = undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* This extensibility point only works for the client_credential flow, i.e. acquireTokenByClientCredential and
|
||||
* is meant for Azure SDK to enhance Managed Identity support.
|
||||
*
|
||||
* @param IAppTokenProvider - Extensibility interface, which allows the app developer to return a token from a custom source.
|
||||
*/
|
||||
SetAppTokenProvider(provider: IAppTokenProvider): void {
|
||||
this.appTokenProvider = provider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Acquires tokens from the authority for the application (not for an end user).
|
||||
*/
|
||||
public async acquireTokenByClientCredential(
|
||||
request: ClientCredentialRequest
|
||||
): Promise<AuthenticationResult | null> {
|
||||
this.logger.info(
|
||||
"acquireTokenByClientCredential called",
|
||||
request.correlationId || ""
|
||||
);
|
||||
|
||||
// If there is a client assertion present in the request, it overrides the one present in the client configuration
|
||||
let clientAssertion: ClientAssertionType | undefined;
|
||||
if (request.clientAssertion) {
|
||||
clientAssertion = {
|
||||
assertion: await getClientAssertion(
|
||||
request.clientAssertion,
|
||||
this.config.auth.clientId
|
||||
// tokenEndpoint will be undefined. resourceRequestUri is omitted in ClientCredentialRequest
|
||||
),
|
||||
assertionType: NodeConstants.JWT_BEARER_ASSERTION_TYPE,
|
||||
};
|
||||
}
|
||||
|
||||
const baseRequest = await this.initializeBaseRequest(request);
|
||||
|
||||
// valid base request should not contain oidc scopes in this grant type
|
||||
const validBaseRequest = {
|
||||
...baseRequest,
|
||||
scopes: baseRequest.scopes.filter(
|
||||
(scope: string) =>
|
||||
!Constants.OIDC_DEFAULT_SCOPES.includes(scope)
|
||||
),
|
||||
};
|
||||
|
||||
const validRequest: CommonClientCredentialRequest = {
|
||||
...request,
|
||||
...validBaseRequest,
|
||||
clientAssertion,
|
||||
};
|
||||
|
||||
/*
|
||||
* valid request should not have "common" or "organizations" in lieu of the tenant_id in the authority in the auth configuration
|
||||
* example authority: "https://login.microsoftonline.com/TenantId",
|
||||
*/
|
||||
const authority = new UrlString(validRequest.authority);
|
||||
const tenantId = authority.getUrlComponents().PathSegments[0];
|
||||
if (
|
||||
Object.values(Constants.AADAuthority).includes(
|
||||
tenantId as Constants.AADAuthority
|
||||
)
|
||||
) {
|
||||
throw createClientAuthError(
|
||||
NodeClientAuthErrorCodes.missingTenantIdError
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
* if this env variable is set, and the developer provided region isn't defined and isn't "DisableMsalForceRegion",
|
||||
* MSAL shall opt-in to ESTS-R with the value of this variable
|
||||
*/
|
||||
const ENV_MSAL_FORCE_REGION: AzureRegion | undefined =
|
||||
process.env[MSAL_FORCE_REGION];
|
||||
|
||||
let region: AzureRegion | undefined;
|
||||
if (validRequest.azureRegion !== "DisableMsalForceRegion") {
|
||||
if (!validRequest.azureRegion && ENV_MSAL_FORCE_REGION) {
|
||||
region = ENV_MSAL_FORCE_REGION;
|
||||
} else {
|
||||
region = validRequest.azureRegion;
|
||||
}
|
||||
}
|
||||
|
||||
const azureRegionConfiguration: AzureRegionConfiguration = {
|
||||
azureRegion: region,
|
||||
environmentRegion: process.env[REGION_ENVIRONMENT_VARIABLE],
|
||||
};
|
||||
|
||||
const serverTelemetryManager = this.initializeServerTelemetryManager(
|
||||
ApiId.acquireTokenByClientCredential,
|
||||
validRequest.correlationId,
|
||||
validRequest.skipCache
|
||||
);
|
||||
try {
|
||||
const discoveredAuthority = await this.createAuthority(
|
||||
validRequest.authority,
|
||||
validRequest.correlationId,
|
||||
azureRegionConfiguration,
|
||||
request.azureCloudOptions
|
||||
);
|
||||
const clientCredentialConfig =
|
||||
await this.buildOauthClientConfiguration(
|
||||
discoveredAuthority,
|
||||
validRequest.correlationId,
|
||||
"",
|
||||
serverTelemetryManager
|
||||
);
|
||||
const clientCredentialClient = new ClientCredentialClient(
|
||||
clientCredentialConfig,
|
||||
this.appTokenProvider
|
||||
);
|
||||
this.logger.verbose(
|
||||
"Client credential client created",
|
||||
validRequest.correlationId
|
||||
);
|
||||
return await clientCredentialClient.acquireToken(validRequest);
|
||||
} catch (e) {
|
||||
if (e instanceof AuthError) {
|
||||
e.setCorrelationId(validRequest.correlationId);
|
||||
}
|
||||
serverTelemetryManager.cacheFailedRequest(e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Acquires tokens from the authority for the application.
|
||||
*
|
||||
* Used in scenarios where the current app is a middle-tier service which was called with a token
|
||||
* representing an end user. The current app can use the token (oboAssertion) to request another
|
||||
* token to access downstream web API, on behalf of that user.
|
||||
*
|
||||
* The current middle-tier app has no user interaction to obtain consent.
|
||||
* See how to gain consent upfront for your middle-tier app from this article.
|
||||
* https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-on-behalf-of-flow#gaining-consent-for-the-middle-tier-application
|
||||
*/
|
||||
public async acquireTokenOnBehalfOf(
|
||||
request: OnBehalfOfRequest
|
||||
): Promise<AuthenticationResult | null> {
|
||||
this.logger.info(
|
||||
"acquireTokenOnBehalfOf called",
|
||||
request.correlationId || ""
|
||||
);
|
||||
const validRequest: CommonOnBehalfOfRequest = {
|
||||
...request,
|
||||
...(await this.initializeBaseRequest(request)),
|
||||
};
|
||||
try {
|
||||
const discoveredAuthority = await this.createAuthority(
|
||||
validRequest.authority,
|
||||
validRequest.correlationId,
|
||||
undefined,
|
||||
request.azureCloudOptions
|
||||
);
|
||||
const onBehalfOfConfig = await this.buildOauthClientConfiguration(
|
||||
discoveredAuthority,
|
||||
validRequest.correlationId,
|
||||
"",
|
||||
undefined
|
||||
);
|
||||
const oboClient = new OnBehalfOfClient(onBehalfOfConfig);
|
||||
this.logger.verbose(
|
||||
"On behalf of client created",
|
||||
validRequest.correlationId
|
||||
);
|
||||
return await oboClient.acquireToken(validRequest);
|
||||
} catch (e) {
|
||||
if (e instanceof AuthError) {
|
||||
e.setCorrelationId(validRequest.correlationId);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
414
backend/node_modules/@azure/msal-node/src/client/DeviceCodeClient.ts
generated
vendored
Normal file
414
backend/node_modules/@azure/msal-node/src/client/DeviceCodeClient.ts
generated
vendored
Normal file
@ -0,0 +1,414 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import {
|
||||
AuthErrorCodes,
|
||||
AuthenticationResult,
|
||||
ClientConfiguration,
|
||||
DeviceCodeResponse,
|
||||
RequestParameterBuilder,
|
||||
RequestThumbprint,
|
||||
ResponseHandler,
|
||||
ServerAuthorizationTokenResponse,
|
||||
ServerDeviceCodeResponse,
|
||||
StringUtils,
|
||||
TimeUtils,
|
||||
UrlString,
|
||||
UrlUtils,
|
||||
createAuthError,
|
||||
createClientAuthError,
|
||||
Constants,
|
||||
} from "@azure/msal-common/node";
|
||||
import { ApiId } from "../utils/Constants.js";
|
||||
import { CommonDeviceCodeRequest } from "../request/CommonDeviceCodeRequest.js";
|
||||
import * as NodeClientAuthErrorCodes from "../error/ClientAuthErrorCodes.js";
|
||||
import { BaseClient } from "./BaseClient.js";
|
||||
|
||||
/**
|
||||
* OAuth2.0 Device code client
|
||||
* @public
|
||||
*/
|
||||
export class DeviceCodeClient extends BaseClient {
|
||||
constructor(configuration: ClientConfiguration) {
|
||||
super(configuration);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets device code from device code endpoint, calls back to with device code response, and
|
||||
* polls token endpoint to exchange device code for tokens
|
||||
* @param request - developer provided CommonDeviceCodeRequest
|
||||
*/
|
||||
public async acquireToken(
|
||||
request: CommonDeviceCodeRequest
|
||||
): Promise<AuthenticationResult | null> {
|
||||
const deviceCodeResponse: DeviceCodeResponse = await this.getDeviceCode(
|
||||
request
|
||||
);
|
||||
request.deviceCodeCallback(deviceCodeResponse);
|
||||
const reqTimestamp = TimeUtils.nowSeconds();
|
||||
const response: ServerAuthorizationTokenResponse =
|
||||
await this.acquireTokenWithDeviceCode(request, deviceCodeResponse);
|
||||
|
||||
const responseHandler = new ResponseHandler(
|
||||
this.config.authOptions.clientId,
|
||||
this.cacheManager,
|
||||
this.cryptoUtils,
|
||||
this.logger,
|
||||
this.performanceClient,
|
||||
this.config.serializableCache,
|
||||
this.config.persistencePlugin
|
||||
);
|
||||
|
||||
// Validate response. This function throws a server error if an error is returned by the server.
|
||||
responseHandler.validateTokenResponse(response, request.correlationId);
|
||||
return responseHandler.handleServerTokenResponse(
|
||||
response,
|
||||
this.authority,
|
||||
reqTimestamp,
|
||||
request,
|
||||
ApiId.acquireTokenByDeviceCode
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates device code request and executes http GET
|
||||
* @param request - developer provided CommonDeviceCodeRequest
|
||||
*/
|
||||
private async getDeviceCode(
|
||||
request: CommonDeviceCodeRequest
|
||||
): Promise<DeviceCodeResponse> {
|
||||
const queryParametersString = this.createExtraQueryParameters(request);
|
||||
const endpoint = UrlString.appendQueryString(
|
||||
this.authority.deviceCodeEndpoint,
|
||||
queryParametersString
|
||||
);
|
||||
const queryString = this.createQueryString(request);
|
||||
const headers = this.createTokenRequestHeaders();
|
||||
const thumbprint: RequestThumbprint = {
|
||||
clientId: this.config.authOptions.clientId,
|
||||
authority: request.authority,
|
||||
scopes: request.scopes,
|
||||
claims: request.claims,
|
||||
authenticationScheme: request.authenticationScheme,
|
||||
resourceRequestMethod: request.resourceRequestMethod,
|
||||
resourceRequestUri: request.resourceRequestUri,
|
||||
shrClaims: request.shrClaims,
|
||||
sshKid: request.sshKid,
|
||||
};
|
||||
|
||||
return this.executePostRequestToDeviceCodeEndpoint(
|
||||
endpoint,
|
||||
queryString,
|
||||
headers,
|
||||
thumbprint,
|
||||
request.correlationId
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates query string for the device code request
|
||||
* @param request - developer provided CommonDeviceCodeRequest
|
||||
*/
|
||||
public createExtraQueryParameters(
|
||||
request: CommonDeviceCodeRequest
|
||||
): string {
|
||||
const parameters = new Map<string, string>();
|
||||
|
||||
if (request.extraQueryParameters) {
|
||||
RequestParameterBuilder.addExtraParameters(
|
||||
parameters,
|
||||
request.extraQueryParameters
|
||||
);
|
||||
}
|
||||
|
||||
return UrlUtils.mapToQueryString(parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes POST request to device code endpoint
|
||||
* @param deviceCodeEndpoint - token endpoint
|
||||
* @param queryString - string to be used in the body of the request
|
||||
* @param headers - headers for the request
|
||||
* @param thumbprint - unique request thumbprint
|
||||
* @param correlationId - correlation id to be used in the request
|
||||
*/
|
||||
private async executePostRequestToDeviceCodeEndpoint(
|
||||
deviceCodeEndpoint: string,
|
||||
queryString: string,
|
||||
headers: Record<string, string>,
|
||||
thumbprint: RequestThumbprint,
|
||||
correlationId: string
|
||||
): Promise<DeviceCodeResponse> {
|
||||
const {
|
||||
body: {
|
||||
user_code: userCode,
|
||||
device_code: deviceCode,
|
||||
verification_uri: verificationUri,
|
||||
expires_in: expiresIn,
|
||||
interval,
|
||||
message,
|
||||
},
|
||||
} = await this.sendPostRequest<ServerDeviceCodeResponse>(
|
||||
thumbprint,
|
||||
deviceCodeEndpoint,
|
||||
{
|
||||
body: queryString,
|
||||
headers: headers,
|
||||
},
|
||||
correlationId
|
||||
);
|
||||
|
||||
return {
|
||||
userCode,
|
||||
deviceCode,
|
||||
verificationUri,
|
||||
expiresIn,
|
||||
interval,
|
||||
message,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Create device code endpoint query parameters and returns string
|
||||
* @param request - developer provided CommonDeviceCodeRequest
|
||||
*/
|
||||
private createQueryString(request: CommonDeviceCodeRequest): string {
|
||||
const parameters = new Map<string, string>();
|
||||
|
||||
RequestParameterBuilder.addScopes(parameters, request.scopes);
|
||||
RequestParameterBuilder.addClientId(
|
||||
parameters,
|
||||
this.config.authOptions.clientId
|
||||
);
|
||||
|
||||
if (request.extraQueryParameters) {
|
||||
RequestParameterBuilder.addExtraParameters(
|
||||
parameters,
|
||||
request.extraQueryParameters
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
request.claims ||
|
||||
(this.config.authOptions.clientCapabilities &&
|
||||
this.config.authOptions.clientCapabilities.length > 0)
|
||||
) {
|
||||
RequestParameterBuilder.addClaims(
|
||||
parameters,
|
||||
request.claims,
|
||||
this.config.authOptions.clientCapabilities
|
||||
);
|
||||
}
|
||||
|
||||
return UrlUtils.mapToQueryString(parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Breaks the polling with specific conditions
|
||||
* @param deviceCodeExpirationTime - expiration time for the device code request
|
||||
* @param userSpecifiedTimeout - developer provided timeout, to be compared against deviceCodeExpirationTime
|
||||
* @param userSpecifiedCancelFlag - boolean indicating the developer would like to cancel the request
|
||||
*/
|
||||
private continuePolling(
|
||||
deviceCodeExpirationTime: number,
|
||||
userSpecifiedTimeout?: number,
|
||||
userSpecifiedCancelFlag?: boolean
|
||||
): boolean {
|
||||
if (userSpecifiedCancelFlag) {
|
||||
this.logger.error(
|
||||
"Token request cancelled by setting DeviceCodeRequest.cancel = true",
|
||||
""
|
||||
);
|
||||
throw createClientAuthError(
|
||||
NodeClientAuthErrorCodes.deviceCodePollingCancelled
|
||||
);
|
||||
} else if (
|
||||
userSpecifiedTimeout &&
|
||||
userSpecifiedTimeout < deviceCodeExpirationTime &&
|
||||
TimeUtils.nowSeconds() > userSpecifiedTimeout
|
||||
) {
|
||||
this.logger.error(
|
||||
`User defined timeout for device code polling reached. The timeout was set for ${userSpecifiedTimeout}`,
|
||||
""
|
||||
);
|
||||
throw createClientAuthError(
|
||||
NodeClientAuthErrorCodes.userTimeoutReached
|
||||
);
|
||||
} else if (TimeUtils.nowSeconds() > deviceCodeExpirationTime) {
|
||||
if (userSpecifiedTimeout) {
|
||||
this.logger.verbose(
|
||||
`User specified timeout ignored as the device code has expired before the timeout elapsed. The user specified timeout was set for ${userSpecifiedTimeout}`,
|
||||
""
|
||||
);
|
||||
}
|
||||
this.logger.error(
|
||||
`Device code expired. Expiration time of device code was ${deviceCodeExpirationTime}`,
|
||||
""
|
||||
);
|
||||
throw createClientAuthError(
|
||||
NodeClientAuthErrorCodes.deviceCodeExpired
|
||||
);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates token request with device code response and polls token endpoint at interval set by the device code response
|
||||
* @param request - developer provided CommonDeviceCodeRequest
|
||||
* @param deviceCodeResponse - DeviceCodeResponse returned by the security token service device code endpoint
|
||||
*/
|
||||
private async acquireTokenWithDeviceCode(
|
||||
request: CommonDeviceCodeRequest,
|
||||
deviceCodeResponse: DeviceCodeResponse
|
||||
): Promise<ServerAuthorizationTokenResponse> {
|
||||
const queryParametersString = this.createTokenQueryParameters(request);
|
||||
const endpoint = UrlString.appendQueryString(
|
||||
this.authority.tokenEndpoint,
|
||||
queryParametersString
|
||||
);
|
||||
const requestBody = this.createTokenRequestBody(
|
||||
request,
|
||||
deviceCodeResponse
|
||||
);
|
||||
const headers: Record<string, string> =
|
||||
this.createTokenRequestHeaders();
|
||||
|
||||
const userSpecifiedTimeout = request.timeout
|
||||
? TimeUtils.nowSeconds() + request.timeout
|
||||
: undefined;
|
||||
const deviceCodeExpirationTime =
|
||||
TimeUtils.nowSeconds() + deviceCodeResponse.expiresIn;
|
||||
const pollingIntervalMilli = deviceCodeResponse.interval * 1000;
|
||||
|
||||
/*
|
||||
* Poll token endpoint while (device code is not expired AND operation has not been cancelled by
|
||||
* setting CancellationToken.cancel = true). POST request is sent at interval set by pollingIntervalMilli
|
||||
*/
|
||||
while (
|
||||
this.continuePolling(
|
||||
deviceCodeExpirationTime,
|
||||
userSpecifiedTimeout,
|
||||
request.cancel
|
||||
)
|
||||
) {
|
||||
const thumbprint: RequestThumbprint = {
|
||||
clientId: this.config.authOptions.clientId,
|
||||
authority: request.authority,
|
||||
scopes: request.scopes,
|
||||
claims: request.claims,
|
||||
authenticationScheme: request.authenticationScheme,
|
||||
resourceRequestMethod: request.resourceRequestMethod,
|
||||
resourceRequestUri: request.resourceRequestUri,
|
||||
shrClaims: request.shrClaims,
|
||||
sshKid: request.sshKid,
|
||||
};
|
||||
const response = await this.executePostToTokenEndpoint(
|
||||
endpoint,
|
||||
requestBody,
|
||||
headers,
|
||||
thumbprint,
|
||||
request.correlationId
|
||||
);
|
||||
|
||||
if (response.body && response.body.error) {
|
||||
// user authorization is pending. Sleep for polling interval and try again
|
||||
if (response.body.error === Constants.AUTHORIZATION_PENDING) {
|
||||
this.logger.info(
|
||||
"Authorization pending. Continue polling.",
|
||||
request.correlationId
|
||||
);
|
||||
await TimeUtils.delay(pollingIntervalMilli);
|
||||
} else {
|
||||
// for any other error, throw
|
||||
this.logger.info(
|
||||
"Unexpected error in polling from the server",
|
||||
request.correlationId
|
||||
);
|
||||
throw createAuthError(
|
||||
AuthErrorCodes.postRequestFailed,
|
||||
response.body.error
|
||||
);
|
||||
}
|
||||
} else {
|
||||
this.logger.verbose(
|
||||
"Authorization completed successfully. Polling stopped.",
|
||||
request.correlationId
|
||||
);
|
||||
return response.body;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* The above code should've thrown by this point, but to satisfy TypeScript,
|
||||
* and in the rare case the conditionals in continuePolling() may not catch everything...
|
||||
*/
|
||||
this.logger.error(
|
||||
"Polling stopped for unknown reasons.",
|
||||
request.correlationId
|
||||
);
|
||||
throw createClientAuthError(
|
||||
NodeClientAuthErrorCodes.deviceCodeUnknownError
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates query parameters and converts to string.
|
||||
* @param request - developer provided CommonDeviceCodeRequest
|
||||
* @param deviceCodeResponse - DeviceCodeResponse returned by the security token service device code endpoint
|
||||
*/
|
||||
private createTokenRequestBody(
|
||||
request: CommonDeviceCodeRequest,
|
||||
deviceCodeResponse: DeviceCodeResponse
|
||||
): string {
|
||||
const parameters = new Map<string, string>();
|
||||
|
||||
RequestParameterBuilder.addScopes(parameters, request.scopes);
|
||||
RequestParameterBuilder.addClientId(
|
||||
parameters,
|
||||
this.config.authOptions.clientId
|
||||
);
|
||||
RequestParameterBuilder.addGrantType(
|
||||
parameters,
|
||||
Constants.GrantType.DEVICE_CODE_GRANT
|
||||
);
|
||||
RequestParameterBuilder.addDeviceCode(
|
||||
parameters,
|
||||
deviceCodeResponse.deviceCode
|
||||
);
|
||||
const correlationId =
|
||||
request.correlationId ||
|
||||
this.config.cryptoInterface.createNewGuid();
|
||||
RequestParameterBuilder.addCorrelationId(parameters, correlationId);
|
||||
RequestParameterBuilder.addClientInfo(parameters);
|
||||
RequestParameterBuilder.addLibraryInfo(
|
||||
parameters,
|
||||
this.config.libraryInfo
|
||||
);
|
||||
RequestParameterBuilder.addApplicationTelemetry(
|
||||
parameters,
|
||||
this.config.telemetry.application
|
||||
);
|
||||
RequestParameterBuilder.addThrottling(parameters);
|
||||
if (this.serverTelemetryManager) {
|
||||
RequestParameterBuilder.addServerTelemetry(
|
||||
parameters,
|
||||
this.serverTelemetryManager
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
!StringUtils.isEmptyObj(request.claims) ||
|
||||
(this.config.authOptions.clientCapabilities &&
|
||||
this.config.authOptions.clientCapabilities.length > 0)
|
||||
) {
|
||||
RequestParameterBuilder.addClaims(
|
||||
parameters,
|
||||
request.claims,
|
||||
this.config.authOptions.clientCapabilities
|
||||
);
|
||||
}
|
||||
return UrlUtils.mapToQueryString(parameters);
|
||||
}
|
||||
}
|
||||
75
backend/node_modules/@azure/msal-node/src/client/IConfidentialClientApplication.ts
generated
vendored
Normal file
75
backend/node_modules/@azure/msal-node/src/client/IConfidentialClientApplication.ts
generated
vendored
Normal file
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import {
|
||||
AuthenticationResult,
|
||||
IAppTokenProvider,
|
||||
Logger,
|
||||
} from "@azure/msal-common/node";
|
||||
import { AuthorizationCodeRequest } from "../request/AuthorizationCodeRequest.js";
|
||||
import { AuthorizationUrlRequest } from "../request/AuthorizationUrlRequest.js";
|
||||
import { ClientCredentialRequest } from "../request/ClientCredentialRequest.js";
|
||||
import { OnBehalfOfRequest } from "../request/OnBehalfOfRequest.js";
|
||||
import { RefreshTokenRequest } from "../request/RefreshTokenRequest.js";
|
||||
import { SilentFlowRequest } from "../request/SilentFlowRequest.js";
|
||||
import { UsernamePasswordRequest } from "../request/UsernamePasswordRequest.js";
|
||||
import { TokenCache } from "../cache/TokenCache.js";
|
||||
|
||||
/**
|
||||
* Interface for the ConfidentialClientApplication class defining the public API signatures
|
||||
* @public
|
||||
*/
|
||||
export interface IConfidentialClientApplication {
|
||||
/** Creates the URL of the authorization request */
|
||||
getAuthCodeUrl(request: AuthorizationUrlRequest): Promise<string>;
|
||||
|
||||
/** Acquires a token by exchanging the authorization code received from the first step of OAuth 2.0 Authorization Code Flow */
|
||||
acquireTokenByCode(
|
||||
request: AuthorizationCodeRequest
|
||||
): Promise<AuthenticationResult>;
|
||||
|
||||
/** Acquires a token silently when a user specifies the account the token is requested for */
|
||||
acquireTokenSilent(
|
||||
request: SilentFlowRequest
|
||||
): Promise<AuthenticationResult | null>;
|
||||
|
||||
/** Acquires a token by exchanging the refresh token provided for a new set of tokens */
|
||||
acquireTokenByRefreshToken(
|
||||
request: RefreshTokenRequest
|
||||
): Promise<AuthenticationResult | null>;
|
||||
|
||||
/** Acquires tokens from the authority for the application (not for an end user) */
|
||||
acquireTokenByClientCredential(
|
||||
request: ClientCredentialRequest
|
||||
): Promise<AuthenticationResult | null>;
|
||||
|
||||
/** Acquires tokens from the authority for the application */
|
||||
acquireTokenOnBehalfOf(
|
||||
request: OnBehalfOfRequest
|
||||
): Promise<AuthenticationResult | null>;
|
||||
|
||||
/**
|
||||
* Acquires tokens with password grant by exchanging client applications username and password for credentials
|
||||
* @deprecated - Use a more secure flow instead
|
||||
*/
|
||||
acquireTokenByUsernamePassword(
|
||||
request: UsernamePasswordRequest
|
||||
): Promise<AuthenticationResult | null>;
|
||||
|
||||
/** Gets the token cache for the application */
|
||||
getTokenCache(): TokenCache;
|
||||
|
||||
/** Returns the logger instance */
|
||||
getLogger(): Logger;
|
||||
|
||||
/** Replaces the default logger set in configurations with new Logger with new configurations */
|
||||
setLogger(logger: Logger): void;
|
||||
|
||||
/** Clear the cache except for authority metadata. */
|
||||
clearCache(): void;
|
||||
|
||||
/** This extensibility point is meant for Azure SDK to enhance Managed Identity support */
|
||||
SetAppTokenProvider(provider: IAppTokenProvider): void;
|
||||
}
|
||||
79
backend/node_modules/@azure/msal-node/src/client/IPublicClientApplication.ts
generated
vendored
Normal file
79
backend/node_modules/@azure/msal-node/src/client/IPublicClientApplication.ts
generated
vendored
Normal file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import {
|
||||
AccountInfo,
|
||||
AuthenticationResult,
|
||||
Logger,
|
||||
} from "@azure/msal-common/node";
|
||||
import { AuthorizationCodeRequest } from "../request/AuthorizationCodeRequest.js";
|
||||
import { AuthorizationUrlRequest } from "../request/AuthorizationUrlRequest.js";
|
||||
import { DeviceCodeRequest } from "../request/DeviceCodeRequest.js";
|
||||
import { RefreshTokenRequest } from "../request/RefreshTokenRequest.js";
|
||||
import { SilentFlowRequest } from "../request/SilentFlowRequest.js";
|
||||
import { UsernamePasswordRequest } from "../request/UsernamePasswordRequest.js";
|
||||
import { TokenCache } from "../cache/TokenCache.js";
|
||||
import { InteractiveRequest } from "../request/InteractiveRequest.js";
|
||||
import { SignOutRequest } from "../request/SignOutRequest.js";
|
||||
|
||||
/**
|
||||
* Interface for the PublicClientApplication class defining the public API signatures
|
||||
* @public
|
||||
*/
|
||||
export interface IPublicClientApplication {
|
||||
/** Creates the URL of the authorization request */
|
||||
getAuthCodeUrl(request: AuthorizationUrlRequest): Promise<string>;
|
||||
|
||||
/** Acquires a token by exchanging the authorization code received from the first step of OAuth 2.0 Authorization Code Flow */
|
||||
acquireTokenByCode(
|
||||
request: AuthorizationCodeRequest
|
||||
): Promise<AuthenticationResult>;
|
||||
|
||||
/** Acquires a token interactively */
|
||||
acquireTokenInteractive(
|
||||
request: InteractiveRequest
|
||||
): Promise<AuthenticationResult>;
|
||||
|
||||
/** Acquires a token silently when a user specifies the account the token is requested for */
|
||||
acquireTokenSilent(
|
||||
request: SilentFlowRequest
|
||||
): Promise<AuthenticationResult>;
|
||||
|
||||
/** Acquires a token by exchanging the refresh token provided for a new set of tokens */
|
||||
acquireTokenByRefreshToken(
|
||||
request: RefreshTokenRequest
|
||||
): Promise<AuthenticationResult | null>;
|
||||
|
||||
/** Acquires a token from the authority using OAuth2.0 device code flow */
|
||||
acquireTokenByDeviceCode(
|
||||
request: DeviceCodeRequest
|
||||
): Promise<AuthenticationResult | null>;
|
||||
|
||||
/**
|
||||
* Acquires tokens with password grant by exchanging client applications username and password for credentials
|
||||
* @deprecated - Use a more secure flow instead
|
||||
*/
|
||||
acquireTokenByUsernamePassword(
|
||||
request: UsernamePasswordRequest
|
||||
): Promise<AuthenticationResult | null>;
|
||||
|
||||
/** Gets the token cache for the application */
|
||||
getTokenCache(): TokenCache;
|
||||
|
||||
/** Returns the logger instance */
|
||||
getLogger(): Logger;
|
||||
|
||||
/** Replaces the default logger set in configurations with new Logger with new configurations */
|
||||
setLogger(logger: Logger): void;
|
||||
|
||||
/** Clear the cache except for authority metadata, which is not included in the serialized cache and would otherwise be lost. */
|
||||
clearCache(): void;
|
||||
|
||||
/** Gets all cached accounts */
|
||||
getAllAccounts(): Promise<AccountInfo[]>;
|
||||
|
||||
/** Removes cache artifacts associated with the given account */
|
||||
signOut(request: SignOutRequest): Promise<void>;
|
||||
}
|
||||
269
backend/node_modules/@azure/msal-node/src/client/ManagedIdentityApplication.ts
generated
vendored
Normal file
269
backend/node_modules/@azure/msal-node/src/client/ManagedIdentityApplication.ts
generated
vendored
Normal file
@ -0,0 +1,269 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import {
|
||||
AuthOptions,
|
||||
Authority,
|
||||
AuthorityOptions,
|
||||
ClientConfiguration,
|
||||
DEFAULT_CRYPTO_IMPLEMENTATION,
|
||||
INetworkModule,
|
||||
Logger,
|
||||
ProtocolMode,
|
||||
StaticAuthorityOptions,
|
||||
AuthenticationResult,
|
||||
createClientConfigurationError,
|
||||
ClientConfigurationErrorCodes,
|
||||
Constants,
|
||||
StubPerformanceClient,
|
||||
} from "@azure/msal-common/node";
|
||||
import {
|
||||
ManagedIdentityConfiguration,
|
||||
ManagedIdentityNodeConfiguration,
|
||||
buildManagedIdentityConfiguration,
|
||||
} from "../config/Configuration.js";
|
||||
import { version, name } from "../packageMetadata.js";
|
||||
import { ManagedIdentityRequest } from "../request/ManagedIdentityRequest.js";
|
||||
import { CryptoProvider } from "../crypto/CryptoProvider.js";
|
||||
import { ClientCredentialClient } from "./ClientCredentialClient.js";
|
||||
import { ManagedIdentityClient } from "./ManagedIdentityClient.js";
|
||||
import { ManagedIdentityRequestParams } from "../request/ManagedIdentityRequestParams.js";
|
||||
import { NodeStorage } from "../cache/NodeStorage.js";
|
||||
import {
|
||||
DEFAULT_AUTHORITY_FOR_MANAGED_IDENTITY,
|
||||
ManagedIdentitySourceNames,
|
||||
} from "../utils/Constants.js";
|
||||
import { ManagedIdentityId } from "../config/ManagedIdentityId.js";
|
||||
import { HashUtils } from "../crypto/HashUtils.js";
|
||||
|
||||
const SOURCES_THAT_SUPPORT_TOKEN_REVOCATION: Array<ManagedIdentitySourceNames> =
|
||||
[ManagedIdentitySourceNames.SERVICE_FABRIC];
|
||||
|
||||
/**
|
||||
* Class to initialize a managed identity and identify the service
|
||||
* @public
|
||||
*/
|
||||
export class ManagedIdentityApplication {
|
||||
private config: ManagedIdentityNodeConfiguration;
|
||||
|
||||
private logger: Logger;
|
||||
private static nodeStorage?: NodeStorage;
|
||||
private networkClient: INetworkModule;
|
||||
private cryptoProvider: CryptoProvider;
|
||||
|
||||
// authority needs to be faked to re-use existing functionality in msal-common: caching in responseHandler, etc.
|
||||
private fakeAuthority: Authority;
|
||||
|
||||
// the ClientCredentialClient class needs to be faked to call it's getCachedAuthenticationResult method
|
||||
private fakeClientCredentialClient: ClientCredentialClient;
|
||||
|
||||
private managedIdentityClient: ManagedIdentityClient;
|
||||
|
||||
private hashUtils: HashUtils;
|
||||
|
||||
constructor(configuration?: ManagedIdentityConfiguration) {
|
||||
// undefined config means the managed identity is system-assigned
|
||||
this.config = buildManagedIdentityConfiguration(configuration || {});
|
||||
|
||||
this.logger = new Logger(
|
||||
this.config.system.loggerOptions,
|
||||
name,
|
||||
version
|
||||
);
|
||||
|
||||
const fakeStatusAuthorityOptions: StaticAuthorityOptions = {
|
||||
canonicalAuthority: Constants.DEFAULT_AUTHORITY,
|
||||
};
|
||||
|
||||
if (!ManagedIdentityApplication.nodeStorage) {
|
||||
ManagedIdentityApplication.nodeStorage = new NodeStorage(
|
||||
this.logger,
|
||||
this.config.managedIdentityId.id,
|
||||
DEFAULT_CRYPTO_IMPLEMENTATION,
|
||||
fakeStatusAuthorityOptions
|
||||
);
|
||||
}
|
||||
|
||||
this.networkClient = this.config.system.networkClient;
|
||||
|
||||
this.cryptoProvider = new CryptoProvider();
|
||||
|
||||
const fakeAuthorityOptions: AuthorityOptions = {
|
||||
protocolMode: ProtocolMode.AAD,
|
||||
knownAuthorities: [DEFAULT_AUTHORITY_FOR_MANAGED_IDENTITY],
|
||||
cloudDiscoveryMetadata: "",
|
||||
authorityMetadata: "",
|
||||
};
|
||||
this.fakeAuthority = new Authority(
|
||||
DEFAULT_AUTHORITY_FOR_MANAGED_IDENTITY,
|
||||
this.networkClient,
|
||||
ManagedIdentityApplication.nodeStorage as NodeStorage,
|
||||
fakeAuthorityOptions,
|
||||
this.logger,
|
||||
this.cryptoProvider.createNewGuid(), // correlationID
|
||||
new StubPerformanceClient(),
|
||||
true
|
||||
);
|
||||
|
||||
this.fakeClientCredentialClient = new ClientCredentialClient({
|
||||
authOptions: {
|
||||
clientId: this.config.managedIdentityId.id,
|
||||
authority: this.fakeAuthority,
|
||||
} as AuthOptions,
|
||||
} as ClientConfiguration);
|
||||
|
||||
this.managedIdentityClient = new ManagedIdentityClient(
|
||||
this.logger,
|
||||
ManagedIdentityApplication.nodeStorage as NodeStorage,
|
||||
this.networkClient,
|
||||
this.cryptoProvider,
|
||||
this.config.disableInternalRetries
|
||||
);
|
||||
|
||||
this.hashUtils = new HashUtils();
|
||||
}
|
||||
|
||||
/**
|
||||
* Acquire an access token from the cache or the managed identity
|
||||
* @param managedIdentityRequest - the ManagedIdentityRequestParams object passed in by the developer
|
||||
* @returns the access token
|
||||
*/
|
||||
public async acquireToken(
|
||||
managedIdentityRequestParams: ManagedIdentityRequestParams
|
||||
): Promise<AuthenticationResult> {
|
||||
if (!managedIdentityRequestParams.resource) {
|
||||
throw createClientConfigurationError(
|
||||
ClientConfigurationErrorCodes.urlEmptyError
|
||||
);
|
||||
}
|
||||
|
||||
const managedIdentityRequest: ManagedIdentityRequest = {
|
||||
forceRefresh: managedIdentityRequestParams.forceRefresh,
|
||||
resource: managedIdentityRequestParams.resource.replace(
|
||||
"/.default",
|
||||
""
|
||||
),
|
||||
scopes: [
|
||||
managedIdentityRequestParams.resource.replace("/.default", ""),
|
||||
],
|
||||
authority: this.fakeAuthority.canonicalAuthority,
|
||||
correlationId: this.cryptoProvider.createNewGuid(),
|
||||
claims: managedIdentityRequestParams.claims,
|
||||
clientCapabilities: this.config.clientCapabilities,
|
||||
};
|
||||
|
||||
if (managedIdentityRequest.forceRefresh) {
|
||||
return this.acquireTokenFromManagedIdentity(
|
||||
managedIdentityRequest,
|
||||
this.config.managedIdentityId,
|
||||
this.fakeAuthority
|
||||
);
|
||||
}
|
||||
|
||||
const [cachedAuthenticationResult, lastCacheOutcome] =
|
||||
await this.fakeClientCredentialClient.getCachedAuthenticationResult(
|
||||
managedIdentityRequest,
|
||||
this.config,
|
||||
this.cryptoProvider,
|
||||
this.fakeAuthority,
|
||||
ManagedIdentityApplication.nodeStorage as NodeStorage
|
||||
);
|
||||
|
||||
/*
|
||||
* Check if claims are present in the managed identity request.
|
||||
* If so, the cached token will not be used.
|
||||
*/
|
||||
if (managedIdentityRequest.claims) {
|
||||
const sourceName: ManagedIdentitySourceNames =
|
||||
this.managedIdentityClient.getManagedIdentitySource();
|
||||
|
||||
/*
|
||||
* Check if there is a cached token and if the Managed Identity source supports token revocation.
|
||||
* If so, hash the cached access token and add it to the request.
|
||||
*/
|
||||
if (
|
||||
cachedAuthenticationResult &&
|
||||
SOURCES_THAT_SUPPORT_TOKEN_REVOCATION.includes(sourceName)
|
||||
) {
|
||||
const revokedTokenSha256Hash: string = this.hashUtils
|
||||
.sha256(cachedAuthenticationResult.accessToken)
|
||||
.toString(Constants.EncodingTypes.HEX);
|
||||
managedIdentityRequest.revokedTokenSha256Hash =
|
||||
revokedTokenSha256Hash;
|
||||
}
|
||||
|
||||
return this.acquireTokenFromManagedIdentity(
|
||||
managedIdentityRequest,
|
||||
this.config.managedIdentityId,
|
||||
this.fakeAuthority
|
||||
);
|
||||
}
|
||||
|
||||
if (cachedAuthenticationResult) {
|
||||
// if the token is not expired but must be refreshed; get a new one in the background
|
||||
if (
|
||||
lastCacheOutcome ===
|
||||
Constants.CacheOutcome.PROACTIVELY_REFRESHED
|
||||
) {
|
||||
this.logger.info(
|
||||
"ClientCredentialClient:getCachedAuthenticationResult - Cached access token's refreshOn property has been exceeded'. It's not expired, but must be refreshed.",
|
||||
managedIdentityRequest.correlationId
|
||||
);
|
||||
|
||||
// force refresh; will run in the background
|
||||
const refreshAccessToken = true;
|
||||
await this.acquireTokenFromManagedIdentity(
|
||||
managedIdentityRequest,
|
||||
this.config.managedIdentityId,
|
||||
this.fakeAuthority,
|
||||
refreshAccessToken
|
||||
);
|
||||
}
|
||||
|
||||
return cachedAuthenticationResult;
|
||||
} else {
|
||||
return this.acquireTokenFromManagedIdentity(
|
||||
managedIdentityRequest,
|
||||
this.config.managedIdentityId,
|
||||
this.fakeAuthority
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Acquires a token from a managed identity endpoint.
|
||||
*
|
||||
* @param managedIdentityRequest - The request object containing parameters for the managed identity token request.
|
||||
* @param managedIdentityId - The identifier for the managed identity (e.g., client ID or resource ID).
|
||||
* @param fakeAuthority - A placeholder authority used for the token request.
|
||||
* @param refreshAccessToken - Optional flag indicating whether to force a refresh of the access token.
|
||||
* @returns A promise that resolves to an AuthenticationResult containing the acquired token and related information.
|
||||
*/
|
||||
private async acquireTokenFromManagedIdentity(
|
||||
managedIdentityRequest: ManagedIdentityRequest,
|
||||
managedIdentityId: ManagedIdentityId,
|
||||
fakeAuthority: Authority,
|
||||
refreshAccessToken?: boolean
|
||||
): Promise<AuthenticationResult> {
|
||||
// make a network call to the managed identity
|
||||
return this.managedIdentityClient.sendManagedIdentityTokenRequest(
|
||||
managedIdentityRequest,
|
||||
managedIdentityId,
|
||||
fakeAuthority,
|
||||
refreshAccessToken
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the Managed Identity Source based on available environment variables. This API is consumed by Azure Identity SDK.
|
||||
* @returns ManagedIdentitySourceNames - The Managed Identity source's name
|
||||
*/
|
||||
public getManagedIdentitySource(): ManagedIdentitySourceNames {
|
||||
return (
|
||||
ManagedIdentityClient.sourceName ||
|
||||
this.managedIdentityClient.getManagedIdentitySource()
|
||||
);
|
||||
}
|
||||
}
|
||||
189
backend/node_modules/@azure/msal-node/src/client/ManagedIdentityClient.ts
generated
vendored
Normal file
189
backend/node_modules/@azure/msal-node/src/client/ManagedIdentityClient.ts
generated
vendored
Normal file
@ -0,0 +1,189 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import {
|
||||
Authority,
|
||||
INetworkModule,
|
||||
Logger,
|
||||
AuthenticationResult,
|
||||
} from "@azure/msal-common/node";
|
||||
import { AppService } from "./ManagedIdentitySources/AppService.js";
|
||||
import { AzureArc } from "./ManagedIdentitySources/AzureArc.js";
|
||||
import { CloudShell } from "./ManagedIdentitySources/CloudShell.js";
|
||||
import { Imds } from "./ManagedIdentitySources/Imds.js";
|
||||
import { ServiceFabric } from "./ManagedIdentitySources/ServiceFabric.js";
|
||||
import { CryptoProvider } from "../crypto/CryptoProvider.js";
|
||||
import {
|
||||
ManagedIdentityErrorCodes,
|
||||
createManagedIdentityError,
|
||||
} from "../error/ManagedIdentityError.js";
|
||||
import { ManagedIdentityRequest } from "../request/ManagedIdentityRequest.js";
|
||||
import { ManagedIdentityId } from "../config/ManagedIdentityId.js";
|
||||
import { NodeStorage } from "../cache/NodeStorage.js";
|
||||
import { BaseManagedIdentitySource } from "./ManagedIdentitySources/BaseManagedIdentitySource.js";
|
||||
import { ManagedIdentitySourceNames } from "../utils/Constants.js";
|
||||
import { MachineLearning } from "./ManagedIdentitySources/MachineLearning.js";
|
||||
|
||||
/*
|
||||
* Class to initialize a managed identity and identify the service.
|
||||
* Original source of code: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/src/ManagedIdentityClient.cs
|
||||
*/
|
||||
export class ManagedIdentityClient {
|
||||
private logger: Logger;
|
||||
private nodeStorage: NodeStorage;
|
||||
private networkClient: INetworkModule;
|
||||
private cryptoProvider: CryptoProvider;
|
||||
private disableInternalRetries: boolean;
|
||||
|
||||
private static identitySource?: BaseManagedIdentitySource;
|
||||
public static sourceName?: ManagedIdentitySourceNames;
|
||||
|
||||
constructor(
|
||||
logger: Logger,
|
||||
nodeStorage: NodeStorage,
|
||||
networkClient: INetworkModule,
|
||||
cryptoProvider: CryptoProvider,
|
||||
disableInternalRetries: boolean
|
||||
) {
|
||||
this.logger = logger;
|
||||
this.nodeStorage = nodeStorage;
|
||||
this.networkClient = networkClient;
|
||||
this.cryptoProvider = cryptoProvider;
|
||||
this.disableInternalRetries = disableInternalRetries;
|
||||
}
|
||||
|
||||
public async sendManagedIdentityTokenRequest(
|
||||
managedIdentityRequest: ManagedIdentityRequest,
|
||||
managedIdentityId: ManagedIdentityId,
|
||||
fakeAuthority: Authority,
|
||||
refreshAccessToken?: boolean
|
||||
): Promise<AuthenticationResult> {
|
||||
if (!ManagedIdentityClient.identitySource) {
|
||||
ManagedIdentityClient.identitySource =
|
||||
this.selectManagedIdentitySource(
|
||||
this.logger,
|
||||
this.nodeStorage,
|
||||
this.networkClient,
|
||||
this.cryptoProvider,
|
||||
this.disableInternalRetries,
|
||||
managedIdentityId
|
||||
);
|
||||
}
|
||||
|
||||
return ManagedIdentityClient.identitySource.acquireTokenWithManagedIdentity(
|
||||
managedIdentityRequest,
|
||||
managedIdentityId,
|
||||
fakeAuthority,
|
||||
refreshAccessToken
|
||||
);
|
||||
}
|
||||
|
||||
private allEnvironmentVariablesAreDefined(
|
||||
environmentVariables: Array<string | undefined>
|
||||
): boolean {
|
||||
return Object.values(environmentVariables).every(
|
||||
(environmentVariable) => {
|
||||
return environmentVariable !== undefined;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the Managed Identity Source based on available environment variables. This API is consumed by ManagedIdentityApplication's getManagedIdentitySource.
|
||||
* @returns ManagedIdentitySourceNames - The Managed Identity source's name
|
||||
*/
|
||||
public getManagedIdentitySource(): ManagedIdentitySourceNames {
|
||||
ManagedIdentityClient.sourceName =
|
||||
this.allEnvironmentVariablesAreDefined(
|
||||
ServiceFabric.getEnvironmentVariables()
|
||||
)
|
||||
? ManagedIdentitySourceNames.SERVICE_FABRIC
|
||||
: this.allEnvironmentVariablesAreDefined(
|
||||
AppService.getEnvironmentVariables()
|
||||
)
|
||||
? ManagedIdentitySourceNames.APP_SERVICE
|
||||
: this.allEnvironmentVariablesAreDefined(
|
||||
MachineLearning.getEnvironmentVariables()
|
||||
)
|
||||
? ManagedIdentitySourceNames.MACHINE_LEARNING
|
||||
: this.allEnvironmentVariablesAreDefined(
|
||||
CloudShell.getEnvironmentVariables()
|
||||
)
|
||||
? ManagedIdentitySourceNames.CLOUD_SHELL
|
||||
: this.allEnvironmentVariablesAreDefined(
|
||||
AzureArc.getEnvironmentVariables()
|
||||
)
|
||||
? ManagedIdentitySourceNames.AZURE_ARC
|
||||
: ManagedIdentitySourceNames.DEFAULT_TO_IMDS;
|
||||
|
||||
return ManagedIdentityClient.sourceName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to create a managed identity source for all sources
|
||||
* @returns the managed identity Source
|
||||
*/
|
||||
private selectManagedIdentitySource(
|
||||
logger: Logger,
|
||||
nodeStorage: NodeStorage,
|
||||
networkClient: INetworkModule,
|
||||
cryptoProvider: CryptoProvider,
|
||||
disableInternalRetries: boolean,
|
||||
managedIdentityId: ManagedIdentityId
|
||||
): BaseManagedIdentitySource {
|
||||
const source =
|
||||
ServiceFabric.tryCreate(
|
||||
logger,
|
||||
nodeStorage,
|
||||
networkClient,
|
||||
cryptoProvider,
|
||||
disableInternalRetries,
|
||||
managedIdentityId
|
||||
) ||
|
||||
AppService.tryCreate(
|
||||
logger,
|
||||
nodeStorage,
|
||||
networkClient,
|
||||
cryptoProvider,
|
||||
disableInternalRetries
|
||||
) ||
|
||||
MachineLearning.tryCreate(
|
||||
logger,
|
||||
nodeStorage,
|
||||
networkClient,
|
||||
cryptoProvider,
|
||||
disableInternalRetries
|
||||
) ||
|
||||
CloudShell.tryCreate(
|
||||
logger,
|
||||
nodeStorage,
|
||||
networkClient,
|
||||
cryptoProvider,
|
||||
disableInternalRetries,
|
||||
managedIdentityId
|
||||
) ||
|
||||
AzureArc.tryCreate(
|
||||
logger,
|
||||
nodeStorage,
|
||||
networkClient,
|
||||
cryptoProvider,
|
||||
disableInternalRetries,
|
||||
managedIdentityId
|
||||
) ||
|
||||
Imds.tryCreate(
|
||||
logger,
|
||||
nodeStorage,
|
||||
networkClient,
|
||||
cryptoProvider,
|
||||
disableInternalRetries
|
||||
);
|
||||
if (!source) {
|
||||
throw createManagedIdentityError(
|
||||
ManagedIdentityErrorCodes.unableToCreateSource
|
||||
);
|
||||
}
|
||||
return source;
|
||||
}
|
||||
}
|
||||
194
backend/node_modules/@azure/msal-node/src/client/ManagedIdentitySources/AppService.ts
generated
vendored
Normal file
194
backend/node_modules/@azure/msal-node/src/client/ManagedIdentitySources/AppService.ts
generated
vendored
Normal file
@ -0,0 +1,194 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import { INetworkModule, Logger } from "@azure/msal-common/node";
|
||||
import { BaseManagedIdentitySource } from "./BaseManagedIdentitySource.js";
|
||||
import {
|
||||
HttpMethod,
|
||||
ManagedIdentityEnvironmentVariableNames,
|
||||
ManagedIdentitySourceNames,
|
||||
ManagedIdentityIdType,
|
||||
ManagedIdentityQueryParameters,
|
||||
ManagedIdentityHeaders,
|
||||
} from "../../utils/Constants.js";
|
||||
import { CryptoProvider } from "../../crypto/CryptoProvider.js";
|
||||
import { ManagedIdentityRequestParameters } from "../../config/ManagedIdentityRequestParameters.js";
|
||||
import { ManagedIdentityId } from "../../config/ManagedIdentityId.js";
|
||||
import { NodeStorage } from "../../cache/NodeStorage.js";
|
||||
|
||||
// MSI Constants. Docs for MSI are available here https://docs.microsoft.com/azure/app-service/overview-managed-identity
|
||||
const APP_SERVICE_MSI_API_VERSION: string = "2019-08-01";
|
||||
|
||||
/**
|
||||
* Azure App Service Managed Identity Source implementation.
|
||||
*
|
||||
* This class provides managed identity authentication for applications running in Azure App Service.
|
||||
* It uses the local metadata service endpoint available within App Service environments to obtain
|
||||
* access tokens without requiring explicit credentials.
|
||||
*
|
||||
* Original source of code: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/src/AppServiceManagedIdentitySource.cs
|
||||
*/
|
||||
export class AppService extends BaseManagedIdentitySource {
|
||||
private identityEndpoint: string;
|
||||
private identityHeader: string;
|
||||
|
||||
/**
|
||||
* Creates a new instance of the AppService managed identity source.
|
||||
*
|
||||
* @param logger - Logger instance for diagnostic output
|
||||
* @param nodeStorage - Node.js storage implementation for caching
|
||||
* @param networkClient - Network client for making HTTP requests
|
||||
* @param cryptoProvider - Cryptographic operations provider
|
||||
* @param disableInternalRetries - Whether to disable internal retry logic
|
||||
* @param identityEndpoint - The App Service identity endpoint URL
|
||||
* @param identityHeader - The secret header value required for authentication
|
||||
*/
|
||||
constructor(
|
||||
logger: Logger,
|
||||
nodeStorage: NodeStorage,
|
||||
networkClient: INetworkModule,
|
||||
cryptoProvider: CryptoProvider,
|
||||
disableInternalRetries: boolean,
|
||||
identityEndpoint: string,
|
||||
identityHeader: string
|
||||
) {
|
||||
super(
|
||||
logger,
|
||||
nodeStorage,
|
||||
networkClient,
|
||||
cryptoProvider,
|
||||
disableInternalRetries
|
||||
);
|
||||
|
||||
this.identityEndpoint = identityEndpoint;
|
||||
this.identityHeader = identityHeader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the required environment variables for App Service managed identity.
|
||||
*
|
||||
* App Service managed identity requires two environment variables:
|
||||
* - IDENTITY_ENDPOINT: The URL of the local metadata service
|
||||
* - IDENTITY_HEADER: A secret header value for authentication
|
||||
*
|
||||
* @returns An array containing [identityEndpoint, identityHeader] values from environment variables.
|
||||
* Either value may be undefined if the environment variable is not set.
|
||||
*/
|
||||
public static getEnvironmentVariables(): Array<string | undefined> {
|
||||
const identityEndpoint: string | undefined =
|
||||
process.env[
|
||||
ManagedIdentityEnvironmentVariableNames.IDENTITY_ENDPOINT
|
||||
];
|
||||
const identityHeader: string | undefined =
|
||||
process.env[
|
||||
ManagedIdentityEnvironmentVariableNames.IDENTITY_HEADER
|
||||
];
|
||||
|
||||
return [identityEndpoint, identityHeader];
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to create an AppService managed identity source if the environment supports it.
|
||||
*
|
||||
* This method checks for the presence of required environment variables and validates
|
||||
* the identity endpoint URL. If the environment is not suitable for App Service managed
|
||||
* identity (missing environment variables or invalid endpoint), it returns null.
|
||||
*
|
||||
* @param logger - Logger instance for diagnostic output
|
||||
* @param nodeStorage - Node.js storage implementation for caching
|
||||
* @param networkClient - Network client for making HTTP requests
|
||||
* @param cryptoProvider - Cryptographic operations provider
|
||||
* @param disableInternalRetries - Whether to disable internal retry logic
|
||||
*
|
||||
* @returns A new AppService instance if the environment is suitable, null otherwise
|
||||
*/
|
||||
public static tryCreate(
|
||||
logger: Logger,
|
||||
nodeStorage: NodeStorage,
|
||||
networkClient: INetworkModule,
|
||||
cryptoProvider: CryptoProvider,
|
||||
disableInternalRetries: boolean
|
||||
): AppService | null {
|
||||
const [identityEndpoint, identityHeader] =
|
||||
AppService.getEnvironmentVariables();
|
||||
|
||||
// if either of the identity endpoint or identity header variables are undefined, this MSI provider is unavailable.
|
||||
if (!identityEndpoint || !identityHeader) {
|
||||
logger.info(
|
||||
`[Managed Identity] ${ManagedIdentitySourceNames.APP_SERVICE} managed identity is unavailable because one or both of the '${ManagedIdentityEnvironmentVariableNames.IDENTITY_HEADER}' and '${ManagedIdentityEnvironmentVariableNames.IDENTITY_ENDPOINT}' environment variables are not defined.`,
|
||||
""
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
const validatedIdentityEndpoint: string =
|
||||
AppService.getValidatedEnvVariableUrlString(
|
||||
ManagedIdentityEnvironmentVariableNames.IDENTITY_ENDPOINT,
|
||||
identityEndpoint,
|
||||
ManagedIdentitySourceNames.APP_SERVICE,
|
||||
logger
|
||||
);
|
||||
|
||||
logger.info(
|
||||
`[Managed Identity] Environment variables validation passed for ${ManagedIdentitySourceNames.APP_SERVICE} managed identity. Endpoint URI: ${validatedIdentityEndpoint}. Creating ${ManagedIdentitySourceNames.APP_SERVICE} managed identity.`,
|
||||
""
|
||||
);
|
||||
|
||||
return new AppService(
|
||||
logger,
|
||||
nodeStorage,
|
||||
networkClient,
|
||||
cryptoProvider,
|
||||
disableInternalRetries,
|
||||
identityEndpoint,
|
||||
identityHeader
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a managed identity token request for the App Service environment.
|
||||
*
|
||||
* This method constructs an HTTP GET request to the App Service identity endpoint
|
||||
* with the required headers, query parameters, and managed identity configuration.
|
||||
* The request includes the secret header for authentication and appropriate API version.
|
||||
*
|
||||
* @param resource - The target resource/scope for which to request an access token (e.g., "https://graph.microsoft.com/.default")
|
||||
* @param managedIdentityId - The managed identity configuration specifying whether to use system-assigned or user-assigned identity
|
||||
*
|
||||
* @returns A configured ManagedIdentityRequestParameters object ready for network execution
|
||||
*/
|
||||
public createRequest(
|
||||
resource: string,
|
||||
managedIdentityId: ManagedIdentityId
|
||||
): ManagedIdentityRequestParameters {
|
||||
const request: ManagedIdentityRequestParameters =
|
||||
new ManagedIdentityRequestParameters(
|
||||
HttpMethod.GET,
|
||||
this.identityEndpoint
|
||||
);
|
||||
|
||||
request.headers[ManagedIdentityHeaders.APP_SERVICE_SECRET_HEADER_NAME] =
|
||||
this.identityHeader;
|
||||
|
||||
request.queryParameters[ManagedIdentityQueryParameters.API_VERSION] =
|
||||
APP_SERVICE_MSI_API_VERSION;
|
||||
request.queryParameters[ManagedIdentityQueryParameters.RESOURCE] =
|
||||
resource;
|
||||
|
||||
if (
|
||||
managedIdentityId.idType !== ManagedIdentityIdType.SYSTEM_ASSIGNED
|
||||
) {
|
||||
request.queryParameters[
|
||||
this.getManagedIdentityUserAssignedIdQueryParameterKey(
|
||||
managedIdentityId.idType
|
||||
)
|
||||
] = managedIdentityId.id;
|
||||
}
|
||||
|
||||
// bodyParameters calculated in BaseManagedIdentity.acquireTokenWithManagedIdentity
|
||||
|
||||
return request;
|
||||
}
|
||||
}
|
||||
415
backend/node_modules/@azure/msal-node/src/client/ManagedIdentitySources/AzureArc.ts
generated
vendored
Normal file
415
backend/node_modules/@azure/msal-node/src/client/ManagedIdentitySources/AzureArc.ts
generated
vendored
Normal file
@ -0,0 +1,415 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import {
|
||||
AuthError,
|
||||
ClientAuthErrorCodes,
|
||||
createClientAuthError,
|
||||
INetworkModule,
|
||||
NetworkResponse,
|
||||
NetworkRequestOptions,
|
||||
Logger,
|
||||
ServerAuthorizationTokenResponse,
|
||||
Constants,
|
||||
} from "@azure/msal-common/node";
|
||||
import { ManagedIdentityRequestParameters } from "../../config/ManagedIdentityRequestParameters.js";
|
||||
import { BaseManagedIdentitySource } from "./BaseManagedIdentitySource.js";
|
||||
import { CryptoProvider } from "../../crypto/CryptoProvider.js";
|
||||
import {
|
||||
ManagedIdentityErrorCodes,
|
||||
createManagedIdentityError,
|
||||
} from "../../error/ManagedIdentityError.js";
|
||||
import {
|
||||
AZURE_ARC_SECRET_FILE_MAX_SIZE_BYTES,
|
||||
HttpMethod,
|
||||
ManagedIdentityEnvironmentVariableNames,
|
||||
ManagedIdentityHeaders,
|
||||
ManagedIdentityIdType,
|
||||
ManagedIdentityQueryParameters,
|
||||
ManagedIdentitySourceNames,
|
||||
} from "../../utils/Constants.js";
|
||||
import { NodeStorage } from "../../cache/NodeStorage.js";
|
||||
import {
|
||||
accessSync,
|
||||
constants as fsConstants,
|
||||
readFileSync,
|
||||
statSync,
|
||||
} from "fs";
|
||||
import { ManagedIdentityTokenResponse } from "../../response/ManagedIdentityTokenResponse.js";
|
||||
import { ManagedIdentityId } from "../../config/ManagedIdentityId.js";
|
||||
import path from "path";
|
||||
|
||||
export const ARC_API_VERSION: string = "2019-11-01";
|
||||
export const DEFAULT_AZURE_ARC_IDENTITY_ENDPOINT: string =
|
||||
"http://127.0.0.1:40342/metadata/identity/oauth2/token";
|
||||
const HIMDS_EXECUTABLE_HELPER_STRING = "N/A: himds executable exists";
|
||||
|
||||
type FilePathMap = {
|
||||
win32: string;
|
||||
linux: string;
|
||||
};
|
||||
|
||||
export const SUPPORTED_AZURE_ARC_PLATFORMS: FilePathMap = {
|
||||
win32: `${process.env["ProgramData"]}\\AzureConnectedMachineAgent\\Tokens\\`,
|
||||
linux: "/var/opt/azcmagent/tokens/",
|
||||
};
|
||||
|
||||
export const AZURE_ARC_FILE_DETECTION: FilePathMap = {
|
||||
win32: `${process.env["ProgramFiles"]}\\AzureConnectedMachineAgent\\himds.exe`,
|
||||
linux: "/opt/azcmagent/bin/himds",
|
||||
};
|
||||
|
||||
/**
|
||||
* Azure Arc managed identity source implementation for acquiring tokens from Azure Arc-enabled servers.
|
||||
*
|
||||
* This class provides managed identity authentication for applications running on Azure Arc-enabled servers
|
||||
* by communicating with the local Hybrid Instance Metadata Service (HIMDS). It supports both environment
|
||||
* variable-based configuration and automatic detection through the HIMDS executable.
|
||||
*
|
||||
* Original source of code: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/src/AzureArcManagedIdentitySource.cs
|
||||
*/
|
||||
export class AzureArc extends BaseManagedIdentitySource {
|
||||
private identityEndpoint: string;
|
||||
|
||||
/**
|
||||
* Creates a new instance of the AzureArc managed identity source.
|
||||
*
|
||||
* @param logger - Logger instance for capturing telemetry and diagnostic information
|
||||
* @param nodeStorage - Storage implementation for caching tokens and metadata
|
||||
* @param networkClient - Network client for making HTTP requests to the identity endpoint
|
||||
* @param cryptoProvider - Cryptographic operations provider for token validation and encryption
|
||||
* @param disableInternalRetries - Flag to disable automatic retry logic for failed requests
|
||||
* @param identityEndpoint - The Azure Arc identity endpoint URL for token requests
|
||||
*/
|
||||
constructor(
|
||||
logger: Logger,
|
||||
nodeStorage: NodeStorage,
|
||||
networkClient: INetworkModule,
|
||||
cryptoProvider: CryptoProvider,
|
||||
disableInternalRetries: boolean,
|
||||
identityEndpoint: string
|
||||
) {
|
||||
super(
|
||||
logger,
|
||||
nodeStorage,
|
||||
networkClient,
|
||||
cryptoProvider,
|
||||
disableInternalRetries
|
||||
);
|
||||
|
||||
this.identityEndpoint = identityEndpoint;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves and validates Azure Arc environment variables for managed identity configuration.
|
||||
*
|
||||
* This method checks for IDENTITY_ENDPOINT and IMDS_ENDPOINT environment variables.
|
||||
* If either is missing, it attempts to detect the Azure Arc environment by checking for
|
||||
* the HIMDS executable at platform-specific paths. On successful detection, it returns
|
||||
* the default identity endpoint and a helper string indicating file-based detection.
|
||||
*
|
||||
* @returns An array containing [identityEndpoint, imdsEndpoint] where both values are
|
||||
* strings if Azure Arc is available, or undefined if not available.
|
||||
*/
|
||||
public static getEnvironmentVariables(): Array<string | undefined> {
|
||||
let identityEndpoint: string | undefined =
|
||||
process.env[
|
||||
ManagedIdentityEnvironmentVariableNames.IDENTITY_ENDPOINT
|
||||
];
|
||||
let imdsEndpoint: string | undefined =
|
||||
process.env[ManagedIdentityEnvironmentVariableNames.IMDS_ENDPOINT];
|
||||
|
||||
// if either of the identity or imds endpoints are undefined, check if the himds executable exists
|
||||
if (!identityEndpoint || !imdsEndpoint) {
|
||||
// get the expected Windows or Linux file path of the himds executable
|
||||
const fileDetectionPath: string =
|
||||
AZURE_ARC_FILE_DETECTION[process.platform as keyof FilePathMap];
|
||||
try {
|
||||
/*
|
||||
* check if the himds executable exists and its permissions allow it to be read
|
||||
* returns undefined if true, throws an error otherwise
|
||||
*/
|
||||
accessSync(
|
||||
fileDetectionPath,
|
||||
fsConstants.F_OK | fsConstants.R_OK
|
||||
);
|
||||
|
||||
identityEndpoint = DEFAULT_AZURE_ARC_IDENTITY_ENDPOINT;
|
||||
imdsEndpoint = HIMDS_EXECUTABLE_HELPER_STRING;
|
||||
} catch (err) {
|
||||
/*
|
||||
* do nothing
|
||||
* accessSync returns undefined on success, and throws an error on failure
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
return [identityEndpoint, imdsEndpoint];
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to create an AzureArc managed identity source instance.
|
||||
*
|
||||
* Validates the Azure Arc environment by checking environment variables
|
||||
* and performing file-based detection. It ensures that only system-assigned managed identities
|
||||
* are supported for Azure Arc scenarios. The method performs comprehensive validation of
|
||||
* endpoint URLs and logs detailed information about the detection process.
|
||||
*
|
||||
* @param logger - Logger instance for capturing creation and validation steps
|
||||
* @param nodeStorage - Storage implementation for the managed identity source
|
||||
* @param networkClient - Network client for HTTP communication
|
||||
* @param cryptoProvider - Cryptographic operations provider
|
||||
* @param disableInternalRetries - Whether to disable automatic retry mechanisms
|
||||
* @param managedIdentityId - The managed identity configuration, must be system-assigned
|
||||
*
|
||||
* @returns AzureArc instance if the environment supports Azure Arc managed identity, null otherwise
|
||||
*
|
||||
* @throws {ManagedIdentityError} When a user-assigned managed identity is specified (not supported for Azure Arc)
|
||||
*/
|
||||
public static tryCreate(
|
||||
logger: Logger,
|
||||
nodeStorage: NodeStorage,
|
||||
networkClient: INetworkModule,
|
||||
cryptoProvider: CryptoProvider,
|
||||
disableInternalRetries: boolean,
|
||||
managedIdentityId: ManagedIdentityId
|
||||
): AzureArc | null {
|
||||
const [identityEndpoint, imdsEndpoint] =
|
||||
AzureArc.getEnvironmentVariables();
|
||||
|
||||
// if either of the identity or imds endpoints are undefined (even after himds file detection)
|
||||
if (!identityEndpoint || !imdsEndpoint) {
|
||||
logger.info(
|
||||
`[Managed Identity] ${ManagedIdentitySourceNames.AZURE_ARC} managed identity is unavailable through environment variables because one or both of '${ManagedIdentityEnvironmentVariableNames.IDENTITY_ENDPOINT}' and '${ManagedIdentityEnvironmentVariableNames.IMDS_ENDPOINT}' are not defined. ${ManagedIdentitySourceNames.AZURE_ARC} managed identity is also unavailable through file detection.`,
|
||||
""
|
||||
);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// check if the imds endpoint is set to the default for file detection
|
||||
if (imdsEndpoint === HIMDS_EXECUTABLE_HELPER_STRING) {
|
||||
logger.info(
|
||||
`[Managed Identity] ${ManagedIdentitySourceNames.AZURE_ARC} managed identity is available through file detection. Defaulting to known ${ManagedIdentitySourceNames.AZURE_ARC} endpoint: ${DEFAULT_AZURE_ARC_IDENTITY_ENDPOINT}. Creating ${ManagedIdentitySourceNames.AZURE_ARC} managed identity.`,
|
||||
""
|
||||
);
|
||||
} else {
|
||||
// otherwise, both the identity and imds endpoints are defined without file detection; validate them
|
||||
|
||||
const validatedIdentityEndpoint: string =
|
||||
AzureArc.getValidatedEnvVariableUrlString(
|
||||
ManagedIdentityEnvironmentVariableNames.IDENTITY_ENDPOINT,
|
||||
identityEndpoint,
|
||||
ManagedIdentitySourceNames.AZURE_ARC,
|
||||
logger
|
||||
);
|
||||
// remove trailing slash
|
||||
validatedIdentityEndpoint.endsWith("/")
|
||||
? validatedIdentityEndpoint.slice(0, -1)
|
||||
: validatedIdentityEndpoint;
|
||||
|
||||
AzureArc.getValidatedEnvVariableUrlString(
|
||||
ManagedIdentityEnvironmentVariableNames.IMDS_ENDPOINT,
|
||||
imdsEndpoint,
|
||||
ManagedIdentitySourceNames.AZURE_ARC,
|
||||
logger
|
||||
);
|
||||
|
||||
logger.info(
|
||||
`[Managed Identity] Environment variables validation passed for ${ManagedIdentitySourceNames.AZURE_ARC} managed identity. Endpoint URI: ${validatedIdentityEndpoint}. Creating ${ManagedIdentitySourceNames.AZURE_ARC} managed identity.`,
|
||||
""
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
managedIdentityId.idType !== ManagedIdentityIdType.SYSTEM_ASSIGNED
|
||||
) {
|
||||
throw createManagedIdentityError(
|
||||
ManagedIdentityErrorCodes.unableToCreateAzureArc
|
||||
);
|
||||
}
|
||||
|
||||
return new AzureArc(
|
||||
logger,
|
||||
nodeStorage,
|
||||
networkClient,
|
||||
cryptoProvider,
|
||||
disableInternalRetries,
|
||||
identityEndpoint
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a properly formatted HTTP request for acquiring tokens from the Azure Arc identity endpoint.
|
||||
*
|
||||
* This method constructs a GET request to the Azure Arc HIMDS endpoint with the required metadata header
|
||||
* and query parameters. The endpoint URL is normalized to use 127.0.0.1 instead of localhost for
|
||||
* consistency. Additional body parameters are calculated by the base class during token acquisition.
|
||||
*
|
||||
* @param resource - The target resource/scope for which to request an access token (e.g., "https://graph.microsoft.com/.default")
|
||||
*
|
||||
* @returns A configured ManagedIdentityRequestParameters object ready for network execution
|
||||
*/
|
||||
public createRequest(resource: string): ManagedIdentityRequestParameters {
|
||||
const request: ManagedIdentityRequestParameters =
|
||||
new ManagedIdentityRequestParameters(
|
||||
HttpMethod.GET,
|
||||
this.identityEndpoint.replace("localhost", "127.0.0.1")
|
||||
);
|
||||
|
||||
request.headers[ManagedIdentityHeaders.METADATA_HEADER_NAME] = "true";
|
||||
|
||||
request.queryParameters[ManagedIdentityQueryParameters.API_VERSION] =
|
||||
ARC_API_VERSION;
|
||||
request.queryParameters[ManagedIdentityQueryParameters.RESOURCE] =
|
||||
resource;
|
||||
|
||||
// bodyParameters calculated in BaseManagedIdentity.acquireTokenWithManagedIdentity
|
||||
|
||||
return request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the server response and handles Azure Arc-specific authentication challenges.
|
||||
*
|
||||
* This method implements the Azure Arc authentication flow which may require reading a secret file
|
||||
* for authorization. When the initial request returns HTTP 401 Unauthorized, it extracts the file
|
||||
* path from the WWW-Authenticate header, validates the file location and size, reads the secret,
|
||||
* and retries the request with Basic authentication. The method includes comprehensive security
|
||||
* validations to prevent path traversal and ensure file integrity.
|
||||
*
|
||||
* @param originalResponse - The initial HTTP response from the identity endpoint
|
||||
* @param networkClient - Network client for making the retry request if needed
|
||||
* @param networkRequest - The original request parameters (modified with auth header for retry)
|
||||
* @param networkRequestOptions - Additional options for network requests
|
||||
*
|
||||
* @returns A promise that resolves to the server token response with access token and metadata
|
||||
*
|
||||
* @throws {ManagedIdentityError} When:
|
||||
* - WWW-Authenticate header is missing or has unsupported format
|
||||
* - Platform is not supported (not Windows or Linux)
|
||||
* - Secret file has invalid extension (not .key)
|
||||
* - Secret file path doesn't match expected platform path
|
||||
* - Secret file cannot be read or is too large (>4096 bytes)
|
||||
* @throws {ClientAuthError} When network errors occur during retry request
|
||||
*/
|
||||
public async getServerTokenResponseAsync(
|
||||
originalResponse: NetworkResponse<ManagedIdentityTokenResponse>,
|
||||
networkClient: INetworkModule,
|
||||
networkRequest: ManagedIdentityRequestParameters,
|
||||
networkRequestOptions: NetworkRequestOptions
|
||||
): Promise<ServerAuthorizationTokenResponse> {
|
||||
let retryResponse:
|
||||
| NetworkResponse<ManagedIdentityTokenResponse>
|
||||
| undefined;
|
||||
|
||||
if (originalResponse.status === Constants.HTTP_UNAUTHORIZED) {
|
||||
const wwwAuthHeader: string =
|
||||
originalResponse.headers["www-authenticate"];
|
||||
if (!wwwAuthHeader) {
|
||||
throw createManagedIdentityError(
|
||||
ManagedIdentityErrorCodes.wwwAuthenticateHeaderMissing
|
||||
);
|
||||
}
|
||||
if (!wwwAuthHeader.includes("Basic realm=")) {
|
||||
throw createManagedIdentityError(
|
||||
ManagedIdentityErrorCodes.wwwAuthenticateHeaderUnsupportedFormat
|
||||
);
|
||||
}
|
||||
|
||||
const secretFilePath = wwwAuthHeader.split("Basic realm=")[1];
|
||||
|
||||
// throw an error if the managed identity application is not being run on Windows or Linux
|
||||
if (
|
||||
!SUPPORTED_AZURE_ARC_PLATFORMS.hasOwnProperty(process.platform)
|
||||
) {
|
||||
throw createManagedIdentityError(
|
||||
ManagedIdentityErrorCodes.platformNotSupported
|
||||
);
|
||||
}
|
||||
|
||||
// get the expected Windows or Linux file path
|
||||
const expectedSecretFilePath: string =
|
||||
SUPPORTED_AZURE_ARC_PLATFORMS[
|
||||
process.platform as keyof FilePathMap
|
||||
];
|
||||
|
||||
// throw an error if the file in the file path is not a .key file
|
||||
const fileName: string = path.basename(secretFilePath);
|
||||
if (!fileName.endsWith(".key")) {
|
||||
throw createManagedIdentityError(
|
||||
ManagedIdentityErrorCodes.invalidFileExtension
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
* throw an error if the file path from the www-authenticate header does not match the
|
||||
* expected file path for the platform (Windows or Linux) the managed identity application
|
||||
* is running on
|
||||
*/
|
||||
if (expectedSecretFilePath + fileName !== secretFilePath) {
|
||||
throw createManagedIdentityError(
|
||||
ManagedIdentityErrorCodes.invalidFilePath
|
||||
);
|
||||
}
|
||||
|
||||
let secretFileSize;
|
||||
// attempt to get the secret file's size, in bytes
|
||||
try {
|
||||
secretFileSize = await statSync(secretFilePath).size;
|
||||
} catch (e) {
|
||||
throw createManagedIdentityError(
|
||||
ManagedIdentityErrorCodes.unableToReadSecretFile
|
||||
);
|
||||
}
|
||||
// throw an error if the secret file's size is greater than 4096 bytes
|
||||
if (secretFileSize > AZURE_ARC_SECRET_FILE_MAX_SIZE_BYTES) {
|
||||
throw createManagedIdentityError(
|
||||
ManagedIdentityErrorCodes.invalidSecret
|
||||
);
|
||||
}
|
||||
|
||||
// attempt to read the contents of the secret file
|
||||
let secret;
|
||||
try {
|
||||
secret = readFileSync(
|
||||
secretFilePath,
|
||||
Constants.EncodingTypes.UTF8
|
||||
);
|
||||
} catch (e) {
|
||||
throw createManagedIdentityError(
|
||||
ManagedIdentityErrorCodes.unableToReadSecretFile
|
||||
);
|
||||
}
|
||||
const authHeaderValue = `Basic ${secret}`;
|
||||
|
||||
this.logger.info(
|
||||
`[Managed Identity] Adding authorization header to the request.`,
|
||||
""
|
||||
);
|
||||
networkRequest.headers[
|
||||
ManagedIdentityHeaders.AUTHORIZATION_HEADER_NAME
|
||||
] = authHeaderValue;
|
||||
|
||||
try {
|
||||
retryResponse =
|
||||
await networkClient.sendGetRequestAsync<ManagedIdentityTokenResponse>(
|
||||
networkRequest.computeUri(),
|
||||
networkRequestOptions
|
||||
);
|
||||
} catch (error) {
|
||||
if (error instanceof AuthError) {
|
||||
throw error;
|
||||
} else {
|
||||
throw createClientAuthError(
|
||||
ClientAuthErrorCodes.networkError
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this.getServerTokenResponse(retryResponse || originalResponse);
|
||||
}
|
||||
}
|
||||
424
backend/node_modules/@azure/msal-node/src/client/ManagedIdentitySources/BaseManagedIdentitySource.ts
generated
vendored
Normal file
424
backend/node_modules/@azure/msal-node/src/client/ManagedIdentitySources/BaseManagedIdentitySource.ts
generated
vendored
Normal file
@ -0,0 +1,424 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import {
|
||||
AuthError,
|
||||
Authority,
|
||||
ClientAuthErrorCodes,
|
||||
INetworkModule,
|
||||
Logger,
|
||||
NetworkRequestOptions,
|
||||
NetworkResponse,
|
||||
ResponseHandler,
|
||||
ServerAuthorizationTokenResponse,
|
||||
TimeUtils,
|
||||
createClientAuthError,
|
||||
AuthenticationResult,
|
||||
UrlString,
|
||||
Constants,
|
||||
StubPerformanceClient,
|
||||
} from "@azure/msal-common/node";
|
||||
import { ManagedIdentityId } from "../../config/ManagedIdentityId.js";
|
||||
import { ManagedIdentityRequestParameters } from "../../config/ManagedIdentityRequestParameters.js";
|
||||
import { CryptoProvider } from "../../crypto/CryptoProvider.js";
|
||||
import { ManagedIdentityRequest } from "../../request/ManagedIdentityRequest.js";
|
||||
import {
|
||||
ApiId,
|
||||
HttpMethod,
|
||||
ManagedIdentityIdType,
|
||||
ManagedIdentityQueryParameters,
|
||||
} from "../../utils/Constants.js";
|
||||
import { ManagedIdentityTokenResponse } from "../../response/ManagedIdentityTokenResponse.js";
|
||||
import { NodeStorage } from "../../cache/NodeStorage.js";
|
||||
import {
|
||||
ManagedIdentityErrorCodes,
|
||||
createManagedIdentityError,
|
||||
} from "../../error/ManagedIdentityError.js";
|
||||
import { isIso8601 } from "../../utils/TimeUtils.js";
|
||||
import { HttpClientWithRetries } from "../../network/HttpClientWithRetries.js";
|
||||
|
||||
/**
|
||||
* Managed Identity User Assigned Id Query Parameter Names
|
||||
*/
|
||||
export const ManagedIdentityUserAssignedIdQueryParameterNames = {
|
||||
MANAGED_IDENTITY_CLIENT_ID_2017: "clientid", // 2017-09-01 API version
|
||||
MANAGED_IDENTITY_CLIENT_ID: "client_id", // 2019+ API versions
|
||||
MANAGED_IDENTITY_OBJECT_ID: "object_id",
|
||||
MANAGED_IDENTITY_RESOURCE_ID_IMDS: "msi_res_id",
|
||||
MANAGED_IDENTITY_RESOURCE_ID_NON_IMDS: "mi_res_id",
|
||||
} as const;
|
||||
export type ManagedIdentityUserAssignedIdQueryParameterNames =
|
||||
(typeof ManagedIdentityUserAssignedIdQueryParameterNames)[keyof typeof ManagedIdentityUserAssignedIdQueryParameterNames];
|
||||
|
||||
/**
|
||||
* Base class for all Managed Identity sources. Provides common functionality for
|
||||
* authenticating with Azure Managed Identity endpoints across different Azure services
|
||||
* including IMDS, App Service, Azure Arc, Service Fabric, Cloud Shell, and Machine Learning.
|
||||
*
|
||||
* This abstract class handles token acquisition, response processing, and network communication
|
||||
* while allowing concrete implementations to define source-specific request creation logic.
|
||||
*/
|
||||
export abstract class BaseManagedIdentitySource {
|
||||
protected logger: Logger;
|
||||
private nodeStorage: NodeStorage;
|
||||
private networkClient: INetworkModule;
|
||||
private cryptoProvider: CryptoProvider;
|
||||
private disableInternalRetries: boolean;
|
||||
|
||||
/**
|
||||
* Creates an instance of BaseManagedIdentitySource.
|
||||
*
|
||||
* @param logger - Logger instance for diagnostic information
|
||||
* @param nodeStorage - Storage interface for caching tokens
|
||||
* @param networkClient - Network client for making HTTP requests
|
||||
* @param cryptoProvider - Cryptographic provider for token operations
|
||||
* @param disableInternalRetries - Whether to disable automatic retry logic
|
||||
*/
|
||||
constructor(
|
||||
logger: Logger,
|
||||
nodeStorage: NodeStorage,
|
||||
networkClient: INetworkModule,
|
||||
cryptoProvider: CryptoProvider,
|
||||
disableInternalRetries: boolean
|
||||
) {
|
||||
this.logger = logger;
|
||||
this.nodeStorage = nodeStorage;
|
||||
this.networkClient = networkClient;
|
||||
this.cryptoProvider = cryptoProvider;
|
||||
this.disableInternalRetries = disableInternalRetries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a new correlation ID for request tracing.
|
||||
*
|
||||
* @returns A new GUID string for use as a correlation or request ID
|
||||
*/
|
||||
protected createCorrelationId(): string {
|
||||
return this.cryptoProvider.createNewGuid();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a managed identity request with source-specific parameters.
|
||||
* This method must be implemented by concrete managed identity sources to define
|
||||
* how requests are constructed for their specific endpoint requirements.
|
||||
*
|
||||
* @param resource - The Azure resource URI for which the access token is requested (e.g., "https://vault.azure.net/")
|
||||
* @param managedIdentityId - The managed identity configuration specifying system-assigned or user-assigned identity details
|
||||
*
|
||||
* @returns Request parameters configured for the specific managed identity source
|
||||
*/
|
||||
abstract createRequest(
|
||||
resource: string,
|
||||
managedIdentityId: ManagedIdentityId
|
||||
): ManagedIdentityRequestParameters;
|
||||
|
||||
/**
|
||||
* Processes the network response and converts it to a standardized server token response.
|
||||
* This async version allows for source-specific response processing logic while maintaining
|
||||
* backward compatibility with the synchronous version.
|
||||
*
|
||||
* @param response - The network response containing the managed identity token
|
||||
* @param _networkClient - Network client used for the request (unused in base implementation)
|
||||
* @param _networkRequest - The original network request parameters (unused in base implementation)
|
||||
* @param _networkRequestOptions - The network request options (unused in base implementation)
|
||||
*
|
||||
* @returns Promise resolving to a standardized server authorization token response
|
||||
*/
|
||||
public async getServerTokenResponseAsync(
|
||||
response: NetworkResponse<ManagedIdentityTokenResponse>,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
_networkClient: INetworkModule,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
_networkRequest: ManagedIdentityRequestParameters,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
_networkRequestOptions: NetworkRequestOptions
|
||||
): Promise<ServerAuthorizationTokenResponse> {
|
||||
return this.getServerTokenResponse(response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a managed identity token response to a standardized server authorization token response.
|
||||
* Handles time format conversion, expiration calculation, and error mapping to ensure
|
||||
* compatibility with the MSAL response handling pipeline.
|
||||
*
|
||||
* @param response - The network response containing the managed identity token
|
||||
*
|
||||
* @returns Standardized server authorization token response with normalized fields
|
||||
*/
|
||||
public getServerTokenResponse(
|
||||
response: NetworkResponse<ManagedIdentityTokenResponse>
|
||||
): ServerAuthorizationTokenResponse {
|
||||
let refreshIn, expiresIn: number | undefined;
|
||||
if (response.body.expires_on) {
|
||||
// if the expires_on field in the response body is a string and in ISO 8601 format, convert it to a Unix timestamp (seconds since epoch)
|
||||
if (isIso8601(response.body.expires_on)) {
|
||||
response.body.expires_on =
|
||||
new Date(response.body.expires_on).getTime() / 1000;
|
||||
}
|
||||
|
||||
expiresIn = response.body.expires_on - TimeUtils.nowSeconds();
|
||||
|
||||
// compute refresh_in as 1/2 of expires_in, but only if expires_in > 2h
|
||||
if (expiresIn > 2 * 3600) {
|
||||
refreshIn = expiresIn / 2;
|
||||
}
|
||||
}
|
||||
|
||||
const serverTokenResponse: ServerAuthorizationTokenResponse = {
|
||||
status: response.status,
|
||||
|
||||
// success
|
||||
access_token: response.body.access_token,
|
||||
expires_in: expiresIn,
|
||||
scope: response.body.resource,
|
||||
token_type: response.body.token_type,
|
||||
refresh_in: refreshIn,
|
||||
|
||||
// error
|
||||
correlation_id:
|
||||
response.body.correlation_id || response.body.correlationId,
|
||||
error:
|
||||
typeof response.body.error === "string"
|
||||
? response.body.error
|
||||
: response.body.error?.code,
|
||||
error_description:
|
||||
response.body.message ||
|
||||
(typeof response.body.error === "string"
|
||||
? response.body.error_description
|
||||
: response.body.error?.message),
|
||||
error_codes: response.body.error_codes,
|
||||
timestamp: response.body.timestamp,
|
||||
trace_id: response.body.trace_id,
|
||||
};
|
||||
|
||||
return serverTokenResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Acquires an access token using the managed identity endpoint for the specified resource.
|
||||
* This is the primary method for token acquisition, handling the complete flow from
|
||||
* request creation through response processing and token caching.
|
||||
*
|
||||
* @param managedIdentityRequest - The managed identity request containing resource and optional parameters
|
||||
* @param managedIdentityId - The managed identity configuration (system or user-assigned)
|
||||
* @param fakeAuthority - Authority instance used for token caching (managed identity uses a placeholder authority)
|
||||
* @param refreshAccessToken - Whether this is a token refresh operation
|
||||
*
|
||||
* @returns Promise resolving to an authentication result containing the access token and metadata
|
||||
*
|
||||
* @throws {AuthError} When network requests fail or token validation fails
|
||||
* @throws {ClientAuthError} When network errors occur during the request
|
||||
*/
|
||||
public async acquireTokenWithManagedIdentity(
|
||||
managedIdentityRequest: ManagedIdentityRequest,
|
||||
managedIdentityId: ManagedIdentityId,
|
||||
fakeAuthority: Authority,
|
||||
refreshAccessToken?: boolean
|
||||
): Promise<AuthenticationResult> {
|
||||
const networkRequest: ManagedIdentityRequestParameters =
|
||||
this.createRequest(
|
||||
managedIdentityRequest.resource,
|
||||
managedIdentityId
|
||||
);
|
||||
|
||||
if (managedIdentityRequest.revokedTokenSha256Hash) {
|
||||
this.logger.info(
|
||||
`[Managed Identity] The following claims are present in the request: ${managedIdentityRequest.claims}`,
|
||||
""
|
||||
);
|
||||
|
||||
networkRequest.queryParameters[
|
||||
ManagedIdentityQueryParameters.SHA256_TOKEN_TO_REFRESH
|
||||
] = managedIdentityRequest.revokedTokenSha256Hash;
|
||||
}
|
||||
|
||||
if (managedIdentityRequest.clientCapabilities?.length) {
|
||||
const clientCapabilities: string =
|
||||
managedIdentityRequest.clientCapabilities.toString();
|
||||
|
||||
this.logger.info(
|
||||
`[Managed Identity] The following client capabilities are present in the request: ${clientCapabilities}`,
|
||||
""
|
||||
);
|
||||
|
||||
networkRequest.queryParameters[
|
||||
ManagedIdentityQueryParameters.XMS_CC
|
||||
] = clientCapabilities;
|
||||
}
|
||||
|
||||
const headers: Record<string, string> = networkRequest.headers;
|
||||
headers[Constants.HeaderNames.CONTENT_TYPE] =
|
||||
Constants.URL_FORM_CONTENT_TYPE;
|
||||
|
||||
const networkRequestOptions: NetworkRequestOptions = { headers };
|
||||
|
||||
if (Object.keys(networkRequest.bodyParameters).length) {
|
||||
networkRequestOptions.body =
|
||||
networkRequest.computeParametersBodyString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the network client helper based on the retry policy configuration.
|
||||
* If internal retries are disabled, it uses the provided network client directly.
|
||||
* Otherwise, it wraps the network client with an HTTP client that supports retries.
|
||||
*/
|
||||
const networkClientHelper: INetworkModule = this.disableInternalRetries
|
||||
? this.networkClient
|
||||
: new HttpClientWithRetries(
|
||||
this.networkClient,
|
||||
networkRequest.retryPolicy,
|
||||
this.logger
|
||||
);
|
||||
|
||||
const reqTimestamp = TimeUtils.nowSeconds();
|
||||
let response: NetworkResponse<ManagedIdentityTokenResponse>;
|
||||
try {
|
||||
// Sources that send POST requests: Cloud Shell
|
||||
if (networkRequest.httpMethod === HttpMethod.POST) {
|
||||
response =
|
||||
await networkClientHelper.sendPostRequestAsync<ManagedIdentityTokenResponse>(
|
||||
networkRequest.computeUri(),
|
||||
networkRequestOptions
|
||||
);
|
||||
// Sources that send GET requests: App Service, Azure Arc, IMDS, Service Fabric
|
||||
} else {
|
||||
response =
|
||||
await networkClientHelper.sendGetRequestAsync<ManagedIdentityTokenResponse>(
|
||||
networkRequest.computeUri(),
|
||||
networkRequestOptions
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
if (error instanceof AuthError) {
|
||||
throw error;
|
||||
} else {
|
||||
throw createClientAuthError(ClientAuthErrorCodes.networkError);
|
||||
}
|
||||
}
|
||||
|
||||
const responseHandler = new ResponseHandler(
|
||||
managedIdentityId.id,
|
||||
this.nodeStorage,
|
||||
this.cryptoProvider,
|
||||
this.logger,
|
||||
new StubPerformanceClient(),
|
||||
null,
|
||||
null
|
||||
);
|
||||
|
||||
const serverTokenResponse: ServerAuthorizationTokenResponse =
|
||||
await this.getServerTokenResponseAsync(
|
||||
response,
|
||||
networkClientHelper,
|
||||
networkRequest,
|
||||
networkRequestOptions
|
||||
);
|
||||
|
||||
responseHandler.validateTokenResponse(
|
||||
serverTokenResponse,
|
||||
serverTokenResponse.correlation_id || "",
|
||||
refreshAccessToken
|
||||
);
|
||||
|
||||
// caches the token
|
||||
return responseHandler.handleServerTokenResponse(
|
||||
serverTokenResponse,
|
||||
fakeAuthority,
|
||||
reqTimestamp,
|
||||
managedIdentityRequest,
|
||||
ApiId.acquireTokenWithManagedIdentity
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the appropriate query parameter name for user-assigned managed identity
|
||||
* based on the identity type, API version, and endpoint characteristics.
|
||||
* Different Azure services and API versions use different parameter names for the same identity types.
|
||||
*
|
||||
* @param managedIdentityIdType - The type of user-assigned managed identity (client ID, object ID, or resource ID)
|
||||
* @param isImds - Whether the request is being made to the IMDS (Instance Metadata Service) endpoint
|
||||
* @param usesApi2017 - Whether the endpoint uses the 2017-09-01 API version (affects client ID parameter name)
|
||||
*
|
||||
* @returns The correct query parameter name for the specified identity type and endpoint
|
||||
*
|
||||
* @throws {ManagedIdentityError} When an invalid managed identity ID type is provided
|
||||
*/
|
||||
public getManagedIdentityUserAssignedIdQueryParameterKey(
|
||||
managedIdentityIdType: ManagedIdentityIdType,
|
||||
isImds?: boolean,
|
||||
usesApi2017?: boolean
|
||||
): string {
|
||||
switch (managedIdentityIdType) {
|
||||
case ManagedIdentityIdType.USER_ASSIGNED_CLIENT_ID:
|
||||
this.logger.info(
|
||||
`[Managed Identity] [API version ${
|
||||
usesApi2017 ? "2017+" : "2019+"
|
||||
}] Adding user assigned client id to the request.`,
|
||||
""
|
||||
);
|
||||
// The Machine Learning source uses the 2017-09-01 API version, which uses "clientid" instead of "client_id"
|
||||
return usesApi2017
|
||||
? ManagedIdentityUserAssignedIdQueryParameterNames.MANAGED_IDENTITY_CLIENT_ID_2017
|
||||
: ManagedIdentityUserAssignedIdQueryParameterNames.MANAGED_IDENTITY_CLIENT_ID;
|
||||
|
||||
case ManagedIdentityIdType.USER_ASSIGNED_RESOURCE_ID:
|
||||
this.logger.info(
|
||||
"[Managed Identity] Adding user assigned resource id to the request.",
|
||||
""
|
||||
);
|
||||
return isImds
|
||||
? ManagedIdentityUserAssignedIdQueryParameterNames.MANAGED_IDENTITY_RESOURCE_ID_IMDS
|
||||
: ManagedIdentityUserAssignedIdQueryParameterNames.MANAGED_IDENTITY_RESOURCE_ID_NON_IMDS;
|
||||
|
||||
case ManagedIdentityIdType.USER_ASSIGNED_OBJECT_ID:
|
||||
this.logger.info(
|
||||
"[Managed Identity] Adding user assigned object id to the request.",
|
||||
""
|
||||
);
|
||||
return ManagedIdentityUserAssignedIdQueryParameterNames.MANAGED_IDENTITY_OBJECT_ID;
|
||||
default:
|
||||
throw createManagedIdentityError(
|
||||
ManagedIdentityErrorCodes.invalidManagedIdentityIdType
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates and normalizes an environment variable containing a URL string.
|
||||
* This static utility method ensures that environment variables used for managed identity
|
||||
* endpoints contain properly formatted URLs and provides informative error messages when validation fails.
|
||||
*
|
||||
* @param envVariableStringName - The name of the environment variable being validated (for error reporting)
|
||||
* @param envVariable - The environment variable value containing the URL string
|
||||
* @param sourceName - The name of the managed identity source (for error reporting)
|
||||
* @param logger - Logger instance for diagnostic information
|
||||
*
|
||||
* @returns The validated and normalized URL string
|
||||
*
|
||||
* @throws {ManagedIdentityError} When the environment variable contains a malformed URL
|
||||
*/
|
||||
public static getValidatedEnvVariableUrlString = (
|
||||
envVariableStringName: keyof typeof ManagedIdentityErrorCodes.MsiEnvironmentVariableUrlMalformedErrorCodes,
|
||||
envVariable: string,
|
||||
sourceName: string,
|
||||
logger: Logger
|
||||
): string => {
|
||||
try {
|
||||
return new UrlString(envVariable).urlString;
|
||||
} catch (error) {
|
||||
logger.info(
|
||||
`[Managed Identity] ${sourceName} managed identity is unavailable because the '${envVariableStringName}' environment variable is malformed.`,
|
||||
""
|
||||
);
|
||||
|
||||
throw createManagedIdentityError(
|
||||
ManagedIdentityErrorCodes
|
||||
.MsiEnvironmentVariableUrlMalformedErrorCodes[
|
||||
envVariableStringName
|
||||
]
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
175
backend/node_modules/@azure/msal-node/src/client/ManagedIdentitySources/CloudShell.ts
generated
vendored
Normal file
175
backend/node_modules/@azure/msal-node/src/client/ManagedIdentitySources/CloudShell.ts
generated
vendored
Normal file
@ -0,0 +1,175 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import { INetworkModule, Logger } from "@azure/msal-common/node";
|
||||
import { ManagedIdentityRequestParameters } from "../../config/ManagedIdentityRequestParameters.js";
|
||||
import { BaseManagedIdentitySource } from "./BaseManagedIdentitySource.js";
|
||||
import { NodeStorage } from "../../cache/NodeStorage.js";
|
||||
import { CryptoProvider } from "../../crypto/CryptoProvider.js";
|
||||
import {
|
||||
HttpMethod,
|
||||
ManagedIdentityEnvironmentVariableNames,
|
||||
ManagedIdentityHeaders,
|
||||
ManagedIdentityIdType,
|
||||
ManagedIdentityQueryParameters,
|
||||
ManagedIdentitySourceNames,
|
||||
} from "../../utils/Constants.js";
|
||||
import {
|
||||
ManagedIdentityErrorCodes,
|
||||
createManagedIdentityError,
|
||||
} from "../../error/ManagedIdentityError.js";
|
||||
import { ManagedIdentityId } from "../../config/ManagedIdentityId.js";
|
||||
|
||||
/**
|
||||
* Azure Cloud Shell managed identity source implementation.
|
||||
*
|
||||
* This class handles authentication for applications running in Azure Cloud Shell environment.
|
||||
* Cloud Shell provides a browser-accessible shell for managing Azure resources and includes
|
||||
* a pre-configured managed identity for authentication.
|
||||
*
|
||||
* Original source of code: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/src/CloudShellManagedIdentitySource.cs
|
||||
*/
|
||||
export class CloudShell extends BaseManagedIdentitySource {
|
||||
private msiEndpoint: string;
|
||||
|
||||
/**
|
||||
* Creates a new CloudShell managed identity source instance.
|
||||
*
|
||||
* @param logger - Logger instance for diagnostic logging
|
||||
* @param nodeStorage - Node.js storage implementation for caching
|
||||
* @param networkClient - HTTP client for making requests to the managed identity endpoint
|
||||
* @param cryptoProvider - Cryptographic operations provider
|
||||
* @param disableInternalRetries - Whether to disable automatic retry logic for failed requests
|
||||
* @param msiEndpoint - The MSI endpoint URL obtained from environment variables
|
||||
*/
|
||||
constructor(
|
||||
logger: Logger,
|
||||
nodeStorage: NodeStorage,
|
||||
networkClient: INetworkModule,
|
||||
cryptoProvider: CryptoProvider,
|
||||
disableInternalRetries: boolean,
|
||||
msiEndpoint: string
|
||||
) {
|
||||
super(
|
||||
logger,
|
||||
nodeStorage,
|
||||
networkClient,
|
||||
cryptoProvider,
|
||||
disableInternalRetries
|
||||
);
|
||||
|
||||
this.msiEndpoint = msiEndpoint;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the required environment variables for Cloud Shell managed identity.
|
||||
*
|
||||
* Cloud Shell requires the MSI_ENDPOINT environment variable to be set, which
|
||||
* contains the URL of the managed identity service endpoint.
|
||||
*
|
||||
* @returns An array containing the MSI_ENDPOINT environment variable value (or undefined if not set)
|
||||
*/
|
||||
public static getEnvironmentVariables(): Array<string | undefined> {
|
||||
const msiEndpoint: string | undefined =
|
||||
process.env[ManagedIdentityEnvironmentVariableNames.MSI_ENDPOINT];
|
||||
|
||||
return [msiEndpoint];
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to create a CloudShell managed identity source instance.
|
||||
*
|
||||
* This method validates that the required environment variables are present and
|
||||
* creates a CloudShell instance if the environment is properly configured.
|
||||
* Cloud Shell only supports system-assigned managed identities.
|
||||
*
|
||||
* @param logger - Logger instance for diagnostic logging
|
||||
* @param nodeStorage - Node.js storage implementation for caching
|
||||
* @param networkClient - HTTP client for making requests
|
||||
* @param cryptoProvider - Cryptographic operations provider
|
||||
* @param disableInternalRetries - Whether to disable automatic retry logic
|
||||
* @param managedIdentityId - The managed identity configuration (must be system-assigned)
|
||||
*
|
||||
* @returns A CloudShell instance if the environment is valid, null otherwise
|
||||
*
|
||||
* @throws {ManagedIdentityError} When a user-assigned managed identity is requested,
|
||||
* as Cloud Shell only supports system-assigned identities
|
||||
*/
|
||||
public static tryCreate(
|
||||
logger: Logger,
|
||||
nodeStorage: NodeStorage,
|
||||
networkClient: INetworkModule,
|
||||
cryptoProvider: CryptoProvider,
|
||||
disableInternalRetries: boolean,
|
||||
managedIdentityId: ManagedIdentityId
|
||||
): CloudShell | null {
|
||||
const [msiEndpoint] = CloudShell.getEnvironmentVariables();
|
||||
|
||||
// if the msi endpoint environment variable is undefined, this MSI provider is unavailable.
|
||||
if (!msiEndpoint) {
|
||||
logger.info(
|
||||
`[Managed Identity] ${ManagedIdentitySourceNames.CLOUD_SHELL} managed identity is unavailable because the '${ManagedIdentityEnvironmentVariableNames.MSI_ENDPOINT} environment variable is not defined.`,
|
||||
""
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
const validatedMsiEndpoint: string =
|
||||
CloudShell.getValidatedEnvVariableUrlString(
|
||||
ManagedIdentityEnvironmentVariableNames.MSI_ENDPOINT,
|
||||
msiEndpoint,
|
||||
ManagedIdentitySourceNames.CLOUD_SHELL,
|
||||
logger
|
||||
);
|
||||
|
||||
logger.info(
|
||||
`[Managed Identity] Environment variable validation passed for ${ManagedIdentitySourceNames.CLOUD_SHELL} managed identity. Endpoint URI: ${validatedMsiEndpoint}. Creating ${ManagedIdentitySourceNames.CLOUD_SHELL} managed identity.`,
|
||||
""
|
||||
);
|
||||
|
||||
if (
|
||||
managedIdentityId.idType !== ManagedIdentityIdType.SYSTEM_ASSIGNED
|
||||
) {
|
||||
throw createManagedIdentityError(
|
||||
ManagedIdentityErrorCodes.unableToCreateCloudShell
|
||||
);
|
||||
}
|
||||
|
||||
return new CloudShell(
|
||||
logger,
|
||||
nodeStorage,
|
||||
networkClient,
|
||||
cryptoProvider,
|
||||
disableInternalRetries,
|
||||
msiEndpoint
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an HTTP request to acquire an access token from the Cloud Shell managed identity endpoint.
|
||||
*
|
||||
* This method constructs a POST request to the MSI endpoint with the required headers and
|
||||
* body parameters for Cloud Shell authentication. The request includes the target resource
|
||||
* for which the access token is being requested.
|
||||
*
|
||||
* @param resource - The target resource/scope for which to request an access token (e.g., "https://graph.microsoft.com/.default")
|
||||
*
|
||||
* @returns A configured ManagedIdentityRequestParameters object ready for network execution
|
||||
*/
|
||||
public createRequest(resource: string): ManagedIdentityRequestParameters {
|
||||
const request: ManagedIdentityRequestParameters =
|
||||
new ManagedIdentityRequestParameters(
|
||||
HttpMethod.POST,
|
||||
this.msiEndpoint
|
||||
);
|
||||
|
||||
request.headers[ManagedIdentityHeaders.METADATA_HEADER_NAME] = "true";
|
||||
|
||||
request.bodyParameters[ManagedIdentityQueryParameters.RESOURCE] =
|
||||
resource;
|
||||
|
||||
return request;
|
||||
}
|
||||
}
|
||||
200
backend/node_modules/@azure/msal-node/src/client/ManagedIdentitySources/Imds.ts
generated
vendored
Normal file
200
backend/node_modules/@azure/msal-node/src/client/ManagedIdentitySources/Imds.ts
generated
vendored
Normal file
@ -0,0 +1,200 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import { INetworkModule, Logger } from "@azure/msal-common/node";
|
||||
import { ManagedIdentityId } from "../../config/ManagedIdentityId.js";
|
||||
import { ManagedIdentityRequestParameters } from "../../config/ManagedIdentityRequestParameters.js";
|
||||
import { BaseManagedIdentitySource } from "./BaseManagedIdentitySource.js";
|
||||
import { CryptoProvider } from "../../crypto/CryptoProvider.js";
|
||||
import {
|
||||
Constants as NodeConstants,
|
||||
HttpMethod,
|
||||
ManagedIdentityEnvironmentVariableNames,
|
||||
ManagedIdentityHeaders,
|
||||
ManagedIdentityIdType,
|
||||
ManagedIdentityQueryParameters,
|
||||
ManagedIdentitySourceNames,
|
||||
} from "../../utils/Constants.js";
|
||||
import { NodeStorage } from "../../cache/NodeStorage.js";
|
||||
import { ImdsRetryPolicy } from "../../retry/ImdsRetryPolicy.js";
|
||||
import { version as packageVersion } from "../../packageMetadata.js";
|
||||
|
||||
// Documentation for IMDS is available at https://docs.microsoft.com/azure/active-directory/managed-identities-azure-resources/how-to-use-vm-token#get-a-token-using-http
|
||||
|
||||
const IMDS_TOKEN_PATH: string = "/metadata/identity/oauth2/token";
|
||||
const DEFAULT_IMDS_ENDPOINT: string = `http://169.254.169.254${IMDS_TOKEN_PATH}`;
|
||||
const IMDS_API_VERSION: string = "2018-02-01";
|
||||
|
||||
/**
|
||||
* Managed Identity source implementation for Azure Instance Metadata Service (IMDS).
|
||||
*
|
||||
* IMDS is available on Azure Virtual Machines and Virtual Machine Scale Sets and provides
|
||||
* a REST endpoint to obtain OAuth tokens for managed identities. This implementation
|
||||
* handles both system-assigned and user-assigned managed identities.
|
||||
*
|
||||
* Original source of code: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/src/ImdsManagedIdentitySource.cs
|
||||
*/
|
||||
export class Imds extends BaseManagedIdentitySource {
|
||||
private identityEndpoint: string;
|
||||
|
||||
/**
|
||||
* Constructs an Imds instance with the specified configuration.
|
||||
*
|
||||
* @param logger - Logger instance for recording debug information and errors
|
||||
* @param nodeStorage - NodeStorage instance used for token caching operations
|
||||
* @param networkClient - Network client implementation for making HTTP requests to IMDS
|
||||
* @param cryptoProvider - CryptoProvider for generating correlation IDs and other cryptographic operations
|
||||
* @param disableInternalRetries - When true, disables the built-in retry logic for IMDS requests
|
||||
* @param identityEndpoint - The complete IMDS endpoint URL including the token path
|
||||
*/
|
||||
constructor(
|
||||
logger: Logger,
|
||||
nodeStorage: NodeStorage,
|
||||
networkClient: INetworkModule,
|
||||
cryptoProvider: CryptoProvider,
|
||||
disableInternalRetries: boolean,
|
||||
identityEndpoint: string
|
||||
) {
|
||||
super(
|
||||
logger,
|
||||
nodeStorage,
|
||||
networkClient,
|
||||
cryptoProvider,
|
||||
disableInternalRetries
|
||||
);
|
||||
|
||||
this.identityEndpoint = identityEndpoint;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an Imds instance with the appropriate endpoint configuration.
|
||||
*
|
||||
* This method checks for the presence of the AZURE_POD_IDENTITY_AUTHORITY_HOST environment
|
||||
* variable, which is used in Azure Kubernetes Service (AKS) environments with Azure AD
|
||||
* Pod Identity. If found, it uses that endpoint; otherwise, it falls back to the standard
|
||||
* IMDS endpoint (169.254.169.254).
|
||||
*
|
||||
* @param logger - Logger instance for recording endpoint discovery and validation
|
||||
* @param nodeStorage - NodeStorage instance for token caching
|
||||
* @param networkClient - Network client for HTTP requests
|
||||
* @param cryptoProvider - CryptoProvider for cryptographic operations
|
||||
* @param disableInternalRetries - Whether to disable built-in retry logic
|
||||
*
|
||||
* @returns A configured Imds instance ready to make token requests
|
||||
*/
|
||||
public static tryCreate(
|
||||
logger: Logger,
|
||||
nodeStorage: NodeStorage,
|
||||
networkClient: INetworkModule,
|
||||
cryptoProvider: CryptoProvider,
|
||||
disableInternalRetries: boolean
|
||||
): Imds {
|
||||
let validatedIdentityEndpoint: string;
|
||||
|
||||
if (
|
||||
process.env[
|
||||
ManagedIdentityEnvironmentVariableNames
|
||||
.AZURE_POD_IDENTITY_AUTHORITY_HOST
|
||||
]
|
||||
) {
|
||||
logger.info(
|
||||
`[Managed Identity] Environment variable ${
|
||||
ManagedIdentityEnvironmentVariableNames.AZURE_POD_IDENTITY_AUTHORITY_HOST
|
||||
} for ${ManagedIdentitySourceNames.IMDS} returned endpoint: ${
|
||||
process.env[
|
||||
ManagedIdentityEnvironmentVariableNames
|
||||
.AZURE_POD_IDENTITY_AUTHORITY_HOST
|
||||
]
|
||||
}`,
|
||||
""
|
||||
);
|
||||
validatedIdentityEndpoint = Imds.getValidatedEnvVariableUrlString(
|
||||
ManagedIdentityEnvironmentVariableNames.AZURE_POD_IDENTITY_AUTHORITY_HOST,
|
||||
`${
|
||||
process.env[
|
||||
ManagedIdentityEnvironmentVariableNames
|
||||
.AZURE_POD_IDENTITY_AUTHORITY_HOST
|
||||
]
|
||||
}${IMDS_TOKEN_PATH}`,
|
||||
ManagedIdentitySourceNames.IMDS,
|
||||
logger
|
||||
);
|
||||
} else {
|
||||
logger.info(
|
||||
`[Managed Identity] Unable to find ${ManagedIdentityEnvironmentVariableNames.AZURE_POD_IDENTITY_AUTHORITY_HOST} environment variable for ${ManagedIdentitySourceNames.IMDS}, using the default endpoint.`,
|
||||
""
|
||||
);
|
||||
validatedIdentityEndpoint = DEFAULT_IMDS_ENDPOINT;
|
||||
}
|
||||
|
||||
return new Imds(
|
||||
logger,
|
||||
nodeStorage,
|
||||
networkClient,
|
||||
cryptoProvider,
|
||||
disableInternalRetries,
|
||||
validatedIdentityEndpoint
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a properly configured HTTP request for acquiring an access token from IMDS.
|
||||
*
|
||||
* This method builds a complete request object with all necessary headers, query parameters,
|
||||
* and retry policies required by the Azure Instance Metadata Service.
|
||||
*
|
||||
* Key request components:
|
||||
* - HTTP GET method to the IMDS token endpoint
|
||||
* - Metadata header set to "true" (required by IMDS)
|
||||
* - API version parameter (currently "2018-02-01")
|
||||
* - Resource parameter specifying the target audience
|
||||
* - Identity-specific parameters for user-assigned managed identities
|
||||
* - IMDS-specific retry policy
|
||||
*
|
||||
* @param resource - The target resource/scope for which to request an access token (e.g., "https://graph.microsoft.com/.default")
|
||||
* @param managedIdentityId - The managed identity configuration specifying whether to use system-assigned or user-assigned identity
|
||||
*
|
||||
* @returns A configured ManagedIdentityRequestParameters object ready for network execution
|
||||
*/
|
||||
public createRequest(
|
||||
resource: string,
|
||||
managedIdentityId: ManagedIdentityId
|
||||
): ManagedIdentityRequestParameters {
|
||||
const request: ManagedIdentityRequestParameters =
|
||||
new ManagedIdentityRequestParameters(
|
||||
HttpMethod.GET,
|
||||
this.identityEndpoint
|
||||
);
|
||||
|
||||
request.headers[ManagedIdentityHeaders.METADATA_HEADER_NAME] = "true";
|
||||
request.headers[ManagedIdentityHeaders.CLIENT_SKU] =
|
||||
NodeConstants.MSAL_SKU;
|
||||
request.headers[ManagedIdentityHeaders.CLIENT_VER] = packageVersion;
|
||||
request.headers[ManagedIdentityHeaders.CLIENT_REQUEST_ID] =
|
||||
this.createCorrelationId();
|
||||
|
||||
request.queryParameters[ManagedIdentityQueryParameters.API_VERSION] =
|
||||
IMDS_API_VERSION;
|
||||
request.queryParameters[ManagedIdentityQueryParameters.RESOURCE] =
|
||||
resource;
|
||||
|
||||
if (
|
||||
managedIdentityId.idType !== ManagedIdentityIdType.SYSTEM_ASSIGNED
|
||||
) {
|
||||
request.queryParameters[
|
||||
this.getManagedIdentityUserAssignedIdQueryParameterKey(
|
||||
managedIdentityId.idType,
|
||||
true // indicates source is IMDS
|
||||
)
|
||||
] = managedIdentityId.id;
|
||||
}
|
||||
|
||||
// The bodyParameters are calculated in BaseManagedIdentity.acquireTokenWithManagedIdentity.
|
||||
|
||||
request.retryPolicy = new ImdsRetryPolicy();
|
||||
|
||||
return request;
|
||||
}
|
||||
}
|
||||
219
backend/node_modules/@azure/msal-node/src/client/ManagedIdentitySources/MachineLearning.ts
generated
vendored
Normal file
219
backend/node_modules/@azure/msal-node/src/client/ManagedIdentitySources/MachineLearning.ts
generated
vendored
Normal file
@ -0,0 +1,219 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import { INetworkModule, Logger } from "@azure/msal-common/node";
|
||||
import {
|
||||
BaseManagedIdentitySource,
|
||||
ManagedIdentityUserAssignedIdQueryParameterNames,
|
||||
} from "./BaseManagedIdentitySource.js";
|
||||
import {
|
||||
HttpMethod,
|
||||
ManagedIdentityEnvironmentVariableNames,
|
||||
ManagedIdentitySourceNames,
|
||||
ManagedIdentityIdType,
|
||||
ManagedIdentityQueryParameters,
|
||||
ManagedIdentityHeaders,
|
||||
} from "../../utils/Constants.js";
|
||||
import { CryptoProvider } from "../../crypto/CryptoProvider.js";
|
||||
import { ManagedIdentityRequestParameters } from "../../config/ManagedIdentityRequestParameters.js";
|
||||
import { ManagedIdentityId } from "../../config/ManagedIdentityId.js";
|
||||
import { NodeStorage } from "../../cache/NodeStorage.js";
|
||||
|
||||
const MACHINE_LEARNING_MSI_API_VERSION: string = "2017-09-01";
|
||||
|
||||
export const MANAGED_IDENTITY_MACHINE_LEARNING_UNSUPPORTED_ID_TYPE_ERROR = `Only client id is supported for user-assigned managed identity in ${ManagedIdentitySourceNames.MACHINE_LEARNING}.`; // referenced in unit test
|
||||
|
||||
/**
|
||||
* Machine Learning Managed Identity Source implementation for Azure Machine Learning environments.
|
||||
*
|
||||
* This class handles managed identity authentication specifically for Azure Machine Learning services.
|
||||
* It supports both system-assigned and user-assigned managed identities, using the MSI_ENDPOINT
|
||||
* and MSI_SECRET environment variables that are automatically provided in Azure ML environments.
|
||||
*/
|
||||
export class MachineLearning extends BaseManagedIdentitySource {
|
||||
private msiEndpoint: string;
|
||||
private secret: string;
|
||||
|
||||
/**
|
||||
* Creates a new MachineLearning managed identity source instance.
|
||||
*
|
||||
* @param logger - Logger instance for diagnostic information
|
||||
* @param nodeStorage - Node storage implementation for caching
|
||||
* @param networkClient - Network client for making HTTP requests
|
||||
* @param cryptoProvider - Cryptographic operations provider
|
||||
* @param disableInternalRetries - Whether to disable automatic request retries
|
||||
* @param msiEndpoint - The MSI endpoint URL from environment variables
|
||||
* @param secret - The MSI secret from environment variables
|
||||
*/
|
||||
constructor(
|
||||
logger: Logger,
|
||||
nodeStorage: NodeStorage,
|
||||
networkClient: INetworkModule,
|
||||
cryptoProvider: CryptoProvider,
|
||||
disableInternalRetries: boolean,
|
||||
msiEndpoint: string,
|
||||
secret: string
|
||||
) {
|
||||
super(
|
||||
logger,
|
||||
nodeStorage,
|
||||
networkClient,
|
||||
cryptoProvider,
|
||||
disableInternalRetries
|
||||
);
|
||||
|
||||
this.msiEndpoint = msiEndpoint;
|
||||
this.secret = secret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the required environment variables for Azure Machine Learning managed identity.
|
||||
*
|
||||
* This method checks for the presence of MSI_ENDPOINT and MSI_SECRET environment variables
|
||||
* that are automatically set by the Azure Machine Learning platform when managed identity
|
||||
* is enabled for the compute instance or cluster.
|
||||
*
|
||||
* @returns An array containing [msiEndpoint, secret] where either value may be undefined
|
||||
* if the corresponding environment variable is not set
|
||||
*/
|
||||
public static getEnvironmentVariables(): Array<string | undefined> {
|
||||
const msiEndpoint: string | undefined =
|
||||
process.env[ManagedIdentityEnvironmentVariableNames.MSI_ENDPOINT];
|
||||
|
||||
const secret: string | undefined =
|
||||
process.env[ManagedIdentityEnvironmentVariableNames.MSI_SECRET];
|
||||
|
||||
return [msiEndpoint, secret];
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to create a MachineLearning managed identity source.
|
||||
*
|
||||
* This method validates the Azure Machine Learning environment by checking for the required
|
||||
* MSI_ENDPOINT and MSI_SECRET environment variables. If both are present and valid,
|
||||
* it creates and returns a MachineLearning instance. If either is missing or invalid,
|
||||
* it returns null, indicating that this managed identity source is not available
|
||||
* in the current environment.
|
||||
*
|
||||
* @param logger - Logger instance for diagnostic information
|
||||
* @param nodeStorage - Node storage implementation for caching
|
||||
* @param networkClient - Network client for making HTTP requests
|
||||
* @param cryptoProvider - Cryptographic operations provider
|
||||
* @param disableInternalRetries - Whether to disable automatic request retries
|
||||
*
|
||||
* @returns A new MachineLearning instance if the environment is valid, null otherwise
|
||||
*/
|
||||
public static tryCreate(
|
||||
logger: Logger,
|
||||
nodeStorage: NodeStorage,
|
||||
networkClient: INetworkModule,
|
||||
cryptoProvider: CryptoProvider,
|
||||
disableInternalRetries: boolean
|
||||
): MachineLearning | null {
|
||||
const [msiEndpoint, secret] = MachineLearning.getEnvironmentVariables();
|
||||
|
||||
// if either of the MSI endpoint or MSI secret variables are undefined, this MSI provider is unavailable.
|
||||
if (!msiEndpoint || !secret) {
|
||||
logger.info(
|
||||
`[Managed Identity] ${ManagedIdentitySourceNames.MACHINE_LEARNING} managed identity is unavailable because one or both of the '${ManagedIdentityEnvironmentVariableNames.MSI_ENDPOINT}' and '${ManagedIdentityEnvironmentVariableNames.MSI_SECRET}' environment variables are not defined.`,
|
||||
""
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
const validatedMsiEndpoint: string =
|
||||
MachineLearning.getValidatedEnvVariableUrlString(
|
||||
ManagedIdentityEnvironmentVariableNames.MSI_ENDPOINT,
|
||||
msiEndpoint,
|
||||
ManagedIdentitySourceNames.MACHINE_LEARNING,
|
||||
logger
|
||||
);
|
||||
|
||||
logger.info(
|
||||
`[Managed Identity] Environment variables validation passed for ${ManagedIdentitySourceNames.MACHINE_LEARNING} managed identity. Endpoint URI: ${validatedMsiEndpoint}. Creating ${ManagedIdentitySourceNames.MACHINE_LEARNING} managed identity.`,
|
||||
""
|
||||
);
|
||||
|
||||
return new MachineLearning(
|
||||
logger,
|
||||
nodeStorage,
|
||||
networkClient,
|
||||
cryptoProvider,
|
||||
disableInternalRetries,
|
||||
msiEndpoint,
|
||||
secret
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a managed identity token request for Azure Machine Learning environments.
|
||||
*
|
||||
* This method constructs the HTTP request parameters needed to acquire an access token
|
||||
* from the Azure Machine Learning managed identity endpoint. It handles both system-assigned
|
||||
* and user-assigned managed identities with specific logic for each type:
|
||||
*
|
||||
* - System-assigned: Uses the DEFAULT_IDENTITY_CLIENT_ID environment variable
|
||||
* - User-assigned: Only supports client ID-based identification (not object ID or resource ID)
|
||||
*
|
||||
* The request uses the 2017-09-01 API version and includes the required secret header
|
||||
* for authentication with the MSI endpoint.
|
||||
*
|
||||
* @param resource - The target resource/scope for which to request an access token (e.g., "https://graph.microsoft.com/.default")
|
||||
* @param managedIdentityId - The managed identity configuration specifying whether to use system-assigned or user-assigned identity
|
||||
*
|
||||
* @returns A configured ManagedIdentityRequestParameters object ready for network execution
|
||||
*
|
||||
* @throws Error if an unsupported managed identity ID type is specified (only client ID is supported for user-assigned)
|
||||
*/
|
||||
public createRequest(
|
||||
resource: string,
|
||||
managedIdentityId: ManagedIdentityId
|
||||
): ManagedIdentityRequestParameters {
|
||||
const request: ManagedIdentityRequestParameters =
|
||||
new ManagedIdentityRequestParameters(
|
||||
HttpMethod.GET,
|
||||
this.msiEndpoint
|
||||
);
|
||||
|
||||
request.headers[ManagedIdentityHeaders.METADATA_HEADER_NAME] = "true";
|
||||
request.headers[ManagedIdentityHeaders.ML_AND_SF_SECRET_HEADER_NAME] =
|
||||
this.secret;
|
||||
|
||||
request.queryParameters[ManagedIdentityQueryParameters.API_VERSION] =
|
||||
MACHINE_LEARNING_MSI_API_VERSION;
|
||||
request.queryParameters[ManagedIdentityQueryParameters.RESOURCE] =
|
||||
resource;
|
||||
|
||||
if (
|
||||
managedIdentityId.idType === ManagedIdentityIdType.SYSTEM_ASSIGNED
|
||||
) {
|
||||
request.queryParameters[
|
||||
ManagedIdentityUserAssignedIdQueryParameterNames.MANAGED_IDENTITY_CLIENT_ID_2017
|
||||
] = process.env[
|
||||
ManagedIdentityEnvironmentVariableNames
|
||||
.DEFAULT_IDENTITY_CLIENT_ID
|
||||
] as string; // this environment variable is always set in an Azure Machine Learning source
|
||||
} else if (
|
||||
managedIdentityId.idType ===
|
||||
ManagedIdentityIdType.USER_ASSIGNED_CLIENT_ID
|
||||
) {
|
||||
request.queryParameters[
|
||||
this.getManagedIdentityUserAssignedIdQueryParameterKey(
|
||||
managedIdentityId.idType,
|
||||
false, // isIMDS
|
||||
true // uses2017API
|
||||
)
|
||||
] = managedIdentityId.id;
|
||||
} else {
|
||||
throw new Error(
|
||||
MANAGED_IDENTITY_MACHINE_LEARNING_UNSUPPORTED_ID_TYPE_ERROR
|
||||
);
|
||||
}
|
||||
|
||||
// bodyParameters calculated in BaseManagedIdentity.acquireTokenWithManagedIdentity
|
||||
|
||||
return request;
|
||||
}
|
||||
}
|
||||
217
backend/node_modules/@azure/msal-node/src/client/ManagedIdentitySources/ServiceFabric.ts
generated
vendored
Normal file
217
backend/node_modules/@azure/msal-node/src/client/ManagedIdentitySources/ServiceFabric.ts
generated
vendored
Normal file
@ -0,0 +1,217 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import { INetworkModule, Logger } from "@azure/msal-common/node";
|
||||
import { ManagedIdentityId } from "../../config/ManagedIdentityId.js";
|
||||
import { ManagedIdentityRequestParameters } from "../../config/ManagedIdentityRequestParameters.js";
|
||||
import { BaseManagedIdentitySource } from "./BaseManagedIdentitySource.js";
|
||||
import { NodeStorage } from "../../cache/NodeStorage.js";
|
||||
import { CryptoProvider } from "../../crypto/CryptoProvider.js";
|
||||
import {
|
||||
HttpMethod,
|
||||
ManagedIdentityEnvironmentVariableNames,
|
||||
ManagedIdentityIdType,
|
||||
ManagedIdentitySourceNames,
|
||||
ManagedIdentityQueryParameters,
|
||||
ManagedIdentityHeaders,
|
||||
} from "../../utils/Constants.js";
|
||||
|
||||
const SERVICE_FABRIC_MSI_API_VERSION: string = "2019-07-01-preview";
|
||||
|
||||
/**
|
||||
* Original source of code: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/src/ServiceFabricManagedIdentitySource.cs
|
||||
*/
|
||||
export class ServiceFabric extends BaseManagedIdentitySource {
|
||||
private identityEndpoint: string;
|
||||
private identityHeader: string;
|
||||
|
||||
/**
|
||||
* Constructs a new ServiceFabric managed identity source for acquiring tokens from Azure Service Fabric clusters.
|
||||
*
|
||||
* Service Fabric managed identity allows applications running in Service Fabric clusters to authenticate
|
||||
* without storing credentials in code. This source handles token acquisition using the Service Fabric
|
||||
* Managed Identity Token Service (MITS).
|
||||
*
|
||||
* @param logger - Logger instance for logging authentication events and debugging information
|
||||
* @param nodeStorage - NodeStorage instance for caching tokens and other authentication artifacts
|
||||
* @param networkClient - Network client for making HTTP requests to the Service Fabric identity endpoint
|
||||
* @param cryptoProvider - Crypto provider for cryptographic operations like token validation
|
||||
* @param disableInternalRetries - Whether to disable internal retry logic for failed requests
|
||||
* @param identityEndpoint - The Service Fabric managed identity endpoint URL
|
||||
* @param identityHeader - The Service Fabric managed identity secret header value
|
||||
*/
|
||||
constructor(
|
||||
logger: Logger,
|
||||
nodeStorage: NodeStorage,
|
||||
networkClient: INetworkModule,
|
||||
cryptoProvider: CryptoProvider,
|
||||
disableInternalRetries: boolean,
|
||||
identityEndpoint: string,
|
||||
identityHeader: string
|
||||
) {
|
||||
super(
|
||||
logger,
|
||||
nodeStorage,
|
||||
networkClient,
|
||||
cryptoProvider,
|
||||
disableInternalRetries
|
||||
);
|
||||
|
||||
this.identityEndpoint = identityEndpoint;
|
||||
this.identityHeader = identityHeader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the environment variables required for Service Fabric managed identity authentication.
|
||||
*
|
||||
* Service Fabric managed identity requires three specific environment variables to be set by the
|
||||
* Service Fabric runtime:
|
||||
* - IDENTITY_ENDPOINT: The endpoint URL for the Managed Identity Token Service (MITS)
|
||||
* - IDENTITY_HEADER: A secret value used for authentication with the MITS
|
||||
* - IDENTITY_SERVER_THUMBPRINT: The thumbprint of the MITS server certificate for secure communication
|
||||
*
|
||||
* @returns An array containing the identity endpoint, identity header, and identity server thumbprint values.
|
||||
* Elements will be undefined if the corresponding environment variables are not set.
|
||||
*/
|
||||
public static getEnvironmentVariables(): Array<string | undefined> {
|
||||
const identityEndpoint: string | undefined =
|
||||
process.env[
|
||||
ManagedIdentityEnvironmentVariableNames.IDENTITY_ENDPOINT
|
||||
];
|
||||
const identityHeader: string | undefined =
|
||||
process.env[
|
||||
ManagedIdentityEnvironmentVariableNames.IDENTITY_HEADER
|
||||
];
|
||||
const identityServerThumbprint: string | undefined =
|
||||
process.env[
|
||||
ManagedIdentityEnvironmentVariableNames
|
||||
.IDENTITY_SERVER_THUMBPRINT
|
||||
];
|
||||
|
||||
return [identityEndpoint, identityHeader, identityServerThumbprint];
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to create a ServiceFabric managed identity source if the runtime environment supports it.
|
||||
*
|
||||
* Checks for the presence of all required Service Fabric environment variables
|
||||
* and validates the endpoint URL format. It will only create a ServiceFabric instance if the application
|
||||
* is running in a properly configured Service Fabric cluster with managed identity enabled.
|
||||
*
|
||||
* Note: User-assigned managed identities must be configured at the cluster level, not at runtime.
|
||||
* This method will log a warning if a user-assigned identity is requested.
|
||||
*
|
||||
* @param logger - Logger instance for logging creation events and validation results
|
||||
* @param nodeStorage - NodeStorage instance for caching tokens and authentication artifacts
|
||||
* @param networkClient - Network client for making HTTP requests to the identity endpoint
|
||||
* @param cryptoProvider - Crypto provider for cryptographic operations
|
||||
* @param disableInternalRetries - Whether to disable internal retry logic for failed requests
|
||||
* @param managedIdentityId - Managed identity identifier specifying system-assigned or user-assigned identity
|
||||
*
|
||||
* @returns A ServiceFabric instance if all environment variables are valid and present, otherwise null
|
||||
*/
|
||||
public static tryCreate(
|
||||
logger: Logger,
|
||||
nodeStorage: NodeStorage,
|
||||
networkClient: INetworkModule,
|
||||
cryptoProvider: CryptoProvider,
|
||||
disableInternalRetries: boolean,
|
||||
managedIdentityId: ManagedIdentityId
|
||||
): ServiceFabric | null {
|
||||
const [identityEndpoint, identityHeader, identityServerThumbprint] =
|
||||
ServiceFabric.getEnvironmentVariables();
|
||||
|
||||
if (!identityEndpoint || !identityHeader || !identityServerThumbprint) {
|
||||
logger.info(
|
||||
`[Managed Identity] ${ManagedIdentitySourceNames.SERVICE_FABRIC} managed identity is unavailable because one or all of the '${ManagedIdentityEnvironmentVariableNames.IDENTITY_HEADER}', '${ManagedIdentityEnvironmentVariableNames.IDENTITY_ENDPOINT}' or '${ManagedIdentityEnvironmentVariableNames.IDENTITY_SERVER_THUMBPRINT}' environment variables are not defined.`,
|
||||
""
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
const validatedIdentityEndpoint: string =
|
||||
ServiceFabric.getValidatedEnvVariableUrlString(
|
||||
ManagedIdentityEnvironmentVariableNames.IDENTITY_ENDPOINT,
|
||||
identityEndpoint,
|
||||
ManagedIdentitySourceNames.SERVICE_FABRIC,
|
||||
logger
|
||||
);
|
||||
|
||||
logger.info(
|
||||
`[Managed Identity] Environment variables validation passed for ${ManagedIdentitySourceNames.SERVICE_FABRIC} managed identity. Endpoint URI: ${validatedIdentityEndpoint}. Creating ${ManagedIdentitySourceNames.SERVICE_FABRIC} managed identity.`,
|
||||
""
|
||||
);
|
||||
|
||||
if (
|
||||
managedIdentityId.idType !== ManagedIdentityIdType.SYSTEM_ASSIGNED
|
||||
) {
|
||||
logger.warning(
|
||||
`[Managed Identity] ${ManagedIdentitySourceNames.SERVICE_FABRIC} user assigned managed identity is configured in the cluster, not during runtime. See also: https://learn.microsoft.com/en-us/azure/service-fabric/configure-existing-cluster-enable-managed-identity-token-service.`,
|
||||
""
|
||||
);
|
||||
}
|
||||
|
||||
return new ServiceFabric(
|
||||
logger,
|
||||
nodeStorage,
|
||||
networkClient,
|
||||
cryptoProvider,
|
||||
disableInternalRetries,
|
||||
identityEndpoint,
|
||||
identityHeader
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates HTTP request parameters for acquiring an access token from the Service Fabric Managed Identity Token Service (MITS).
|
||||
*
|
||||
* This method constructs a properly formatted HTTP GET request that includes:
|
||||
* - The secret header for authentication with MITS
|
||||
* - API version parameter for the Service Fabric MSI endpoint
|
||||
* - Resource parameter specifying the target Azure service
|
||||
* - Optional identity parameters for user-assigned managed identities
|
||||
*
|
||||
* The request follows the Service Fabric managed identity protocol and uses the 2019-07-01-preview API version.
|
||||
* For user-assigned identities, the appropriate query parameter (client_id, object_id, or resource_id) is added
|
||||
* based on the identity type.
|
||||
*
|
||||
* @param resource - The Azure resource URI for which the access token is requested (e.g., "https://vault.azure.net/")
|
||||
* @param managedIdentityId - The managed identity configuration specifying system-assigned or user-assigned identity details
|
||||
*
|
||||
* @returns A configured ManagedIdentityRequestParameters object ready for network execution
|
||||
*/
|
||||
public createRequest(
|
||||
resource: string,
|
||||
managedIdentityId: ManagedIdentityId
|
||||
): ManagedIdentityRequestParameters {
|
||||
const request: ManagedIdentityRequestParameters =
|
||||
new ManagedIdentityRequestParameters(
|
||||
HttpMethod.GET,
|
||||
this.identityEndpoint
|
||||
);
|
||||
|
||||
request.headers[ManagedIdentityHeaders.ML_AND_SF_SECRET_HEADER_NAME] =
|
||||
this.identityHeader;
|
||||
|
||||
request.queryParameters[ManagedIdentityQueryParameters.API_VERSION] =
|
||||
SERVICE_FABRIC_MSI_API_VERSION;
|
||||
request.queryParameters[ManagedIdentityQueryParameters.RESOURCE] =
|
||||
resource;
|
||||
|
||||
if (
|
||||
managedIdentityId.idType !== ManagedIdentityIdType.SYSTEM_ASSIGNED
|
||||
) {
|
||||
request.queryParameters[
|
||||
this.getManagedIdentityUserAssignedIdQueryParameterKey(
|
||||
managedIdentityId.idType
|
||||
)
|
||||
] = managedIdentityId.id;
|
||||
}
|
||||
|
||||
// bodyParameters calculated in BaseManagedIdentity.acquireTokenWithManagedIdentity
|
||||
|
||||
return request;
|
||||
}
|
||||
}
|
||||
415
backend/node_modules/@azure/msal-node/src/client/OnBehalfOfClient.ts
generated
vendored
Normal file
415
backend/node_modules/@azure/msal-node/src/client/OnBehalfOfClient.ts
generated
vendored
Normal file
@ -0,0 +1,415 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import {
|
||||
AADServerParamKeys,
|
||||
AccessTokenEntity,
|
||||
AccountEntity,
|
||||
AccountInfo,
|
||||
AuthenticationResult,
|
||||
Authority,
|
||||
AuthToken,
|
||||
ClientAuthErrorCodes,
|
||||
ClientConfiguration,
|
||||
createClientAuthError,
|
||||
CredentialFilter,
|
||||
Constants,
|
||||
IdTokenEntity,
|
||||
RequestParameterBuilder,
|
||||
RequestThumbprint,
|
||||
ResponseHandler,
|
||||
ScopeSet,
|
||||
TimeUtils,
|
||||
TokenClaims,
|
||||
UrlString,
|
||||
ClientAssertion,
|
||||
getClientAssertion,
|
||||
UrlUtils,
|
||||
} from "@azure/msal-common/node";
|
||||
import { ApiId } from "../utils/Constants.js";
|
||||
import { EncodingUtils } from "../utils/EncodingUtils.js";
|
||||
import { CommonOnBehalfOfRequest } from "../request/CommonOnBehalfOfRequest.js";
|
||||
import { BaseClient } from "./BaseClient.js";
|
||||
|
||||
/**
|
||||
* On-Behalf-Of client
|
||||
* @public
|
||||
*/
|
||||
export class OnBehalfOfClient extends BaseClient {
|
||||
private scopeSet: ScopeSet;
|
||||
private userAssertionHash: string;
|
||||
|
||||
constructor(configuration: ClientConfiguration) {
|
||||
super(configuration);
|
||||
}
|
||||
|
||||
/**
|
||||
* Public API to acquire tokens with on behalf of flow
|
||||
* @param request - developer provided CommonOnBehalfOfRequest
|
||||
*/
|
||||
public async acquireToken(
|
||||
request: CommonOnBehalfOfRequest
|
||||
): Promise<AuthenticationResult | null> {
|
||||
this.scopeSet = new ScopeSet(request.scopes || []);
|
||||
|
||||
// generate the user_assertion_hash for OBOAssertion
|
||||
this.userAssertionHash = await this.cryptoUtils.hashString(
|
||||
request.oboAssertion
|
||||
);
|
||||
|
||||
if (request.skipCache || request.claims) {
|
||||
return this.executeTokenRequest(
|
||||
request,
|
||||
this.authority,
|
||||
this.userAssertionHash
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
return await this.getCachedAuthenticationResult(request);
|
||||
} catch (e) {
|
||||
// Any failure falls back to interactive request, once we implement distributed cache, we plan to handle `createRefreshRequiredError` to refresh using the RT
|
||||
return await this.executeTokenRequest(
|
||||
request,
|
||||
this.authority,
|
||||
this.userAssertionHash
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* look up cache for tokens
|
||||
* Find idtoken in the cache
|
||||
* Find accessToken based on user assertion and account info in the cache
|
||||
* Please note we are not yet supported OBO tokens refreshed with long lived RT. User will have to send a new assertion if the current access token expires
|
||||
* This is to prevent security issues when the assertion changes over time, however, longlived RT helps retaining the session
|
||||
* @param request - developer provided CommonOnBehalfOfRequest
|
||||
*/
|
||||
private async getCachedAuthenticationResult(
|
||||
request: CommonOnBehalfOfRequest
|
||||
): Promise<AuthenticationResult | null> {
|
||||
// look in the cache for the access_token which matches the incoming_assertion
|
||||
const cachedAccessToken = this.readAccessTokenFromCacheForOBO(
|
||||
this.config.authOptions.clientId,
|
||||
request
|
||||
);
|
||||
if (!cachedAccessToken) {
|
||||
// Must refresh due to non-existent access_token.
|
||||
this.serverTelemetryManager?.setCacheOutcome(
|
||||
Constants.CacheOutcome.NO_CACHED_ACCESS_TOKEN
|
||||
);
|
||||
this.logger.info(
|
||||
"SilentFlowClient:acquireCachedToken - No access token found in cache for the given properties.",
|
||||
request.correlationId
|
||||
);
|
||||
throw createClientAuthError(
|
||||
ClientAuthErrorCodes.tokenRefreshRequired
|
||||
);
|
||||
} else if (
|
||||
TimeUtils.isTokenExpired(
|
||||
cachedAccessToken.expiresOn,
|
||||
this.config.systemOptions.tokenRenewalOffsetSeconds
|
||||
)
|
||||
) {
|
||||
// Access token expired, will need to renewed
|
||||
this.serverTelemetryManager?.setCacheOutcome(
|
||||
Constants.CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED
|
||||
);
|
||||
this.logger.info(
|
||||
`OnbehalfofFlow:getCachedAuthenticationResult - Cached access token is expired or will expire within ${this.config.systemOptions.tokenRenewalOffsetSeconds} seconds.`,
|
||||
request.correlationId
|
||||
);
|
||||
throw createClientAuthError(
|
||||
ClientAuthErrorCodes.tokenRefreshRequired
|
||||
);
|
||||
}
|
||||
|
||||
// fetch the idToken from cache
|
||||
const cachedIdToken = this.readIdTokenFromCacheForOBO(
|
||||
cachedAccessToken.homeAccountId,
|
||||
request.correlationId
|
||||
);
|
||||
let idTokenClaims: TokenClaims | undefined;
|
||||
let cachedAccount: AccountEntity | null = null;
|
||||
if (cachedIdToken) {
|
||||
idTokenClaims = AuthToken.extractTokenClaims(
|
||||
cachedIdToken.secret,
|
||||
EncodingUtils.base64Decode
|
||||
);
|
||||
const localAccountId = idTokenClaims.oid || idTokenClaims.sub;
|
||||
const accountInfo: AccountInfo = {
|
||||
homeAccountId: cachedIdToken.homeAccountId,
|
||||
environment: cachedIdToken.environment,
|
||||
tenantId: cachedIdToken.realm,
|
||||
username: "",
|
||||
localAccountId: localAccountId || "",
|
||||
};
|
||||
|
||||
cachedAccount = this.cacheManager.getAccount(
|
||||
this.cacheManager.generateAccountKey(accountInfo),
|
||||
request.correlationId
|
||||
);
|
||||
}
|
||||
|
||||
// increment telemetry cache hit counter
|
||||
if (this.config.serverTelemetryManager) {
|
||||
this.config.serverTelemetryManager.incrementCacheHits();
|
||||
}
|
||||
|
||||
return ResponseHandler.generateAuthenticationResult(
|
||||
this.cryptoUtils,
|
||||
this.authority,
|
||||
{
|
||||
account: cachedAccount,
|
||||
accessToken: cachedAccessToken,
|
||||
idToken: cachedIdToken,
|
||||
refreshToken: null,
|
||||
appMetadata: null,
|
||||
},
|
||||
true,
|
||||
request,
|
||||
this.performanceClient,
|
||||
idTokenClaims
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* read idtoken from cache, this is a specific implementation for OBO as the requirements differ from a generic lookup in the cacheManager
|
||||
* Certain use cases of OBO flow do not expect an idToken in the cache/or from the service
|
||||
* @param atHomeAccountId - account id
|
||||
*/
|
||||
private readIdTokenFromCacheForOBO(
|
||||
atHomeAccountId: string,
|
||||
correlationId: string
|
||||
): IdTokenEntity | null {
|
||||
const idTokenFilter: CredentialFilter = {
|
||||
homeAccountId: atHomeAccountId,
|
||||
environment:
|
||||
this.authority.canonicalAuthorityUrlComponents.HostNameAndPort,
|
||||
credentialType: Constants.CredentialType.ID_TOKEN,
|
||||
clientId: this.config.authOptions.clientId,
|
||||
realm: this.authority.tenant,
|
||||
};
|
||||
|
||||
const idTokenMap: Map<string, IdTokenEntity> =
|
||||
this.cacheManager.getIdTokensByFilter(idTokenFilter, correlationId);
|
||||
|
||||
// When acquiring a token on behalf of an application, there might not be an id token in the cache
|
||||
if (Object.values(idTokenMap).length < 1) {
|
||||
return null;
|
||||
}
|
||||
return Object.values(idTokenMap)[0] as IdTokenEntity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the cached access token based on incoming assertion
|
||||
* @param clientId - client id
|
||||
* @param request - developer provided CommonOnBehalfOfRequest
|
||||
*/
|
||||
private readAccessTokenFromCacheForOBO(
|
||||
clientId: string,
|
||||
request: CommonOnBehalfOfRequest
|
||||
) {
|
||||
const authScheme =
|
||||
request.authenticationScheme ||
|
||||
Constants.AuthenticationScheme.BEARER;
|
||||
/*
|
||||
* Distinguish between Bearer and PoP/SSH token cache types
|
||||
* Cast to lowercase to handle "bearer" from ADFS
|
||||
*/
|
||||
const credentialType =
|
||||
authScheme &&
|
||||
authScheme.toLowerCase() !==
|
||||
Constants.AuthenticationScheme.BEARER.toLowerCase()
|
||||
? Constants.CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME
|
||||
: Constants.CredentialType.ACCESS_TOKEN;
|
||||
|
||||
const accessTokenFilter: CredentialFilter = {
|
||||
credentialType: credentialType,
|
||||
clientId,
|
||||
target: ScopeSet.createSearchScopes(this.scopeSet.asArray()),
|
||||
tokenType: authScheme,
|
||||
keyId: request.sshKid,
|
||||
userAssertionHash: this.userAssertionHash,
|
||||
};
|
||||
|
||||
const accessTokens = this.cacheManager.getAccessTokensByFilter(
|
||||
accessTokenFilter,
|
||||
request.correlationId
|
||||
);
|
||||
|
||||
const numAccessTokens = accessTokens.length;
|
||||
if (numAccessTokens < 1) {
|
||||
return null;
|
||||
} else if (numAccessTokens > 1) {
|
||||
throw createClientAuthError(
|
||||
ClientAuthErrorCodes.multipleMatchingTokens
|
||||
);
|
||||
}
|
||||
|
||||
return accessTokens[0] as AccessTokenEntity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a network call to the server requesting credentials
|
||||
* @param request - developer provided CommonOnBehalfOfRequest
|
||||
* @param authority - authority object
|
||||
*/
|
||||
private async executeTokenRequest(
|
||||
request: CommonOnBehalfOfRequest,
|
||||
authority: Authority,
|
||||
userAssertionHash: string
|
||||
): Promise<AuthenticationResult | null> {
|
||||
const queryParametersString = this.createTokenQueryParameters(request);
|
||||
const endpoint = UrlString.appendQueryString(
|
||||
authority.tokenEndpoint,
|
||||
queryParametersString
|
||||
);
|
||||
const requestBody = await this.createTokenRequestBody(request);
|
||||
const headers: Record<string, string> =
|
||||
this.createTokenRequestHeaders();
|
||||
const thumbprint: RequestThumbprint = {
|
||||
clientId: this.config.authOptions.clientId,
|
||||
authority: request.authority,
|
||||
scopes: request.scopes,
|
||||
claims: request.claims,
|
||||
authenticationScheme: request.authenticationScheme,
|
||||
resourceRequestMethod: request.resourceRequestMethod,
|
||||
resourceRequestUri: request.resourceRequestUri,
|
||||
shrClaims: request.shrClaims,
|
||||
sshKid: request.sshKid,
|
||||
};
|
||||
|
||||
const reqTimestamp = TimeUtils.nowSeconds();
|
||||
const response = await this.executePostToTokenEndpoint(
|
||||
endpoint,
|
||||
requestBody,
|
||||
headers,
|
||||
thumbprint,
|
||||
request.correlationId
|
||||
);
|
||||
|
||||
const responseHandler = new ResponseHandler(
|
||||
this.config.authOptions.clientId,
|
||||
this.cacheManager,
|
||||
this.cryptoUtils,
|
||||
this.logger,
|
||||
this.performanceClient,
|
||||
this.config.serializableCache,
|
||||
this.config.persistencePlugin
|
||||
);
|
||||
|
||||
responseHandler.validateTokenResponse(
|
||||
response.body,
|
||||
request.correlationId
|
||||
);
|
||||
const tokenResponse = await responseHandler.handleServerTokenResponse(
|
||||
response.body,
|
||||
this.authority,
|
||||
reqTimestamp,
|
||||
request,
|
||||
ApiId.acquireTokenByOBO,
|
||||
undefined,
|
||||
userAssertionHash
|
||||
);
|
||||
|
||||
return tokenResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* generate a server request in accepable format
|
||||
* @param request - developer provided CommonOnBehalfOfRequest
|
||||
*/
|
||||
private async createTokenRequestBody(
|
||||
request: CommonOnBehalfOfRequest
|
||||
): Promise<string> {
|
||||
const parameters = new Map<string, string>();
|
||||
|
||||
RequestParameterBuilder.addClientId(
|
||||
parameters,
|
||||
this.config.authOptions.clientId
|
||||
);
|
||||
|
||||
RequestParameterBuilder.addScopes(parameters, request.scopes);
|
||||
|
||||
RequestParameterBuilder.addGrantType(
|
||||
parameters,
|
||||
Constants.GrantType.JWT_BEARER
|
||||
);
|
||||
|
||||
RequestParameterBuilder.addClientInfo(parameters);
|
||||
|
||||
RequestParameterBuilder.addLibraryInfo(
|
||||
parameters,
|
||||
this.config.libraryInfo
|
||||
);
|
||||
RequestParameterBuilder.addApplicationTelemetry(
|
||||
parameters,
|
||||
this.config.telemetry.application
|
||||
);
|
||||
RequestParameterBuilder.addThrottling(parameters);
|
||||
|
||||
if (this.serverTelemetryManager) {
|
||||
RequestParameterBuilder.addServerTelemetry(
|
||||
parameters,
|
||||
this.serverTelemetryManager
|
||||
);
|
||||
}
|
||||
|
||||
const correlationId =
|
||||
request.correlationId ||
|
||||
this.config.cryptoInterface.createNewGuid();
|
||||
RequestParameterBuilder.addCorrelationId(parameters, correlationId);
|
||||
|
||||
RequestParameterBuilder.addRequestTokenUse(
|
||||
parameters,
|
||||
AADServerParamKeys.ON_BEHALF_OF
|
||||
);
|
||||
|
||||
RequestParameterBuilder.addOboAssertion(
|
||||
parameters,
|
||||
request.oboAssertion
|
||||
);
|
||||
|
||||
if (this.config.clientCredentials.clientSecret) {
|
||||
RequestParameterBuilder.addClientSecret(
|
||||
parameters,
|
||||
this.config.clientCredentials.clientSecret
|
||||
);
|
||||
}
|
||||
|
||||
const clientAssertion: ClientAssertion | undefined =
|
||||
this.config.clientCredentials.clientAssertion;
|
||||
|
||||
if (clientAssertion) {
|
||||
RequestParameterBuilder.addClientAssertion(
|
||||
parameters,
|
||||
await getClientAssertion(
|
||||
clientAssertion.assertion,
|
||||
this.config.authOptions.clientId,
|
||||
request.resourceRequestUri
|
||||
)
|
||||
);
|
||||
RequestParameterBuilder.addClientAssertionType(
|
||||
parameters,
|
||||
clientAssertion.assertionType
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
request.claims ||
|
||||
(this.config.authOptions.clientCapabilities &&
|
||||
this.config.authOptions.clientCapabilities.length > 0)
|
||||
) {
|
||||
RequestParameterBuilder.addClaims(
|
||||
parameters,
|
||||
request.claims,
|
||||
this.config.authOptions.clientCapabilities
|
||||
);
|
||||
}
|
||||
|
||||
return UrlUtils.mapToQueryString(parameters);
|
||||
}
|
||||
}
|
||||
405
backend/node_modules/@azure/msal-node/src/client/PublicClientApplication.ts
generated
vendored
Normal file
405
backend/node_modules/@azure/msal-node/src/client/PublicClientApplication.ts
generated
vendored
Normal file
@ -0,0 +1,405 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import {
|
||||
ApiId,
|
||||
Constants,
|
||||
LOOPBACK_SERVER_CONSTANTS,
|
||||
} from "../utils/Constants.js";
|
||||
import {
|
||||
AuthenticationResult,
|
||||
AuthError,
|
||||
Constants as CommonConstants,
|
||||
ServerError,
|
||||
NativeRequest,
|
||||
NativeSignOutRequest,
|
||||
AccountInfo,
|
||||
INativeBrokerPlugin,
|
||||
AuthorizeResponse,
|
||||
AADServerParamKeys,
|
||||
ServerTelemetryManager,
|
||||
AuthorizationCodePayload,
|
||||
enforceResourceParameter,
|
||||
} from "@azure/msal-common/node";
|
||||
import { Configuration } from "../config/Configuration.js";
|
||||
import { ClientApplication } from "./ClientApplication.js";
|
||||
import { IPublicClientApplication } from "./IPublicClientApplication.js";
|
||||
import { DeviceCodeRequest } from "../request/DeviceCodeRequest.js";
|
||||
import { CommonDeviceCodeRequest } from "../request/CommonDeviceCodeRequest.js";
|
||||
import { AuthorizationUrlRequest } from "../request/AuthorizationUrlRequest.js";
|
||||
import { AuthorizationCodeRequest } from "../request/AuthorizationCodeRequest.js";
|
||||
import { InteractiveRequest } from "../request/InteractiveRequest.js";
|
||||
import { NodeAuthError, NodeAuthErrorMessage } from "../error/NodeAuthError.js";
|
||||
import { LoopbackClient } from "../network/LoopbackClient.js";
|
||||
import { SilentFlowRequest } from "../request/SilentFlowRequest.js";
|
||||
import { SignOutRequest } from "../request/SignOutRequest.js";
|
||||
import { RefreshTokenRequest } from "../request/RefreshTokenRequest.js";
|
||||
import { ILoopbackClient } from "../network/ILoopbackClient.js";
|
||||
import { DeviceCodeClient } from "./DeviceCodeClient.js";
|
||||
import { version } from "../packageMetadata.js";
|
||||
|
||||
/**
|
||||
* This class is to be used to acquire tokens for public client applications (desktop, mobile). Public client applications
|
||||
* are not trusted to safely store application secrets, and therefore can only request tokens in the name of an user.
|
||||
* @public
|
||||
*/
|
||||
export class PublicClientApplication
|
||||
extends ClientApplication
|
||||
implements IPublicClientApplication
|
||||
{
|
||||
private nativeBrokerPlugin?: INativeBrokerPlugin;
|
||||
private readonly skus: string;
|
||||
/**
|
||||
* Important attributes in the Configuration object for auth are:
|
||||
* - clientID: the application ID of your application. You can obtain one by registering your application with our Application registration portal.
|
||||
* - authority: the authority URL for your application.
|
||||
*
|
||||
* AAD authorities are of the form https://login.microsoftonline.com/\{Enter_the_Tenant_Info_Here\}.
|
||||
* - If your application supports Accounts in one organizational directory, replace "Enter_the_Tenant_Info_Here" value with the Tenant Id or Tenant name (for example, contoso.microsoft.com).
|
||||
* - If your application supports Accounts in any organizational directory, replace "Enter_the_Tenant_Info_Here" value with organizations.
|
||||
* - If your application supports Accounts in any organizational directory and personal Microsoft accounts, replace "Enter_the_Tenant_Info_Here" value with common.
|
||||
* - To restrict support to Personal Microsoft accounts only, replace "Enter_the_Tenant_Info_Here" value with consumers.
|
||||
*
|
||||
* Azure B2C authorities are of the form https://\{instance\}/\{tenant\}/\{policy\}. Each policy is considered
|
||||
* its own authority. You will have to set the all of the knownAuthorities at the time of the client application
|
||||
* construction.
|
||||
*
|
||||
* ADFS authorities are of the form https://\{instance\}/adfs.
|
||||
*/
|
||||
constructor(configuration: Configuration) {
|
||||
super(configuration);
|
||||
if (this.config.broker.nativeBrokerPlugin) {
|
||||
if (this.config.broker.nativeBrokerPlugin.isBrokerAvailable) {
|
||||
this.nativeBrokerPlugin = this.config.broker.nativeBrokerPlugin;
|
||||
this.nativeBrokerPlugin.setLogger(
|
||||
this.config.system.loggerOptions
|
||||
);
|
||||
} else {
|
||||
this.logger.warning(
|
||||
"NativeBroker implementation was provided but the broker is unavailable.",
|
||||
""
|
||||
);
|
||||
}
|
||||
}
|
||||
this.skus = ServerTelemetryManager.makeExtraSkuString({
|
||||
libraryName: Constants.MSAL_SKU,
|
||||
libraryVersion: version,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Acquires a token from the authority using OAuth2.0 device code flow.
|
||||
* This flow is designed for devices that do not have access to a browser or have input constraints.
|
||||
* The authorization server issues a DeviceCode object with a verification code, an end-user code,
|
||||
* and the end-user verification URI. The DeviceCode object is provided through a callback, and the end-user should be
|
||||
* instructed to use another device to navigate to the verification URI to input credentials.
|
||||
* Since the client cannot receive incoming requests, it polls the authorization server repeatedly
|
||||
* until the end-user completes input of credentials.
|
||||
*/
|
||||
public async acquireTokenByDeviceCode(
|
||||
request: DeviceCodeRequest
|
||||
): Promise<AuthenticationResult | null> {
|
||||
this.logger.info(
|
||||
"acquireTokenByDeviceCode called",
|
||||
request.correlationId || ""
|
||||
);
|
||||
enforceResourceParameter(this.config.auth.isMcp, request);
|
||||
const validRequest: CommonDeviceCodeRequest = Object.assign(
|
||||
request,
|
||||
await this.initializeBaseRequest(request)
|
||||
);
|
||||
const serverTelemetryManager = this.initializeServerTelemetryManager(
|
||||
ApiId.acquireTokenByDeviceCode,
|
||||
validRequest.correlationId
|
||||
);
|
||||
try {
|
||||
const discoveredAuthority = await this.createAuthority(
|
||||
validRequest.authority,
|
||||
validRequest.correlationId,
|
||||
undefined,
|
||||
request.azureCloudOptions
|
||||
);
|
||||
const deviceCodeConfig = await this.buildOauthClientConfiguration(
|
||||
discoveredAuthority,
|
||||
validRequest.correlationId,
|
||||
"",
|
||||
serverTelemetryManager
|
||||
);
|
||||
const deviceCodeClient = new DeviceCodeClient(deviceCodeConfig);
|
||||
this.logger.verbose(
|
||||
"Device code client created",
|
||||
validRequest.correlationId
|
||||
);
|
||||
return await deviceCodeClient.acquireToken(validRequest);
|
||||
} catch (e) {
|
||||
if (e instanceof AuthError) {
|
||||
e.setCorrelationId(validRequest.correlationId);
|
||||
}
|
||||
serverTelemetryManager.cacheFailedRequest(e as AuthError);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Acquires a token interactively via the browser by requesting an authorization code then exchanging it for a token.
|
||||
*/
|
||||
async acquireTokenInteractive(
|
||||
request: InteractiveRequest
|
||||
): Promise<AuthenticationResult> {
|
||||
const correlationId =
|
||||
request.correlationId || this.cryptoProvider.createNewGuid();
|
||||
this.logger.trace("acquireTokenInteractive called", correlationId);
|
||||
enforceResourceParameter(this.config.auth.isMcp, request);
|
||||
const {
|
||||
openBrowser,
|
||||
successTemplate,
|
||||
errorTemplate,
|
||||
windowHandle,
|
||||
loopbackClient: customLoopbackClient,
|
||||
...remainingProperties
|
||||
} = request;
|
||||
|
||||
if (this.nativeBrokerPlugin) {
|
||||
const brokerRequest: NativeRequest = {
|
||||
...remainingProperties,
|
||||
clientId: this.config.auth.clientId,
|
||||
scopes: request.scopes || CommonConstants.OIDC_DEFAULT_SCOPES,
|
||||
redirectUri: request.redirectUri || "",
|
||||
authority: request.authority || this.config.auth.authority,
|
||||
correlationId: correlationId,
|
||||
extraParameters: {
|
||||
...remainingProperties.extraQueryParameters,
|
||||
...remainingProperties.extraParameters,
|
||||
[AADServerParamKeys.X_CLIENT_EXTRA_SKU]: this.skus,
|
||||
},
|
||||
accountId: remainingProperties.account?.nativeAccountId,
|
||||
};
|
||||
return this.nativeBrokerPlugin.acquireTokenInteractive(
|
||||
brokerRequest,
|
||||
windowHandle
|
||||
);
|
||||
}
|
||||
|
||||
if (request.redirectUri) {
|
||||
// If it's not a broker fallback scenario, we throw an error
|
||||
if (!this.config.broker.nativeBrokerPlugin) {
|
||||
throw NodeAuthError.createRedirectUriNotSupportedError();
|
||||
}
|
||||
// If a redirect URI is provided for a broker flow but MSAL runtime startup failed, we fall back to the browser flow and will ignore the redirect URI provided for the broker flow
|
||||
request.redirectUri = "";
|
||||
}
|
||||
|
||||
const { verifier, challenge } =
|
||||
await this.cryptoProvider.generatePkceCodes();
|
||||
|
||||
const loopbackClient: ILoopbackClient =
|
||||
customLoopbackClient || new LoopbackClient();
|
||||
|
||||
let authCodeResponse: AuthorizeResponse = {};
|
||||
let authCodeListenerError: AuthError | null = null;
|
||||
try {
|
||||
const authCodeListener = loopbackClient
|
||||
.listenForAuthCode(successTemplate, errorTemplate)
|
||||
.then((response) => {
|
||||
authCodeResponse = response;
|
||||
})
|
||||
.catch((e) => {
|
||||
// Store the promise instead of throwing so we can control when its thrown
|
||||
authCodeListenerError = e;
|
||||
});
|
||||
|
||||
// Wait for server to be listening
|
||||
const redirectUri = await this.waitForRedirectUri(loopbackClient);
|
||||
|
||||
const validRequest: AuthorizationUrlRequest = {
|
||||
...remainingProperties,
|
||||
correlationId: correlationId,
|
||||
scopes: request.scopes || CommonConstants.OIDC_DEFAULT_SCOPES,
|
||||
redirectUri: redirectUri,
|
||||
responseMode: CommonConstants.ResponseMode.QUERY,
|
||||
codeChallenge: challenge,
|
||||
codeChallengeMethod:
|
||||
CommonConstants.CodeChallengeMethodValues.S256,
|
||||
};
|
||||
|
||||
const authCodeUrl = await this.getAuthCodeUrl(validRequest);
|
||||
await openBrowser(authCodeUrl);
|
||||
await authCodeListener;
|
||||
if (authCodeListenerError) {
|
||||
throw authCodeListenerError;
|
||||
}
|
||||
|
||||
if (authCodeResponse.error) {
|
||||
throw new ServerError(
|
||||
authCodeResponse.error,
|
||||
authCodeResponse.error_description,
|
||||
authCodeResponse.suberror
|
||||
);
|
||||
} else if (!authCodeResponse.code) {
|
||||
throw NodeAuthError.createNoAuthCodeInResponseError();
|
||||
}
|
||||
|
||||
const clientInfo = authCodeResponse.client_info;
|
||||
const tokenRequest: AuthorizationCodeRequest = {
|
||||
code: authCodeResponse.code,
|
||||
codeVerifier: verifier,
|
||||
clientInfo: clientInfo || "",
|
||||
...validRequest,
|
||||
};
|
||||
return await this.acquireTokenByCode(tokenRequest); // Await this so the server doesn't close prematurely
|
||||
} finally {
|
||||
loopbackClient.closeServer();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a token retrieved either from the cache or by exchanging the refresh token for a fresh access token. If brokering is enabled the token request will be serviced by the broker.
|
||||
* @param request - developer provided SilentFlowRequest
|
||||
* @returns
|
||||
*/
|
||||
async acquireTokenSilent(
|
||||
request: SilentFlowRequest
|
||||
): Promise<AuthenticationResult> {
|
||||
const correlationId =
|
||||
request.correlationId || this.cryptoProvider.createNewGuid();
|
||||
this.logger.trace("acquireTokenSilent called", correlationId);
|
||||
enforceResourceParameter(this.config.auth.isMcp, request);
|
||||
|
||||
if (this.nativeBrokerPlugin) {
|
||||
const brokerRequest: NativeRequest = {
|
||||
...request,
|
||||
clientId: this.config.auth.clientId,
|
||||
scopes: request.scopes || CommonConstants.OIDC_DEFAULT_SCOPES,
|
||||
redirectUri: request.redirectUri || "",
|
||||
authority: request.authority || this.config.auth.authority,
|
||||
correlationId: correlationId,
|
||||
extraParameters: {
|
||||
...request.extraQueryParameters,
|
||||
...request.extraParameters,
|
||||
[AADServerParamKeys.X_CLIENT_EXTRA_SKU]: this.skus,
|
||||
},
|
||||
accountId: request.account.nativeAccountId,
|
||||
forceRefresh: request.forceRefresh || false,
|
||||
};
|
||||
return this.nativeBrokerPlugin.acquireTokenSilent(brokerRequest);
|
||||
}
|
||||
|
||||
if (request.redirectUri) {
|
||||
// If it's not a broker fallback scenario, we throw an error
|
||||
if (!this.config.broker.nativeBrokerPlugin) {
|
||||
throw NodeAuthError.createRedirectUriNotSupportedError();
|
||||
}
|
||||
request.redirectUri = "";
|
||||
}
|
||||
|
||||
return super.acquireTokenSilent(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Acquires a token by exchanging the authorization code received from the first step of OAuth 2.0 Authorization Code Flow.
|
||||
* In MCP mode, a resource parameter is required on the request.
|
||||
*/
|
||||
async acquireTokenByCode(
|
||||
request: AuthorizationCodeRequest,
|
||||
authCodePayLoad?: AuthorizationCodePayload
|
||||
): Promise<AuthenticationResult> {
|
||||
enforceResourceParameter(this.config.auth.isMcp, request);
|
||||
return super.acquireTokenByCode(request, authCodePayLoad);
|
||||
}
|
||||
|
||||
/**
|
||||
* Acquires a token by exchanging the refresh token provided for a new set of tokens.
|
||||
* In MCP mode, a resource parameter is required on the request.
|
||||
*/
|
||||
async acquireTokenByRefreshToken(
|
||||
request: RefreshTokenRequest
|
||||
): Promise<AuthenticationResult | null> {
|
||||
enforceResourceParameter(this.config.auth.isMcp, request);
|
||||
return super.acquireTokenByRefreshToken(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes cache artifacts associated with the given account
|
||||
* @param request - developer provided SignOutRequest
|
||||
* @returns
|
||||
*/
|
||||
async signOut(request: SignOutRequest): Promise<void> {
|
||||
if (this.nativeBrokerPlugin && request.account.nativeAccountId) {
|
||||
const signoutRequest: NativeSignOutRequest = {
|
||||
clientId: this.config.auth.clientId,
|
||||
accountId: request.account.nativeAccountId,
|
||||
correlationId:
|
||||
request.correlationId ||
|
||||
this.cryptoProvider.createNewGuid(),
|
||||
};
|
||||
await this.nativeBrokerPlugin.signOut(signoutRequest);
|
||||
}
|
||||
|
||||
await this.getTokenCache().removeAccount(
|
||||
request.account,
|
||||
request.correlationId
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all cached accounts for this application. If brokering is enabled this request will be serviced by the broker.
|
||||
* @returns
|
||||
*/
|
||||
async getAllAccounts(): Promise<AccountInfo[]> {
|
||||
if (this.nativeBrokerPlugin) {
|
||||
const correlationId = this.cryptoProvider.createNewGuid();
|
||||
return this.nativeBrokerPlugin.getAllAccounts(
|
||||
this.config.auth.clientId,
|
||||
correlationId
|
||||
);
|
||||
}
|
||||
|
||||
return this.getTokenCache().getAllAccounts();
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to retrieve the redirectUri from the loopback server. If the loopback server does not start listening for requests within the timeout this will throw.
|
||||
* @param loopbackClient - developer provided custom loopback server implementation
|
||||
* @returns
|
||||
*/
|
||||
private async waitForRedirectUri(
|
||||
loopbackClient: ILoopbackClient
|
||||
): Promise<string> {
|
||||
return new Promise<string>((resolve, reject) => {
|
||||
let ticks = 0;
|
||||
const id = setInterval(() => {
|
||||
if (
|
||||
LOOPBACK_SERVER_CONSTANTS.TIMEOUT_MS /
|
||||
LOOPBACK_SERVER_CONSTANTS.INTERVAL_MS <
|
||||
ticks
|
||||
) {
|
||||
clearInterval(id);
|
||||
reject(NodeAuthError.createLoopbackServerTimeoutError());
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const r = loopbackClient.getRedirectUri();
|
||||
clearInterval(id);
|
||||
resolve(r);
|
||||
return;
|
||||
} catch (e) {
|
||||
if (
|
||||
e instanceof AuthError &&
|
||||
e.errorCode ===
|
||||
NodeAuthErrorMessage.noLoopbackServerExists.code
|
||||
) {
|
||||
// Loopback server is not listening yet
|
||||
ticks++;
|
||||
return;
|
||||
}
|
||||
clearInterval(id);
|
||||
reject(e);
|
||||
return;
|
||||
}
|
||||
}, LOOPBACK_SERVER_CONSTANTS.INTERVAL_MS);
|
||||
});
|
||||
}
|
||||
}
|
||||
221
backend/node_modules/@azure/msal-node/src/client/UsernamePasswordClient.ts
generated
vendored
Normal file
221
backend/node_modules/@azure/msal-node/src/client/UsernamePasswordClient.ts
generated
vendored
Normal file
@ -0,0 +1,221 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import {
|
||||
AuthenticationResult,
|
||||
Authority,
|
||||
CcsCredentialType,
|
||||
ClientAssertion,
|
||||
ClientConfiguration,
|
||||
NetworkResponse,
|
||||
Constants,
|
||||
RequestParameterBuilder,
|
||||
RequestThumbprint,
|
||||
ResponseHandler,
|
||||
ServerAuthorizationTokenResponse,
|
||||
StringUtils,
|
||||
TimeUtils,
|
||||
UrlString,
|
||||
UrlUtils,
|
||||
getClientAssertion,
|
||||
} from "@azure/msal-common/node";
|
||||
import { ApiId } from "../utils/Constants.js";
|
||||
import { CommonUsernamePasswordRequest } from "../request/CommonUsernamePasswordRequest.js";
|
||||
import { BaseClient } from "./BaseClient.js";
|
||||
|
||||
/**
|
||||
* Oauth2.0 Password grant client
|
||||
* Note: We are only supporting public clients for password grant and for purely testing purposes
|
||||
* @public
|
||||
* @deprecated - Use a more secure flow instead
|
||||
*/
|
||||
export class UsernamePasswordClient extends BaseClient {
|
||||
constructor(configuration: ClientConfiguration) {
|
||||
super(configuration);
|
||||
}
|
||||
|
||||
/**
|
||||
* API to acquire a token by passing the username and password to the service in exchage of credentials
|
||||
* password_grant
|
||||
* @param request - CommonUsernamePasswordRequest
|
||||
*/
|
||||
async acquireToken(
|
||||
request: CommonUsernamePasswordRequest
|
||||
): Promise<AuthenticationResult | null> {
|
||||
this.logger.info(
|
||||
"in acquireToken call in username-password client",
|
||||
request.correlationId
|
||||
);
|
||||
|
||||
const reqTimestamp = TimeUtils.nowSeconds();
|
||||
const response = await this.executeTokenRequest(
|
||||
this.authority,
|
||||
request
|
||||
);
|
||||
|
||||
const responseHandler = new ResponseHandler(
|
||||
this.config.authOptions.clientId,
|
||||
this.cacheManager,
|
||||
this.cryptoUtils,
|
||||
this.logger,
|
||||
this.performanceClient,
|
||||
this.config.serializableCache,
|
||||
this.config.persistencePlugin
|
||||
);
|
||||
|
||||
// Validate response. This function throws a server error if an error is returned by the server.
|
||||
responseHandler.validateTokenResponse(
|
||||
response.body,
|
||||
request.correlationId
|
||||
);
|
||||
const tokenResponse = responseHandler.handleServerTokenResponse(
|
||||
response.body,
|
||||
this.authority,
|
||||
reqTimestamp,
|
||||
request,
|
||||
ApiId.acquireTokenByUsernamePassword
|
||||
);
|
||||
|
||||
return tokenResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes POST request to token endpoint
|
||||
* @param authority - authority object
|
||||
* @param request - CommonUsernamePasswordRequest provided by the developer
|
||||
*/
|
||||
private async executeTokenRequest(
|
||||
authority: Authority,
|
||||
request: CommonUsernamePasswordRequest
|
||||
): Promise<NetworkResponse<ServerAuthorizationTokenResponse>> {
|
||||
const queryParametersString = this.createTokenQueryParameters(request);
|
||||
const endpoint = UrlString.appendQueryString(
|
||||
authority.tokenEndpoint,
|
||||
queryParametersString
|
||||
);
|
||||
const requestBody = await this.createTokenRequestBody(request);
|
||||
const headers: Record<string, string> = this.createTokenRequestHeaders({
|
||||
credential: request.username,
|
||||
type: CcsCredentialType.UPN,
|
||||
});
|
||||
const thumbprint: RequestThumbprint = {
|
||||
clientId: this.config.authOptions.clientId,
|
||||
authority: authority.canonicalAuthority,
|
||||
scopes: request.scopes,
|
||||
claims: request.claims,
|
||||
authenticationScheme: request.authenticationScheme,
|
||||
resourceRequestMethod: request.resourceRequestMethod,
|
||||
resourceRequestUri: request.resourceRequestUri,
|
||||
shrClaims: request.shrClaims,
|
||||
sshKid: request.sshKid,
|
||||
};
|
||||
|
||||
return this.executePostToTokenEndpoint(
|
||||
endpoint,
|
||||
requestBody,
|
||||
headers,
|
||||
thumbprint,
|
||||
request.correlationId
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a map for all the params to be sent to the service
|
||||
* @param request - CommonUsernamePasswordRequest provided by the developer
|
||||
*/
|
||||
private async createTokenRequestBody(
|
||||
request: CommonUsernamePasswordRequest
|
||||
): Promise<string> {
|
||||
const parameters = new Map<string, string>();
|
||||
|
||||
RequestParameterBuilder.addClientId(
|
||||
parameters,
|
||||
this.config.authOptions.clientId
|
||||
);
|
||||
RequestParameterBuilder.addUsername(parameters, request.username);
|
||||
RequestParameterBuilder.addPassword(parameters, request.password);
|
||||
|
||||
RequestParameterBuilder.addScopes(parameters, request.scopes);
|
||||
|
||||
RequestParameterBuilder.addResponseType(
|
||||
parameters,
|
||||
Constants.OAuthResponseType.IDTOKEN_TOKEN
|
||||
);
|
||||
|
||||
RequestParameterBuilder.addGrantType(
|
||||
parameters,
|
||||
Constants.GrantType.RESOURCE_OWNER_PASSWORD_GRANT
|
||||
);
|
||||
RequestParameterBuilder.addClientInfo(parameters);
|
||||
|
||||
RequestParameterBuilder.addLibraryInfo(
|
||||
parameters,
|
||||
this.config.libraryInfo
|
||||
);
|
||||
RequestParameterBuilder.addApplicationTelemetry(
|
||||
parameters,
|
||||
this.config.telemetry.application
|
||||
);
|
||||
RequestParameterBuilder.addThrottling(parameters);
|
||||
|
||||
if (this.serverTelemetryManager) {
|
||||
RequestParameterBuilder.addServerTelemetry(
|
||||
parameters,
|
||||
this.serverTelemetryManager
|
||||
);
|
||||
}
|
||||
|
||||
const correlationId =
|
||||
request.correlationId ||
|
||||
this.config.cryptoInterface.createNewGuid();
|
||||
RequestParameterBuilder.addCorrelationId(parameters, correlationId);
|
||||
|
||||
if (this.config.clientCredentials.clientSecret) {
|
||||
RequestParameterBuilder.addClientSecret(
|
||||
parameters,
|
||||
this.config.clientCredentials.clientSecret
|
||||
);
|
||||
}
|
||||
|
||||
const clientAssertion: ClientAssertion | undefined =
|
||||
this.config.clientCredentials.clientAssertion;
|
||||
|
||||
if (clientAssertion) {
|
||||
RequestParameterBuilder.addClientAssertion(
|
||||
parameters,
|
||||
await getClientAssertion(
|
||||
clientAssertion.assertion,
|
||||
this.config.authOptions.clientId,
|
||||
request.resourceRequestUri
|
||||
)
|
||||
);
|
||||
RequestParameterBuilder.addClientAssertionType(
|
||||
parameters,
|
||||
clientAssertion.assertionType
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
!StringUtils.isEmptyObj(request.claims) ||
|
||||
(this.config.authOptions.clientCapabilities &&
|
||||
this.config.authOptions.clientCapabilities.length > 0)
|
||||
) {
|
||||
RequestParameterBuilder.addClaims(
|
||||
parameters,
|
||||
request.claims,
|
||||
this.config.authOptions.clientCapabilities
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
this.config.systemOptions.preventCorsPreflight &&
|
||||
request.username
|
||||
) {
|
||||
RequestParameterBuilder.addCcsUpn(parameters, request.username);
|
||||
}
|
||||
|
||||
return UrlUtils.mapToQueryString(parameters);
|
||||
}
|
||||
}
|
||||
267
backend/node_modules/@azure/msal-node/src/config/Configuration.ts
generated
vendored
Normal file
267
backend/node_modules/@azure/msal-node/src/config/Configuration.ts
generated
vendored
Normal file
@ -0,0 +1,267 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import {
|
||||
LoggerOptions,
|
||||
INetworkModule,
|
||||
LogLevel,
|
||||
ProtocolMode,
|
||||
ICachePlugin,
|
||||
AzureCloudInstance,
|
||||
AzureCloudOptions,
|
||||
ApplicationTelemetry,
|
||||
INativeBrokerPlugin,
|
||||
ClientAssertionCallback,
|
||||
Constants,
|
||||
} from "@azure/msal-common/node";
|
||||
import { HttpClient } from "../network/HttpClient.js";
|
||||
import { ManagedIdentityId } from "./ManagedIdentityId.js";
|
||||
import { NodeAuthError } from "../error/NodeAuthError.js";
|
||||
|
||||
/**
|
||||
* - clientId - Client id of the application.
|
||||
* - authority - Url of the authority. If no value is set, defaults to https://login.microsoftonline.com/common.
|
||||
* - knownAuthorities - Needed for Azure B2C and ADFS. All authorities that will be used in the client application. Only the host of the authority should be passed in.
|
||||
* - clientSecret - Secret string that the application uses when requesting a token. Only used in confidential client applications. Can be created in the Azure app registration portal.
|
||||
* - clientAssertion - A ClientAssertion object containing an assertion string or a callback function that returns an assertion string that the application uses when requesting a token, as well as the assertion's type (urn:ietf:params:oauth:client-assertion-type:jwt-bearer). Only used in confidential client applications.
|
||||
* - clientCertificate - Certificate that the application uses when requesting a token. Only used in confidential client applications. Requires hex encoded X.509 SHA-1 or SHA-256 thumbprint of the certificate, and the PEM encoded private key (string should contain -----BEGIN PRIVATE KEY----- ... -----END PRIVATE KEY----- )
|
||||
* @public
|
||||
*/
|
||||
export type NodeAuthOptions = {
|
||||
clientId: string;
|
||||
authority?: string;
|
||||
clientSecret?: string;
|
||||
clientAssertion?: string | ClientAssertionCallback;
|
||||
clientCertificate?: {
|
||||
/**
|
||||
* @deprecated Use thumbprintSha2 property instead. Thumbprint needs to be computed with SHA-256 algorithm.
|
||||
* SHA-1 is only needed for backwards compatibility with older versions of ADFS.
|
||||
*/
|
||||
thumbprint?: string;
|
||||
thumbprintSha256?: string;
|
||||
privateKey: string;
|
||||
x5c?: string;
|
||||
};
|
||||
knownAuthorities?: Array<string>;
|
||||
cloudDiscoveryMetadata?: string;
|
||||
authorityMetadata?: string;
|
||||
clientCapabilities?: Array<string>;
|
||||
azureCloudOptions?: AzureCloudOptions;
|
||||
/**
|
||||
* Flag on whether a resource parameter is required for token requests. Used for MCP flows.
|
||||
*/
|
||||
isMcp?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
* Use this to configure the below cache configuration options:
|
||||
*
|
||||
* - cachePlugin - Plugin for reading and writing token cache to disk.
|
||||
* @public
|
||||
*/
|
||||
export type CacheOptions = {
|
||||
cachePlugin?: ICachePlugin;
|
||||
};
|
||||
|
||||
/**
|
||||
* Use this to configure the below broker options:
|
||||
* - nativeBrokerPlugin - Native broker implementation (should be imported from msal-node-extensions)
|
||||
*
|
||||
* Note: These options are only available for PublicClientApplications using the Authorization Code Flow
|
||||
* @public
|
||||
*/
|
||||
export type BrokerOptions = {
|
||||
nativeBrokerPlugin?: INativeBrokerPlugin;
|
||||
};
|
||||
|
||||
/**
|
||||
* Type for configuring logger and http client options
|
||||
*
|
||||
* - logger - Used to initialize the Logger object; TODO: Expand on logger details or link to the documentation on logger
|
||||
* - networkClient - Http client used for all http get and post calls. Defaults to using MSAL's default http client.
|
||||
* - protocolMode - Enum that represents the protocol that msal follows. Used for configuring proper endpoints.
|
||||
* @public
|
||||
*/
|
||||
export type NodeSystemOptions = {
|
||||
loggerOptions?: LoggerOptions;
|
||||
networkClient?: INetworkModule;
|
||||
disableInternalRetries?: boolean;
|
||||
protocolMode?: ProtocolMode;
|
||||
};
|
||||
|
||||
/** @public */
|
||||
export type NodeTelemetryOptions = {
|
||||
application?: ApplicationTelemetry;
|
||||
};
|
||||
|
||||
/**
|
||||
* Use the configuration object to configure MSAL and initialize the client application object
|
||||
*
|
||||
* - auth: this is where you configure auth elements like clientID, authority used for authenticating against the Microsoft Identity Platform
|
||||
* - broker: this is where you configure broker options
|
||||
* - cache: this is where you configure cache location
|
||||
* - system: this is where you can configure the network client, logger
|
||||
* - telemetry: this is where you can configure telemetry options
|
||||
* @public
|
||||
*/
|
||||
export type Configuration = {
|
||||
auth: NodeAuthOptions;
|
||||
broker?: BrokerOptions;
|
||||
cache?: CacheOptions;
|
||||
system?: NodeSystemOptions;
|
||||
telemetry?: NodeTelemetryOptions;
|
||||
};
|
||||
|
||||
/** @public */
|
||||
export type ManagedIdentityIdParams = {
|
||||
userAssignedClientId?: string;
|
||||
userAssignedResourceId?: string;
|
||||
userAssignedObjectId?: string;
|
||||
};
|
||||
|
||||
/** @public */
|
||||
export type ManagedIdentityConfiguration = {
|
||||
clientCapabilities?: Array<string>;
|
||||
managedIdentityIdParams?: ManagedIdentityIdParams;
|
||||
system?: NodeSystemOptions;
|
||||
};
|
||||
|
||||
const DEFAULT_AUTH_OPTIONS: Required<NodeAuthOptions> = {
|
||||
clientId: "",
|
||||
authority: Constants.DEFAULT_AUTHORITY,
|
||||
clientSecret: "",
|
||||
clientAssertion: "",
|
||||
clientCertificate: {
|
||||
thumbprint: "",
|
||||
thumbprintSha256: "",
|
||||
privateKey: "",
|
||||
x5c: "",
|
||||
},
|
||||
knownAuthorities: [],
|
||||
cloudDiscoveryMetadata: "",
|
||||
authorityMetadata: "",
|
||||
clientCapabilities: [],
|
||||
azureCloudOptions: {
|
||||
azureCloudInstance: AzureCloudInstance.None,
|
||||
tenant: "",
|
||||
},
|
||||
isMcp: false,
|
||||
};
|
||||
|
||||
const DEFAULT_LOGGER_OPTIONS: LoggerOptions = {
|
||||
loggerCallback: (): void => {
|
||||
// allow users to not set logger call back
|
||||
},
|
||||
piiLoggingEnabled: false,
|
||||
logLevel: LogLevel.Info,
|
||||
};
|
||||
|
||||
const DEFAULT_SYSTEM_OPTIONS: Required<NodeSystemOptions> = {
|
||||
loggerOptions: DEFAULT_LOGGER_OPTIONS,
|
||||
networkClient: new HttpClient(),
|
||||
disableInternalRetries: false,
|
||||
protocolMode: ProtocolMode.AAD,
|
||||
};
|
||||
|
||||
const DEFAULT_TELEMETRY_OPTIONS: Required<NodeTelemetryOptions> = {
|
||||
application: {
|
||||
appName: "",
|
||||
appVersion: "",
|
||||
},
|
||||
};
|
||||
|
||||
/** @internal */
|
||||
export type NodeConfiguration = {
|
||||
auth: Required<NodeAuthOptions>;
|
||||
broker: BrokerOptions;
|
||||
cache: CacheOptions;
|
||||
system: Required<NodeSystemOptions>;
|
||||
telemetry: Required<NodeTelemetryOptions>;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets the default options when not explicitly configured from app developer
|
||||
*
|
||||
* @param auth - Authentication options
|
||||
* @param cache - Cache options
|
||||
* @param system - System options
|
||||
* @param telemetry - Telemetry options
|
||||
*
|
||||
* @returns Configuration
|
||||
* @internal
|
||||
*/
|
||||
export function buildAppConfiguration({
|
||||
auth,
|
||||
broker,
|
||||
cache,
|
||||
system,
|
||||
telemetry,
|
||||
}: Configuration): NodeConfiguration {
|
||||
const systemOptions: Required<NodeSystemOptions> = {
|
||||
...DEFAULT_SYSTEM_OPTIONS,
|
||||
networkClient: new HttpClient(),
|
||||
loggerOptions: system?.loggerOptions || DEFAULT_LOGGER_OPTIONS,
|
||||
disableInternalRetries: system?.disableInternalRetries || false,
|
||||
};
|
||||
|
||||
// if client certificate was provided, ensure that at least one of the SHA-1 or SHA-256 thumbprints were provided
|
||||
if (
|
||||
!!auth.clientCertificate &&
|
||||
!!!auth.clientCertificate.thumbprint &&
|
||||
!!!auth.clientCertificate.thumbprintSha256
|
||||
) {
|
||||
throw NodeAuthError.createStateNotFoundError();
|
||||
}
|
||||
|
||||
return {
|
||||
auth: { ...DEFAULT_AUTH_OPTIONS, ...auth },
|
||||
broker: { ...broker },
|
||||
cache: { ...cache },
|
||||
system: { ...systemOptions, ...system },
|
||||
telemetry: { ...DEFAULT_TELEMETRY_OPTIONS, ...telemetry },
|
||||
};
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export type ManagedIdentityNodeConfiguration = {
|
||||
clientCapabilities?: Array<string>;
|
||||
disableInternalRetries: boolean;
|
||||
managedIdentityId: ManagedIdentityId;
|
||||
system: Required<
|
||||
Pick<NodeSystemOptions, "loggerOptions" | "networkClient">
|
||||
>;
|
||||
};
|
||||
|
||||
export function buildManagedIdentityConfiguration({
|
||||
clientCapabilities,
|
||||
managedIdentityIdParams,
|
||||
system,
|
||||
}: ManagedIdentityConfiguration): ManagedIdentityNodeConfiguration {
|
||||
const managedIdentityId: ManagedIdentityId = new ManagedIdentityId(
|
||||
managedIdentityIdParams
|
||||
);
|
||||
|
||||
const loggerOptions: LoggerOptions =
|
||||
system?.loggerOptions || DEFAULT_LOGGER_OPTIONS;
|
||||
|
||||
let networkClient: INetworkModule;
|
||||
// use developer provided network client if passed in
|
||||
if (system?.networkClient) {
|
||||
networkClient = system.networkClient;
|
||||
// otherwise, create a new one
|
||||
} else {
|
||||
networkClient = new HttpClient();
|
||||
}
|
||||
|
||||
return {
|
||||
clientCapabilities: clientCapabilities || [],
|
||||
managedIdentityId: managedIdentityId,
|
||||
system: {
|
||||
loggerOptions,
|
||||
networkClient,
|
||||
},
|
||||
disableInternalRetries: system?.disableInternalRetries || false,
|
||||
};
|
||||
}
|
||||
73
backend/node_modules/@azure/msal-node/src/config/ManagedIdentityId.ts
generated
vendored
Normal file
73
backend/node_modules/@azure/msal-node/src/config/ManagedIdentityId.ts
generated
vendored
Normal file
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import {
|
||||
ManagedIdentityErrorCodes,
|
||||
createManagedIdentityError,
|
||||
} from "../error/ManagedIdentityError.js";
|
||||
import {
|
||||
DEFAULT_MANAGED_IDENTITY_ID,
|
||||
ManagedIdentityIdType,
|
||||
} from "../utils/Constants.js";
|
||||
import type { ManagedIdentityIdParams } from "./Configuration.js";
|
||||
|
||||
export class ManagedIdentityId {
|
||||
private _id: string;
|
||||
public get id(): string {
|
||||
return this._id;
|
||||
}
|
||||
private set id(value: string) {
|
||||
this._id = value;
|
||||
}
|
||||
|
||||
private _idType: ManagedIdentityIdType;
|
||||
public get idType(): ManagedIdentityIdType {
|
||||
return this._idType;
|
||||
}
|
||||
private set idType(value: ManagedIdentityIdType) {
|
||||
this._idType = value;
|
||||
}
|
||||
|
||||
constructor(managedIdentityIdParams?: ManagedIdentityIdParams) {
|
||||
const userAssignedClientId =
|
||||
managedIdentityIdParams?.userAssignedClientId;
|
||||
const userAssignedResourceId =
|
||||
managedIdentityIdParams?.userAssignedResourceId;
|
||||
const userAssignedObjectId =
|
||||
managedIdentityIdParams?.userAssignedObjectId;
|
||||
|
||||
if (userAssignedClientId) {
|
||||
if (userAssignedResourceId || userAssignedObjectId) {
|
||||
throw createManagedIdentityError(
|
||||
ManagedIdentityErrorCodes.invalidManagedIdentityIdType
|
||||
);
|
||||
}
|
||||
|
||||
this.id = userAssignedClientId;
|
||||
this.idType = ManagedIdentityIdType.USER_ASSIGNED_CLIENT_ID;
|
||||
} else if (userAssignedResourceId) {
|
||||
if (userAssignedClientId || userAssignedObjectId) {
|
||||
throw createManagedIdentityError(
|
||||
ManagedIdentityErrorCodes.invalidManagedIdentityIdType
|
||||
);
|
||||
}
|
||||
|
||||
this.id = userAssignedResourceId;
|
||||
this.idType = ManagedIdentityIdType.USER_ASSIGNED_RESOURCE_ID;
|
||||
} else if (userAssignedObjectId) {
|
||||
if (userAssignedClientId || userAssignedResourceId) {
|
||||
throw createManagedIdentityError(
|
||||
ManagedIdentityErrorCodes.invalidManagedIdentityIdType
|
||||
);
|
||||
}
|
||||
|
||||
this.id = userAssignedObjectId;
|
||||
this.idType = ManagedIdentityIdType.USER_ASSIGNED_OBJECT_ID;
|
||||
} else {
|
||||
this.id = DEFAULT_MANAGED_IDENTITY_ID;
|
||||
this.idType = ManagedIdentityIdType.SYSTEM_ASSIGNED;
|
||||
}
|
||||
}
|
||||
}
|
||||
67
backend/node_modules/@azure/msal-node/src/config/ManagedIdentityRequestParameters.ts
generated
vendored
Normal file
67
backend/node_modules/@azure/msal-node/src/config/ManagedIdentityRequestParameters.ts
generated
vendored
Normal file
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import {
|
||||
RequestParameterBuilder,
|
||||
UrlString,
|
||||
UrlUtils,
|
||||
} from "@azure/msal-common/node";
|
||||
import { DefaultManagedIdentityRetryPolicy } from "../retry/DefaultManagedIdentityRetryPolicy.js";
|
||||
import { HttpMethod, RetryPolicies } from "../utils/Constants.js";
|
||||
|
||||
export class ManagedIdentityRequestParameters {
|
||||
private _baseEndpoint: string;
|
||||
public httpMethod: HttpMethod;
|
||||
public headers: Record<string, string>;
|
||||
public bodyParameters: Record<string, string>;
|
||||
public queryParameters: Record<string, string>;
|
||||
public retryPolicy: RetryPolicies;
|
||||
|
||||
constructor(
|
||||
httpMethod: HttpMethod,
|
||||
endpoint: string,
|
||||
retryPolicy?: RetryPolicies
|
||||
) {
|
||||
this.httpMethod = httpMethod;
|
||||
this._baseEndpoint = endpoint;
|
||||
this.headers = {} as Record<string, string>;
|
||||
this.bodyParameters = {} as Record<string, string>;
|
||||
this.queryParameters = {} as Record<string, string>;
|
||||
|
||||
this.retryPolicy =
|
||||
retryPolicy || new DefaultManagedIdentityRetryPolicy();
|
||||
}
|
||||
|
||||
public computeUri(): string {
|
||||
const parameters = new Map<string, string>();
|
||||
|
||||
if (this.queryParameters) {
|
||||
RequestParameterBuilder.addExtraParameters(
|
||||
parameters,
|
||||
this.queryParameters
|
||||
);
|
||||
}
|
||||
|
||||
const queryParametersString = UrlUtils.mapToQueryString(parameters);
|
||||
|
||||
return UrlString.appendQueryString(
|
||||
this._baseEndpoint,
|
||||
queryParametersString
|
||||
);
|
||||
}
|
||||
|
||||
public computeParametersBodyString(): string {
|
||||
const parameters = new Map<string, string>();
|
||||
|
||||
if (this.bodyParameters) {
|
||||
RequestParameterBuilder.addExtraParameters(
|
||||
parameters,
|
||||
this.bodyParameters
|
||||
);
|
||||
}
|
||||
|
||||
return UrlUtils.mapToQueryString(parameters);
|
||||
}
|
||||
}
|
||||
115
backend/node_modules/@azure/msal-node/src/crypto/CryptoProvider.ts
generated
vendored
Normal file
115
backend/node_modules/@azure/msal-node/src/crypto/CryptoProvider.ts
generated
vendored
Normal file
@ -0,0 +1,115 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import { Constants, ICrypto, PkceCodes } from "@azure/msal-common/node";
|
||||
import { GuidGenerator } from "./GuidGenerator.js";
|
||||
import { EncodingUtils } from "../utils/EncodingUtils.js";
|
||||
import { PkceGenerator } from "./PkceGenerator.js";
|
||||
import { HashUtils } from "./HashUtils.js";
|
||||
|
||||
/**
|
||||
* This class implements MSAL node's crypto interface, which allows it to perform base64 encoding and decoding, generating cryptographically random GUIDs and
|
||||
* implementing Proof Key for Code Exchange specs for the OAuth Authorization Code Flow using PKCE (rfc here: https://tools.ietf.org/html/rfc7636).
|
||||
* @public
|
||||
*/
|
||||
export class CryptoProvider implements ICrypto {
|
||||
private pkceGenerator: PkceGenerator;
|
||||
private guidGenerator: GuidGenerator;
|
||||
private hashUtils: HashUtils;
|
||||
|
||||
constructor() {
|
||||
// Browser crypto needs to be validated first before any other classes can be set.
|
||||
this.pkceGenerator = new PkceGenerator();
|
||||
this.guidGenerator = new GuidGenerator();
|
||||
this.hashUtils = new HashUtils();
|
||||
}
|
||||
|
||||
/**
|
||||
* base64 URL safe encoded string
|
||||
*/
|
||||
base64UrlEncode(): string {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
/**
|
||||
* Stringifies and base64Url encodes input public key
|
||||
* @param inputKid - public key id
|
||||
* @returns Base64Url encoded public key
|
||||
*/
|
||||
encodeKid(): string {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new random GUID - used to populate state and nonce.
|
||||
* @returns string (GUID)
|
||||
*/
|
||||
createNewGuid(): string {
|
||||
return this.guidGenerator.generateGuid();
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes input string to base64.
|
||||
* @param input - string to be encoded
|
||||
*/
|
||||
base64Encode(input: string): string {
|
||||
return EncodingUtils.base64Encode(input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes input string from base64.
|
||||
* @param input - string to be decoded
|
||||
*/
|
||||
base64Decode(input: string): string {
|
||||
return EncodingUtils.base64Decode(input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates PKCE codes used in Authorization Code Flow.
|
||||
*/
|
||||
generatePkceCodes(): Promise<PkceCodes> {
|
||||
return this.pkceGenerator.generatePkceCodes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a keypair, stores it and returns a thumbprint - not yet implemented for node
|
||||
*/
|
||||
getPublicKeyThumbprint(): Promise<string> {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes cryptographic keypair from key store matching the keyId passed in
|
||||
* @param kid - public key id
|
||||
*/
|
||||
removeTokenBindingKey(): Promise<void> {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all cryptographic keys from Keystore
|
||||
*/
|
||||
clearKeystore(): Promise<boolean> {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Signs the given object as a jwt payload with private key retrieved by given kid - currently not implemented for node
|
||||
*/
|
||||
signJwt(): Promise<string> {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the SHA-256 hash of an input string
|
||||
*/
|
||||
async hashString(plainText: string): Promise<string> {
|
||||
return EncodingUtils.base64EncodeUrl(
|
||||
this.hashUtils
|
||||
.sha256(plainText)
|
||||
.toString(Constants.EncodingTypes.BASE64),
|
||||
Constants.EncodingTypes.BASE64
|
||||
);
|
||||
}
|
||||
}
|
||||
27
backend/node_modules/@azure/msal-node/src/crypto/GuidGenerator.ts
generated
vendored
Normal file
27
backend/node_modules/@azure/msal-node/src/crypto/GuidGenerator.ts
generated
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import { IGuidGenerator } from "@azure/msal-common/node";
|
||||
import { randomUUID } from "node:crypto";
|
||||
|
||||
export class GuidGenerator implements IGuidGenerator {
|
||||
/**
|
||||
* Generates a random [RFC 4122](https://www.rfc-editor.org/rfc/rfc4122.txt) version 4 UUID. The UUID is generated using a
|
||||
* cryptographic pseudorandom number generator.
|
||||
*/
|
||||
generateGuid(): string {
|
||||
return randomUUID();
|
||||
}
|
||||
|
||||
/**
|
||||
* verifies if a string is GUID
|
||||
* @param guid
|
||||
*/
|
||||
isGuid(guid: string): boolean {
|
||||
const regexGuid =
|
||||
/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
||||
return regexGuid.test(guid);
|
||||
}
|
||||
}
|
||||
17
backend/node_modules/@azure/msal-node/src/crypto/HashUtils.ts
generated
vendored
Normal file
17
backend/node_modules/@azure/msal-node/src/crypto/HashUtils.ts
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import { Hash } from "../utils/Constants.js";
|
||||
import crypto from "crypto";
|
||||
|
||||
export class HashUtils {
|
||||
/**
|
||||
* generate 'SHA256' hash
|
||||
* @param buffer
|
||||
*/
|
||||
sha256(buffer: string): Buffer {
|
||||
return crypto.createHash(Hash.SHA256).update(buffer).digest();
|
||||
}
|
||||
}
|
||||
65
backend/node_modules/@azure/msal-node/src/crypto/PkceGenerator.ts
generated
vendored
Normal file
65
backend/node_modules/@azure/msal-node/src/crypto/PkceGenerator.ts
generated
vendored
Normal file
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import { PkceCodes, Constants } from "@azure/msal-common/node";
|
||||
import { CharSet, RANDOM_OCTET_SIZE } from "../utils/Constants.js";
|
||||
import { EncodingUtils } from "../utils/EncodingUtils.js";
|
||||
import { HashUtils } from "./HashUtils.js";
|
||||
import crypto from "crypto";
|
||||
|
||||
/**
|
||||
* https://tools.ietf.org/html/rfc7636#page-8
|
||||
*/
|
||||
export class PkceGenerator {
|
||||
private hashUtils: HashUtils;
|
||||
|
||||
constructor() {
|
||||
this.hashUtils = new HashUtils();
|
||||
}
|
||||
/**
|
||||
* generates the codeVerfier and the challenge from the codeVerfier
|
||||
* reference: https://tools.ietf.org/html/rfc7636#section-4.1 and https://tools.ietf.org/html/rfc7636#section-4.2
|
||||
*/
|
||||
async generatePkceCodes(): Promise<PkceCodes> {
|
||||
const verifier = this.generateCodeVerifier();
|
||||
const challenge = this.generateCodeChallengeFromVerifier(verifier);
|
||||
return { verifier, challenge };
|
||||
}
|
||||
|
||||
/**
|
||||
* generates the codeVerfier; reference: https://tools.ietf.org/html/rfc7636#section-4.1
|
||||
*/
|
||||
private generateCodeVerifier(): string {
|
||||
const charArr = [];
|
||||
const maxNumber = 256 - (256 % CharSet.CV_CHARSET.length);
|
||||
while (charArr.length <= RANDOM_OCTET_SIZE) {
|
||||
const byte = crypto.randomBytes(1)[0];
|
||||
if (byte >= maxNumber) {
|
||||
/*
|
||||
* Ignore this number to maintain randomness.
|
||||
* Including it would result in an unequal distribution of characters after doing the modulo
|
||||
*/
|
||||
continue;
|
||||
}
|
||||
const index = byte % CharSet.CV_CHARSET.length;
|
||||
charArr.push(CharSet.CV_CHARSET[index]);
|
||||
}
|
||||
const verifier: string = charArr.join("");
|
||||
return EncodingUtils.base64EncodeUrl(verifier);
|
||||
}
|
||||
|
||||
/**
|
||||
* generate the challenge from the codeVerfier; reference: https://tools.ietf.org/html/rfc7636#section-4.2
|
||||
* @param codeVerifier
|
||||
*/
|
||||
private generateCodeChallengeFromVerifier(codeVerifier: string): string {
|
||||
return EncodingUtils.base64EncodeUrl(
|
||||
this.hashUtils
|
||||
.sha256(codeVerifier)
|
||||
.toString(Constants.EncodingTypes.BASE64),
|
||||
Constants.EncodingTypes.BASE64
|
||||
);
|
||||
}
|
||||
}
|
||||
12
backend/node_modules/@azure/msal-node/src/error/ClientAuthErrorCodes.ts
generated
vendored
Normal file
12
backend/node_modules/@azure/msal-node/src/error/ClientAuthErrorCodes.ts
generated
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
export const missingTenantIdError = "missing_tenant_id_error";
|
||||
export const userTimeoutReached = "user_timeout_reached";
|
||||
export const invalidAssertion = "invalid_assertion";
|
||||
export const invalidClientCredential = "invalid_client_credential";
|
||||
export const deviceCodePollingCancelled = "device_code_polling_cancelled";
|
||||
export const deviceCodeExpired = "device_code_expired";
|
||||
export const deviceCodeUnknownError = "device_code_unknown_error";
|
||||
65
backend/node_modules/@azure/msal-node/src/error/ManagedIdentityError.ts
generated
vendored
Normal file
65
backend/node_modules/@azure/msal-node/src/error/ManagedIdentityError.ts
generated
vendored
Normal file
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import { AuthError } from "@azure/msal-common/node";
|
||||
import * as ManagedIdentityErrorCodes from "./ManagedIdentityErrorCodes.js";
|
||||
import { ManagedIdentityEnvironmentVariableNames } from "../utils/Constants.js";
|
||||
export { ManagedIdentityErrorCodes };
|
||||
|
||||
/**
|
||||
* ManagedIdentityErrorMessage class containing string constants used by error codes and messages.
|
||||
*/
|
||||
export const ManagedIdentityErrorMessages = {
|
||||
[ManagedIdentityErrorCodes.invalidFileExtension]:
|
||||
"The file path in the WWW-Authenticate header does not contain a .key file.",
|
||||
[ManagedIdentityErrorCodes.invalidFilePath]:
|
||||
"The file path in the WWW-Authenticate header is not in a valid Windows or Linux Format.",
|
||||
[ManagedIdentityErrorCodes.invalidManagedIdentityIdType]:
|
||||
"More than one ManagedIdentityIdType was provided.",
|
||||
[ManagedIdentityErrorCodes.invalidSecret]:
|
||||
"The secret in the file on the file path in the WWW-Authenticate header is greater than 4096 bytes.",
|
||||
[ManagedIdentityErrorCodes.platformNotSupported]:
|
||||
"The platform is not supported by Azure Arc. Azure Arc only supports Windows and Linux.",
|
||||
[ManagedIdentityErrorCodes.missingId]:
|
||||
"A ManagedIdentityId id was not provided.",
|
||||
[ManagedIdentityErrorCodes.MsiEnvironmentVariableUrlMalformedErrorCodes
|
||||
.AZURE_POD_IDENTITY_AUTHORITY_HOST]: `The Managed Identity's '${ManagedIdentityEnvironmentVariableNames.AZURE_POD_IDENTITY_AUTHORITY_HOST}' environment variable is malformed.`,
|
||||
[ManagedIdentityErrorCodes.MsiEnvironmentVariableUrlMalformedErrorCodes
|
||||
.IDENTITY_ENDPOINT]: `The Managed Identity's '${ManagedIdentityEnvironmentVariableNames.IDENTITY_ENDPOINT}' environment variable is malformed.`,
|
||||
[ManagedIdentityErrorCodes.MsiEnvironmentVariableUrlMalformedErrorCodes
|
||||
.IMDS_ENDPOINT]: `The Managed Identity's '${ManagedIdentityEnvironmentVariableNames.IMDS_ENDPOINT}' environment variable is malformed.`,
|
||||
[ManagedIdentityErrorCodes.MsiEnvironmentVariableUrlMalformedErrorCodes
|
||||
.MSI_ENDPOINT]: `The Managed Identity's '${ManagedIdentityEnvironmentVariableNames.MSI_ENDPOINT}' environment variable is malformed.`,
|
||||
[ManagedIdentityErrorCodes.networkUnavailable]:
|
||||
"Authentication unavailable. The request to the managed identity endpoint timed out.",
|
||||
[ManagedIdentityErrorCodes.unableToCreateAzureArc]:
|
||||
"Azure Arc Managed Identities can only be system assigned.",
|
||||
[ManagedIdentityErrorCodes.unableToCreateCloudShell]:
|
||||
"Cloud Shell Managed Identities can only be system assigned.",
|
||||
[ManagedIdentityErrorCodes.unableToCreateSource]:
|
||||
"Unable to create a Managed Identity source based on environment variables.",
|
||||
[ManagedIdentityErrorCodes.unableToReadSecretFile]:
|
||||
"Unable to read the secret file.",
|
||||
[ManagedIdentityErrorCodes.userAssignedNotAvailableAtRuntime]:
|
||||
"Service Fabric user assigned managed identity ClientId or ResourceId is not configurable at runtime.",
|
||||
[ManagedIdentityErrorCodes.wwwAuthenticateHeaderMissing]:
|
||||
"A 401 response was received form the Azure Arc Managed Identity, but the www-authenticate header is missing.",
|
||||
[ManagedIdentityErrorCodes.wwwAuthenticateHeaderUnsupportedFormat]:
|
||||
"A 401 response was received form the Azure Arc Managed Identity, but the www-authenticate header is in an unsupported format.",
|
||||
};
|
||||
|
||||
export class ManagedIdentityError extends AuthError {
|
||||
constructor(errorCode: string) {
|
||||
super(errorCode, ManagedIdentityErrorMessages[errorCode]);
|
||||
this.name = "ManagedIdentityError";
|
||||
Object.setPrototypeOf(this, ManagedIdentityError.prototype);
|
||||
}
|
||||
}
|
||||
|
||||
export function createManagedIdentityError(
|
||||
errorCode: string
|
||||
): ManagedIdentityError {
|
||||
return new ManagedIdentityError(errorCode);
|
||||
}
|
||||
37
backend/node_modules/@azure/msal-node/src/error/ManagedIdentityErrorCodes.ts
generated
vendored
Normal file
37
backend/node_modules/@azure/msal-node/src/error/ManagedIdentityErrorCodes.ts
generated
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import { ManagedIdentityEnvironmentVariableNames } from "../utils/Constants.js";
|
||||
|
||||
export const invalidFileExtension = "invalid_file_extension";
|
||||
export const invalidFilePath = "invalid_file_path";
|
||||
export const invalidManagedIdentityIdType = "invalid_managed_identity_id_type";
|
||||
export const invalidSecret = "invalid_secret";
|
||||
export const missingId = "missing_client_id";
|
||||
export const networkUnavailable = "network_unavailable";
|
||||
export const platformNotSupported = "platform_not_supported";
|
||||
export const unableToCreateAzureArc = "unable_to_create_azure_arc";
|
||||
export const unableToCreateCloudShell = "unable_to_create_cloud_shell";
|
||||
export const unableToCreateSource = "unable_to_create_source";
|
||||
export const unableToReadSecretFile = "unable_to_read_secret_file";
|
||||
export const urlParseError = "url_parse_error";
|
||||
export const userAssignedNotAvailableAtRuntime =
|
||||
"user_assigned_not_available_at_runtime";
|
||||
export const wwwAuthenticateHeaderMissing = "www_authenticate_header_missing";
|
||||
export const wwwAuthenticateHeaderUnsupportedFormat =
|
||||
"www_authenticate_header_unsupported_format";
|
||||
|
||||
export const MsiEnvironmentVariableUrlMalformedErrorCodes = {
|
||||
[ManagedIdentityEnvironmentVariableNames.AZURE_POD_IDENTITY_AUTHORITY_HOST]:
|
||||
"azure_pod_identity_authority_host_url_malformed",
|
||||
[ManagedIdentityEnvironmentVariableNames.IDENTITY_ENDPOINT]:
|
||||
"identity_endpoint_url_malformed",
|
||||
[ManagedIdentityEnvironmentVariableNames.IMDS_ENDPOINT]:
|
||||
"imds_endpoint_url_malformed",
|
||||
[ManagedIdentityEnvironmentVariableNames.MSI_ENDPOINT]:
|
||||
"msi_endpoint_url_malformed",
|
||||
} as const;
|
||||
export type MsiEnvironmentVariableErrorCodes =
|
||||
(typeof MsiEnvironmentVariableUrlMalformedErrorCodes)[keyof typeof MsiEnvironmentVariableUrlMalformedErrorCodes];
|
||||
145
backend/node_modules/@azure/msal-node/src/error/NodeAuthError.ts
generated
vendored
Normal file
145
backend/node_modules/@azure/msal-node/src/error/NodeAuthError.ts
generated
vendored
Normal file
@ -0,0 +1,145 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import { AuthError } from "@azure/msal-common/node";
|
||||
|
||||
/**
|
||||
* NodeAuthErrorMessage class containing string constants used by error codes and messages.
|
||||
*/
|
||||
export const NodeAuthErrorMessage = {
|
||||
invalidLoopbackAddressType: {
|
||||
code: "invalid_loopback_server_address_type",
|
||||
desc: "Loopback server address is not type string. This is unexpected.",
|
||||
},
|
||||
unableToLoadRedirectUri: {
|
||||
code: "unable_to_load_redirectUrl",
|
||||
desc: "Loopback server callback was invoked without a url. This is unexpected.",
|
||||
},
|
||||
noAuthCodeInResponse: {
|
||||
code: "no_auth_code_in_response",
|
||||
desc: "No auth code found in the server response. Please check your network trace to determine what happened.",
|
||||
},
|
||||
noLoopbackServerExists: {
|
||||
code: "no_loopback_server_exists",
|
||||
desc: "No loopback server exists yet.",
|
||||
},
|
||||
loopbackServerAlreadyExists: {
|
||||
code: "loopback_server_already_exists",
|
||||
desc: "Loopback server already exists. Cannot create another.",
|
||||
},
|
||||
loopbackServerTimeout: {
|
||||
code: "loopback_server_timeout",
|
||||
desc: "Timed out waiting for auth code listener to be registered.",
|
||||
},
|
||||
stateNotFoundError: {
|
||||
code: "state_not_found",
|
||||
desc: "State not found. Please verify that the request originated from msal.",
|
||||
},
|
||||
thumbprintMissing: {
|
||||
code: "thumbprint_missing_from_client_certificate",
|
||||
desc: "Client certificate does not contain a SHA-1 or SHA-256 thumbprint.",
|
||||
},
|
||||
redirectUriNotSupported: {
|
||||
code: "redirect_uri_not_supported",
|
||||
desc: "RedirectUri is not supported in this scenario. Please remove redirectUri from the request.",
|
||||
},
|
||||
};
|
||||
|
||||
export class NodeAuthError extends AuthError {
|
||||
constructor(errorCode: string, errorMessage?: string) {
|
||||
super(errorCode, errorMessage);
|
||||
this.name = "NodeAuthError";
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an error thrown if loopback server address is of type string.
|
||||
*/
|
||||
static createInvalidLoopbackAddressTypeError(): NodeAuthError {
|
||||
return new NodeAuthError(
|
||||
NodeAuthErrorMessage.invalidLoopbackAddressType.code,
|
||||
`${NodeAuthErrorMessage.invalidLoopbackAddressType.desc}`
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an error thrown if the loopback server is unable to get a url.
|
||||
*/
|
||||
static createUnableToLoadRedirectUrlError(): NodeAuthError {
|
||||
return new NodeAuthError(
|
||||
NodeAuthErrorMessage.unableToLoadRedirectUri.code,
|
||||
`${NodeAuthErrorMessage.unableToLoadRedirectUri.desc}`
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an error thrown if the server response does not contain an auth code.
|
||||
*/
|
||||
static createNoAuthCodeInResponseError(): NodeAuthError {
|
||||
return new NodeAuthError(
|
||||
NodeAuthErrorMessage.noAuthCodeInResponse.code,
|
||||
`${NodeAuthErrorMessage.noAuthCodeInResponse.desc}`
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an error thrown if the loopback server has not been spun up yet.
|
||||
*/
|
||||
static createNoLoopbackServerExistsError(): NodeAuthError {
|
||||
return new NodeAuthError(
|
||||
NodeAuthErrorMessage.noLoopbackServerExists.code,
|
||||
`${NodeAuthErrorMessage.noLoopbackServerExists.desc}`
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an error thrown if a loopback server already exists when attempting to create another one.
|
||||
*/
|
||||
static createLoopbackServerAlreadyExistsError(): NodeAuthError {
|
||||
return new NodeAuthError(
|
||||
NodeAuthErrorMessage.loopbackServerAlreadyExists.code,
|
||||
`${NodeAuthErrorMessage.loopbackServerAlreadyExists.desc}`
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an error thrown if the loopback server times out registering the auth code listener.
|
||||
*/
|
||||
static createLoopbackServerTimeoutError(): NodeAuthError {
|
||||
return new NodeAuthError(
|
||||
NodeAuthErrorMessage.loopbackServerTimeout.code,
|
||||
`${NodeAuthErrorMessage.loopbackServerTimeout.desc}`
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an error thrown when the state is not present.
|
||||
*/
|
||||
static createStateNotFoundError(): NodeAuthError {
|
||||
return new NodeAuthError(
|
||||
NodeAuthErrorMessage.stateNotFoundError.code,
|
||||
NodeAuthErrorMessage.stateNotFoundError.desc
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an error thrown when client certificate was provided, but neither the SHA-1 or SHA-256 thumbprints were provided
|
||||
*/
|
||||
static createThumbprintMissingError(): NodeAuthError {
|
||||
return new NodeAuthError(
|
||||
NodeAuthErrorMessage.thumbprintMissing.code,
|
||||
NodeAuthErrorMessage.thumbprintMissing.desc
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an error thrown when redirectUri is provided in an unsupported scenario
|
||||
*/
|
||||
static createRedirectUriNotSupportedError(): NodeAuthError {
|
||||
return new NodeAuthError(
|
||||
NodeAuthErrorMessage.redirectUriNotSupported.code,
|
||||
NodeAuthErrorMessage.redirectUriNotSupported.desc
|
||||
);
|
||||
}
|
||||
}
|
||||
123
backend/node_modules/@azure/msal-node/src/index.ts
generated
vendored
Normal file
123
backend/node_modules/@azure/msal-node/src/index.ts
generated
vendored
Normal file
@ -0,0 +1,123 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @packageDocumentation
|
||||
* @module @azure/msal-node
|
||||
*/
|
||||
|
||||
/**
|
||||
* Warning: This set of exports is purely intended to be used by other MSAL libraries, and should be considered potentially unstable. We strongly discourage using them directly, you do so at your own risk.
|
||||
* Breaking changes to these APIs will be shipped under a minor version, instead of a major version.
|
||||
*/
|
||||
import * as internals from "./internals.js";
|
||||
import { Constants as CommonConstants } from "@azure/msal-common/node";
|
||||
export { internals };
|
||||
|
||||
// Interfaces
|
||||
export { IPublicClientApplication } from "./client/IPublicClientApplication.js";
|
||||
export { IConfidentialClientApplication } from "./client/IConfidentialClientApplication.js";
|
||||
export { ITokenCache } from "./cache/ITokenCache.js";
|
||||
export { ICacheClient } from "./cache/distributed/ICacheClient.js";
|
||||
export { IPartitionManager } from "./cache/distributed/IPartitionManager.js";
|
||||
export { ILoopbackClient } from "./network/ILoopbackClient.js";
|
||||
|
||||
// Clients and Configuration
|
||||
export { PublicClientApplication } from "./client/PublicClientApplication.js";
|
||||
export { ConfidentialClientApplication } from "./client/ConfidentialClientApplication.js";
|
||||
export { ManagedIdentityApplication } from "./client/ManagedIdentityApplication.js";
|
||||
|
||||
export {
|
||||
Configuration,
|
||||
ManagedIdentityConfiguration,
|
||||
ManagedIdentityIdParams,
|
||||
NodeAuthOptions,
|
||||
NodeSystemOptions,
|
||||
BrokerOptions,
|
||||
NodeTelemetryOptions,
|
||||
CacheOptions,
|
||||
} from "./config/Configuration.js";
|
||||
export { ClientAssertion } from "./client/ClientAssertion.js";
|
||||
|
||||
// Cache and Storage
|
||||
export { TokenCache } from "./cache/TokenCache.js";
|
||||
export {
|
||||
CacheKVStore,
|
||||
JsonCache,
|
||||
InMemoryCache,
|
||||
SerializedAccountEntity,
|
||||
SerializedIdTokenEntity,
|
||||
SerializedAccessTokenEntity,
|
||||
SerializedAppMetadataEntity,
|
||||
SerializedRefreshTokenEntity,
|
||||
} from "./cache/serializer/SerializerTypes.js";
|
||||
export { DistributedCachePlugin } from "./cache/distributed/DistributedCachePlugin.js";
|
||||
|
||||
// Constants
|
||||
export { ManagedIdentitySourceNames } from "./utils/Constants.js";
|
||||
|
||||
// Request objects
|
||||
export type { AuthorizationCodeRequest } from "./request/AuthorizationCodeRequest.js";
|
||||
export type { AuthorizationUrlRequest } from "./request/AuthorizationUrlRequest.js";
|
||||
export type { ClientCredentialRequest } from "./request/ClientCredentialRequest.js";
|
||||
export type { DeviceCodeRequest } from "./request/DeviceCodeRequest.js";
|
||||
export type { OnBehalfOfRequest } from "./request/OnBehalfOfRequest.js";
|
||||
export type { UsernamePasswordRequest } from "./request/UsernamePasswordRequest.js";
|
||||
export type { RefreshTokenRequest } from "./request/RefreshTokenRequest.js";
|
||||
export type { SilentFlowRequest } from "./request/SilentFlowRequest.js";
|
||||
export type { InteractiveRequest } from "./request/InteractiveRequest.js";
|
||||
export type { SignOutRequest } from "./request/SignOutRequest.js";
|
||||
export type { ManagedIdentityRequestParams } from "./request/ManagedIdentityRequestParams.js";
|
||||
|
||||
const PromptValue = CommonConstants.PromptValue;
|
||||
const ResponseMode = CommonConstants.ResponseMode;
|
||||
export { PromptValue, ResponseMode };
|
||||
|
||||
export { CryptoProvider } from "./crypto/CryptoProvider.js";
|
||||
|
||||
// Common Object Formats
|
||||
export {
|
||||
AuthorizationCodePayload,
|
||||
// Response
|
||||
AuthenticationResult,
|
||||
AuthorizeResponse,
|
||||
IdTokenClaims,
|
||||
// Cache
|
||||
AccountInfo,
|
||||
ValidCacheType,
|
||||
// Error
|
||||
AuthError,
|
||||
AuthErrorCodes,
|
||||
ClientAuthError,
|
||||
ClientAuthErrorCodes,
|
||||
ClientConfigurationError,
|
||||
ClientConfigurationErrorCodes,
|
||||
InteractionRequiredAuthError,
|
||||
InteractionRequiredAuthErrorCodes,
|
||||
ServerError,
|
||||
// Network Interface
|
||||
INetworkModule,
|
||||
NetworkRequestOptions,
|
||||
NetworkResponse,
|
||||
// Logger
|
||||
Logger,
|
||||
LogLevel,
|
||||
// ProtocolMode enum
|
||||
ProtocolMode,
|
||||
ICachePlugin,
|
||||
TokenCacheContext,
|
||||
ISerializableTokenCache,
|
||||
// AzureCloudInstance enum
|
||||
AzureCloudInstance,
|
||||
AzureCloudOptions,
|
||||
// IAppTokenProvider
|
||||
IAppTokenProvider,
|
||||
AppTokenProviderParameters,
|
||||
AppTokenProviderResult,
|
||||
INativeBrokerPlugin,
|
||||
ClientAssertionCallback,
|
||||
} from "@azure/msal-common/node";
|
||||
|
||||
export { version } from "./packageMetadata.js";
|
||||
12
backend/node_modules/@azure/msal-node/src/internals.ts
generated
vendored
Normal file
12
backend/node_modules/@azure/msal-node/src/internals.ts
generated
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Warning: This set of exports is purely intended to be used by other MSAL libraries, and should be considered potentially unstable. We strongly discourage using them directly, you do so at your own risk.
|
||||
* Breaking changes to these APIs will be shipped under a minor version, instead of a major version.
|
||||
*/
|
||||
|
||||
export { Serializer } from "./cache/serializer/Serializer.js";
|
||||
export { Deserializer } from "./cache/serializer/Deserializer.js";
|
||||
221
backend/node_modules/@azure/msal-node/src/network/HttpClient.ts
generated
vendored
Normal file
221
backend/node_modules/@azure/msal-node/src/network/HttpClient.ts
generated
vendored
Normal file
@ -0,0 +1,221 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import {
|
||||
AuthError,
|
||||
ClientAuthErrorCodes,
|
||||
INetworkModule,
|
||||
NetworkRequestOptions,
|
||||
NetworkResponse,
|
||||
createAuthError,
|
||||
createNetworkError,
|
||||
} from "@azure/msal-common/node";
|
||||
import { HttpMethod } from "../utils/Constants.js";
|
||||
|
||||
/**
|
||||
* HTTP client implementation using Node.js native fetch API.
|
||||
*
|
||||
* This class provides a clean interface for making HTTP requests using the modern
|
||||
* fetch API available in Node.js 18+. It replaces the previous implementation that
|
||||
* relied on custom proxy handling and the legacy http/https modules.
|
||||
*/
|
||||
export class HttpClient implements INetworkModule {
|
||||
/**
|
||||
* Sends an HTTP GET request to the specified URL.
|
||||
*
|
||||
* This method handles GET requests with optional timeout support. The timeout
|
||||
* is implemented using AbortController, which provides a clean way to cancel
|
||||
* fetch requests that take too long to complete.
|
||||
*
|
||||
* @param url - The target URL for the GET request
|
||||
* @param options - Optional request configuration including headers
|
||||
* @param timeout - Optional timeout in milliseconds. If specified, the request
|
||||
* will be aborted if it doesn't complete within this time
|
||||
* @returns Promise that resolves to a NetworkResponse containing headers, body, and status
|
||||
* @throws {AuthError} When the request times out or response parsing fails
|
||||
* @throws {NetworkError} When the network request fails
|
||||
*/
|
||||
async sendGetRequestAsync<T>(
|
||||
url: string,
|
||||
options?: NetworkRequestOptions,
|
||||
timeout?: number
|
||||
): Promise<NetworkResponse<T>> {
|
||||
return this.sendRequest<T>(url, HttpMethod.GET, options, timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends an HTTP POST request to the specified URL.
|
||||
*
|
||||
* This method handles POST requests with request body support. Currently,
|
||||
* timeout functionality is not exposed for POST requests, but the underlying
|
||||
* implementation supports it through the shared sendRequest method.
|
||||
*
|
||||
* @param url - The target URL for the POST request
|
||||
* @param options - Optional request configuration including headers and body
|
||||
* @returns Promise that resolves to a NetworkResponse containing headers, body, and status
|
||||
* @throws {AuthError} When the request times out or response parsing fails
|
||||
* @throws {NetworkError} When the network request fails
|
||||
*/
|
||||
async sendPostRequestAsync<T>(
|
||||
url: string,
|
||||
options?: NetworkRequestOptions
|
||||
): Promise<NetworkResponse<T>> {
|
||||
return this.sendRequest<T>(url, HttpMethod.POST, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Core HTTP request implementation using native fetch API.
|
||||
*
|
||||
* This method handles GET and POST HTTP requests with comprehensive
|
||||
* timeout support and error handling. The timeout mechanism works as follows:
|
||||
*
|
||||
* 1. An AbortController is created for each request
|
||||
* 2. If a timeout is specified, setTimeout is used to call abort() after the delay
|
||||
* 3. The abort signal is passed to fetch, which will reject the promise if aborted
|
||||
* 4. Cleanup occurs in both success and error cases to prevent timer leaks
|
||||
*
|
||||
* Error handling priority:
|
||||
* 1. Timeout errors (AbortError) are converted to "Request timeout" messages
|
||||
* 2. Network/connection errors are wrapped with "Network request failed" prefix
|
||||
* 3. JSON parsing errors are wrapped with "Failed to parse response" prefix
|
||||
*
|
||||
* @param url - The target URL for the request
|
||||
* @param method - HTTP method (GET or POST)
|
||||
* @param options - Optional request configuration (headers, body)
|
||||
* @param timeout - Optional timeout in milliseconds for request cancellation
|
||||
* @returns Promise resolving to NetworkResponse with parsed JSON body
|
||||
* @throws {AuthError} For timeouts or JSON parsing errors
|
||||
* @throws {NetworkError} For network failures
|
||||
*/
|
||||
private async sendRequest<T>(
|
||||
url: string,
|
||||
method: string,
|
||||
options?: NetworkRequestOptions,
|
||||
timeout?: number
|
||||
): Promise<NetworkResponse<T>> {
|
||||
/*
|
||||
* Setup timeout mechanism using AbortController
|
||||
* This provides a standard way to cancel fetch requests
|
||||
*/
|
||||
const controller = new AbortController();
|
||||
let timeoutId: NodeJS.Timeout | undefined;
|
||||
|
||||
/*
|
||||
* Configure timeout if specified
|
||||
* The setTimeout will trigger abort() if the request takes too long
|
||||
*/
|
||||
if (timeout) {
|
||||
timeoutId = setTimeout(() => {
|
||||
// Calling abort() will cause fetch to reject with AbortError
|
||||
controller.abort();
|
||||
}, timeout);
|
||||
}
|
||||
|
||||
const fetchOptions: RequestInit = {
|
||||
method: method,
|
||||
headers: getFetchHeaders(options),
|
||||
signal: controller.signal, // Enable cancellation via AbortController
|
||||
};
|
||||
|
||||
if (method === HttpMethod.POST) {
|
||||
fetchOptions.body = options?.body || "";
|
||||
}
|
||||
|
||||
let response: Response;
|
||||
try {
|
||||
response = await fetch(url, fetchOptions);
|
||||
} catch (error) {
|
||||
// Clean up timeout to prevent memory leaks
|
||||
if (timeoutId) {
|
||||
clearTimeout(timeoutId);
|
||||
}
|
||||
|
||||
if (error instanceof Error && error.name === "AbortError") {
|
||||
throw createAuthError(
|
||||
ClientAuthErrorCodes.networkError,
|
||||
"Request timeout"
|
||||
);
|
||||
}
|
||||
|
||||
const baseAuthError: AuthError = createAuthError(
|
||||
ClientAuthErrorCodes.networkError,
|
||||
`Network request failed: ${
|
||||
error instanceof Error ? error.message : "unknown"
|
||||
}`
|
||||
);
|
||||
throw createNetworkError(
|
||||
baseAuthError,
|
||||
undefined,
|
||||
undefined,
|
||||
error instanceof Error ? error : undefined
|
||||
);
|
||||
}
|
||||
|
||||
// Clean up timeout to prevent memory leaks
|
||||
if (timeoutId) {
|
||||
clearTimeout(timeoutId);
|
||||
}
|
||||
|
||||
try {
|
||||
return {
|
||||
headers: getHeaderDict(response.headers),
|
||||
body: (await response.json()) as T,
|
||||
status: response.status,
|
||||
};
|
||||
} catch (error) {
|
||||
throw createAuthError(
|
||||
ClientAuthErrorCodes.tokenParsingError,
|
||||
`Failed to parse response: ${
|
||||
error instanceof Error ? error.message : "unknown"
|
||||
}`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a fetch Headers object to a plain JavaScript object.
|
||||
*
|
||||
* The fetch API returns headers as a Headers object with methods like get(), has(),
|
||||
* etc. However, the rest of the MSAL codebase expects headers as a simple key-value
|
||||
* object. This function performs that conversion.
|
||||
*
|
||||
* @param headers - The Headers object returned by fetch response
|
||||
* @returns A plain object with header names as keys and values as strings
|
||||
*/
|
||||
function getHeaderDict(headers: Headers): Record<string, string> {
|
||||
const headerDict: Record<string, string> = {};
|
||||
|
||||
headers.forEach((value: string, key: string) => {
|
||||
headerDict[key] = value;
|
||||
});
|
||||
|
||||
return headerDict;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts NetworkRequestOptions headers to a fetch-compatible Headers object.
|
||||
*
|
||||
* The MSAL library uses plain objects for headers in NetworkRequestOptions,
|
||||
* but the fetch API expects either a Headers object, plain object, or array
|
||||
* of arrays. Using the Headers constructor provides better compatibility
|
||||
* and validation.
|
||||
*
|
||||
* @param options - Optional NetworkRequestOptions containing headers
|
||||
* @returns A Headers object ready for use with fetch API
|
||||
*/
|
||||
function getFetchHeaders(options?: NetworkRequestOptions): Headers {
|
||||
const headers = new Headers();
|
||||
|
||||
if (!(options && options.headers)) {
|
||||
return headers;
|
||||
}
|
||||
|
||||
Object.entries(options.headers).forEach(([key, value]) => {
|
||||
headers.append(key, value);
|
||||
});
|
||||
|
||||
return headers;
|
||||
}
|
||||
89
backend/node_modules/@azure/msal-node/src/network/HttpClientWithRetries.ts
generated
vendored
Normal file
89
backend/node_modules/@azure/msal-node/src/network/HttpClientWithRetries.ts
generated
vendored
Normal file
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import {
|
||||
Constants,
|
||||
INetworkModule,
|
||||
Logger,
|
||||
NetworkRequestOptions,
|
||||
NetworkResponse,
|
||||
} from "@azure/msal-common/node";
|
||||
import { IHttpRetryPolicy } from "../retry/IHttpRetryPolicy.js";
|
||||
import { HttpMethod } from "../utils/Constants.js";
|
||||
|
||||
export class HttpClientWithRetries implements INetworkModule {
|
||||
private httpClientNoRetries: INetworkModule;
|
||||
private retryPolicy: IHttpRetryPolicy;
|
||||
private logger: Logger;
|
||||
|
||||
constructor(
|
||||
httpClientNoRetries: INetworkModule,
|
||||
retryPolicy: IHttpRetryPolicy,
|
||||
logger: Logger
|
||||
) {
|
||||
this.httpClientNoRetries = httpClientNoRetries;
|
||||
this.retryPolicy = retryPolicy;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
private async sendNetworkRequestAsyncHelper<T>(
|
||||
httpMethod: HttpMethod,
|
||||
url: string,
|
||||
options?: NetworkRequestOptions
|
||||
): Promise<NetworkResponse<T>> {
|
||||
if (httpMethod === HttpMethod.GET) {
|
||||
return this.httpClientNoRetries.sendGetRequestAsync(url, options);
|
||||
} else {
|
||||
return this.httpClientNoRetries.sendPostRequestAsync(url, options);
|
||||
}
|
||||
}
|
||||
|
||||
private async sendNetworkRequestAsync<T>(
|
||||
httpMethod: HttpMethod,
|
||||
url: string,
|
||||
options?: NetworkRequestOptions
|
||||
): Promise<NetworkResponse<T>> {
|
||||
// the underlying network module (custom or HttpClient) will make the call
|
||||
let response: NetworkResponse<T> =
|
||||
await this.sendNetworkRequestAsyncHelper(httpMethod, url, options);
|
||||
|
||||
if ("isNewRequest" in this.retryPolicy) {
|
||||
this.retryPolicy.isNewRequest = true;
|
||||
}
|
||||
|
||||
let currentRetry: number = 0;
|
||||
while (
|
||||
await this.retryPolicy.pauseForRetry(
|
||||
response.status,
|
||||
currentRetry,
|
||||
this.logger,
|
||||
response.headers[Constants.HeaderNames.RETRY_AFTER]
|
||||
)
|
||||
) {
|
||||
response = await this.sendNetworkRequestAsyncHelper(
|
||||
httpMethod,
|
||||
url,
|
||||
options
|
||||
);
|
||||
currentRetry++;
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
public async sendGetRequestAsync<T>(
|
||||
url: string,
|
||||
options?: NetworkRequestOptions
|
||||
): Promise<NetworkResponse<T>> {
|
||||
return this.sendNetworkRequestAsync(HttpMethod.GET, url, options);
|
||||
}
|
||||
|
||||
public async sendPostRequestAsync<T>(
|
||||
url: string,
|
||||
options?: NetworkRequestOptions
|
||||
): Promise<NetworkResponse<T>> {
|
||||
return this.sendNetworkRequestAsync(HttpMethod.POST, url, options);
|
||||
}
|
||||
}
|
||||
19
backend/node_modules/@azure/msal-node/src/network/ILoopbackClient.ts
generated
vendored
Normal file
19
backend/node_modules/@azure/msal-node/src/network/ILoopbackClient.ts
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import { AuthorizeResponse } from "@azure/msal-common/node";
|
||||
|
||||
/**
|
||||
* Interface for LoopbackClient allowing to replace the default loopback server with a custom implementation.
|
||||
* @public
|
||||
*/
|
||||
export interface ILoopbackClient {
|
||||
listenForAuthCode(
|
||||
successTemplate?: string,
|
||||
errorTemplate?: string
|
||||
): Promise<AuthorizeResponse>;
|
||||
getRedirectUri(): string;
|
||||
closeServer(): void;
|
||||
}
|
||||
116
backend/node_modules/@azure/msal-node/src/network/LoopbackClient.ts
generated
vendored
Normal file
116
backend/node_modules/@azure/msal-node/src/network/LoopbackClient.ts
generated
vendored
Normal file
@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import {
|
||||
AuthorizeResponse,
|
||||
Constants as CommonConstants,
|
||||
UrlUtils,
|
||||
} from "@azure/msal-common/node";
|
||||
import http from "http";
|
||||
import { NodeAuthError } from "../error/NodeAuthError.js";
|
||||
import { Constants } from "../utils/Constants.js";
|
||||
import { ILoopbackClient } from "./ILoopbackClient.js";
|
||||
|
||||
export class LoopbackClient implements ILoopbackClient {
|
||||
private server: http.Server | undefined;
|
||||
|
||||
/**
|
||||
* Spins up a loopback server which returns the server response when the localhost redirectUri is hit
|
||||
* @param successTemplate
|
||||
* @param errorTemplate
|
||||
* @returns
|
||||
*/
|
||||
async listenForAuthCode(
|
||||
successTemplate?: string,
|
||||
errorTemplate?: string
|
||||
): Promise<AuthorizeResponse> {
|
||||
if (this.server) {
|
||||
throw NodeAuthError.createLoopbackServerAlreadyExistsError();
|
||||
}
|
||||
|
||||
return new Promise<AuthorizeResponse>((resolve, reject) => {
|
||||
this.server = http.createServer(
|
||||
(req: http.IncomingMessage, res: http.ServerResponse) => {
|
||||
const url = req.url;
|
||||
if (!url) {
|
||||
res.end(
|
||||
errorTemplate ||
|
||||
"Error occurred loading redirectUrl"
|
||||
);
|
||||
reject(
|
||||
NodeAuthError.createUnableToLoadRedirectUrlError()
|
||||
);
|
||||
return;
|
||||
} else if (url === CommonConstants.FORWARD_SLASH) {
|
||||
res.end(
|
||||
successTemplate ||
|
||||
"Auth code was successfully acquired. You can close this window now."
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const redirectUri = this.getRedirectUri();
|
||||
const parsedUrl = new URL(url, redirectUri);
|
||||
const authCodeResponse =
|
||||
UrlUtils.getDeserializedResponse(parsedUrl.search) ||
|
||||
{};
|
||||
if (authCodeResponse.code) {
|
||||
res.writeHead(CommonConstants.HTTP_REDIRECT, {
|
||||
location: redirectUri,
|
||||
}); // Prevent auth code from being saved in the browser history
|
||||
res.end();
|
||||
}
|
||||
if (authCodeResponse.error) {
|
||||
res.end(
|
||||
errorTemplate ||
|
||||
`Error occurred: ${authCodeResponse.error}`
|
||||
);
|
||||
}
|
||||
resolve(authCodeResponse);
|
||||
}
|
||||
);
|
||||
this.server.listen(0, "127.0.0.1"); // Listen on any available port
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the port that the loopback server is running on
|
||||
* @returns
|
||||
*/
|
||||
getRedirectUri(): string {
|
||||
if (!this.server || !this.server.listening) {
|
||||
throw NodeAuthError.createNoLoopbackServerExistsError();
|
||||
}
|
||||
|
||||
const address = this.server.address();
|
||||
if (!address || typeof address === "string" || !address.port) {
|
||||
this.closeServer();
|
||||
throw NodeAuthError.createInvalidLoopbackAddressTypeError();
|
||||
}
|
||||
|
||||
const port = address && address.port;
|
||||
|
||||
return `${Constants.HTTP_PROTOCOL}${Constants.LOCALHOST}:${port}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the loopback server
|
||||
*/
|
||||
closeServer(): void {
|
||||
if (this.server) {
|
||||
// Only stops accepting new connections, server will close once open/idle connections are closed.
|
||||
this.server.close();
|
||||
|
||||
if (typeof this.server.closeAllConnections === "function") {
|
||||
/*
|
||||
* Close open/idle connections. This API is available in Node versions 18.2 and higher
|
||||
*/
|
||||
this.server.closeAllConnections();
|
||||
}
|
||||
this.server.unref();
|
||||
this.server = undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
backend/node_modules/@azure/msal-node/src/packageMetadata.ts
generated
vendored
Normal file
3
backend/node_modules/@azure/msal-node/src/packageMetadata.ts
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
/* eslint-disable header/header */
|
||||
export const name = "@azure/msal-node";
|
||||
export const version = "5.2.2";
|
||||
72
backend/node_modules/@azure/msal-node/src/protocol/Authorize.ts
generated
vendored
Normal file
72
backend/node_modules/@azure/msal-node/src/protocol/Authorize.ts
generated
vendored
Normal file
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import {
|
||||
Authority,
|
||||
AuthorizeProtocol,
|
||||
CommonAuthorizationUrlRequest,
|
||||
Logger,
|
||||
Constants,
|
||||
ProtocolMode,
|
||||
RequestParameterBuilder,
|
||||
} from "@azure/msal-common/node";
|
||||
import { NodeConfiguration } from "../config/Configuration.js";
|
||||
import { Constants as NodeConstants } from "../utils/Constants.js";
|
||||
import { version } from "../packageMetadata.js";
|
||||
|
||||
/**
|
||||
* Constructs the full /authorize URL with request parameters
|
||||
* @param config
|
||||
* @param authority
|
||||
* @param request
|
||||
* @param logger
|
||||
* @returns
|
||||
*/
|
||||
export function getAuthCodeRequestUrl(
|
||||
config: NodeConfiguration,
|
||||
authority: Authority,
|
||||
request: CommonAuthorizationUrlRequest,
|
||||
logger: Logger
|
||||
): string {
|
||||
const parameters = AuthorizeProtocol.getStandardAuthorizeRequestParameters(
|
||||
{
|
||||
...config.auth,
|
||||
authority: authority,
|
||||
redirectUri: request.redirectUri || "",
|
||||
},
|
||||
request,
|
||||
logger
|
||||
);
|
||||
RequestParameterBuilder.addLibraryInfo(parameters, {
|
||||
sku: NodeConstants.MSAL_SKU,
|
||||
version: version,
|
||||
cpu: process.arch || "",
|
||||
os: process.platform || "",
|
||||
});
|
||||
if (config.system.protocolMode !== ProtocolMode.OIDC) {
|
||||
RequestParameterBuilder.addApplicationTelemetry(
|
||||
parameters,
|
||||
config.telemetry.application
|
||||
);
|
||||
}
|
||||
RequestParameterBuilder.addResponseType(
|
||||
parameters,
|
||||
Constants.OAuthResponseType.CODE
|
||||
);
|
||||
if (request.codeChallenge && request.codeChallengeMethod) {
|
||||
RequestParameterBuilder.addCodeChallengeParams(
|
||||
parameters,
|
||||
request.codeChallenge,
|
||||
request.codeChallengeMethod
|
||||
);
|
||||
}
|
||||
|
||||
RequestParameterBuilder.addExtraParameters(
|
||||
parameters,
|
||||
request.extraQueryParameters || {}
|
||||
);
|
||||
|
||||
return AuthorizeProtocol.getAuthorizeUrl(authority, parameters);
|
||||
}
|
||||
40
backend/node_modules/@azure/msal-node/src/request/AuthorizationCodeRequest.ts
generated
vendored
Normal file
40
backend/node_modules/@azure/msal-node/src/request/AuthorizationCodeRequest.ts
generated
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import { CommonAuthorizationCodeRequest } from "@azure/msal-common/node";
|
||||
|
||||
/**
|
||||
* Request object passed by user to acquire a token from the server exchanging a valid authorization code (second leg of OAuth2.0 Authorization Code flow)
|
||||
* @public
|
||||
*/
|
||||
export type AuthorizationCodeRequest = Partial<
|
||||
Omit<
|
||||
CommonAuthorizationCodeRequest,
|
||||
| "scopes"
|
||||
| "redirectUri"
|
||||
| "code"
|
||||
| "authenticationScheme"
|
||||
| "resourceRequestMethod"
|
||||
| "resourceRequestUri"
|
||||
| "storeInCache"
|
||||
>
|
||||
> & {
|
||||
/**
|
||||
* Array of scopes the application is requesting access to.
|
||||
*/
|
||||
scopes: Array<string>;
|
||||
/**
|
||||
* The redirect URI of your app, where the authority will redirect to after the user inputs credentials and consents. It must exactly match one of the redirect URIs you registered in the portal.
|
||||
*/
|
||||
redirectUri: string;
|
||||
/**
|
||||
* The authorization_code that the user acquired in the first leg of the flow.
|
||||
*/
|
||||
code: string;
|
||||
/**
|
||||
* Unique GUID generated by the user that is cached by the user and sent to the server during the first leg of the flow. This string is sent back by the server with the authorization code. The user cached state is then compared with the state received from the server to mitigate the risk of CSRF attacks. See https://datatracker.ietf.org/doc/html/rfc6819#section-3.6.
|
||||
*/
|
||||
state?: string;
|
||||
};
|
||||
31
backend/node_modules/@azure/msal-node/src/request/AuthorizationUrlRequest.ts
generated
vendored
Normal file
31
backend/node_modules/@azure/msal-node/src/request/AuthorizationUrlRequest.ts
generated
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import { CommonAuthorizationUrlRequest } from "@azure/msal-common/node";
|
||||
|
||||
/**
|
||||
* Request object passed by user to retrieve a Code from the server (first leg of authorization code grant flow)
|
||||
* @public
|
||||
*/
|
||||
export type AuthorizationUrlRequest = Partial<
|
||||
Omit<
|
||||
CommonAuthorizationUrlRequest,
|
||||
| "scopes"
|
||||
| "redirectUri"
|
||||
| "resourceRequestMethod"
|
||||
| "resourceRequestUri"
|
||||
| "authenticationScheme"
|
||||
| "storeInCache"
|
||||
>
|
||||
> & {
|
||||
/**
|
||||
* Array of scopes the application is requesting access to.
|
||||
*/
|
||||
scopes: Array<string>;
|
||||
/**
|
||||
* The redirect URI where authentication responses can be received by your application. It must exactly match one of the redirect URIs registered in the Azure portal.
|
||||
*/
|
||||
redirectUri: string;
|
||||
};
|
||||
26
backend/node_modules/@azure/msal-node/src/request/ClientCredentialRequest.ts
generated
vendored
Normal file
26
backend/node_modules/@azure/msal-node/src/request/ClientCredentialRequest.ts
generated
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import { ClientAssertionCallback } from "@azure/msal-common/node";
|
||||
import { CommonClientCredentialRequest } from "./CommonClientCredentialRequest.js";
|
||||
|
||||
/**
|
||||
* ClientCredentialRequest
|
||||
* @public
|
||||
*/
|
||||
export type ClientCredentialRequest = Partial<
|
||||
Omit<
|
||||
CommonClientCredentialRequest,
|
||||
| "resourceRequestMethod"
|
||||
| "resourceRequestUri"
|
||||
| "clientAssertion"
|
||||
| "storeInCache"
|
||||
>
|
||||
> & {
|
||||
/**
|
||||
* An assertion string or a callback function that returns an assertion string (both are Base64Url-encoded signed JWTs) used in the Client Credential flow
|
||||
*/
|
||||
clientAssertion?: string | ClientAssertionCallback;
|
||||
};
|
||||
31
backend/node_modules/@azure/msal-node/src/request/CommonClientCredentialRequest.ts
generated
vendored
Normal file
31
backend/node_modules/@azure/msal-node/src/request/CommonClientCredentialRequest.ts
generated
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import {
|
||||
BaseAuthRequest,
|
||||
AzureRegion,
|
||||
ClientAssertion,
|
||||
} from "@azure/msal-common/node";
|
||||
|
||||
/**
|
||||
* CommonClientCredentialRequest
|
||||
*/
|
||||
export type CommonClientCredentialRequest = Omit<
|
||||
BaseAuthRequest,
|
||||
"extraQueryParameters" | "extraParameters"
|
||||
> & {
|
||||
/**
|
||||
* Skip token cache lookup and force request to authority to get a a new token. Defaults to false.
|
||||
*/
|
||||
skipCache?: boolean;
|
||||
/**
|
||||
* Azure region to be used for regional authentication.
|
||||
*/
|
||||
azureRegion?: AzureRegion;
|
||||
/**
|
||||
* An assertion string or a callback function that returns an assertion string (both are Base64Url-encoded signed JWTs) used in the Client Credential flow.
|
||||
*/
|
||||
clientAssertion?: ClientAssertion;
|
||||
};
|
||||
32
backend/node_modules/@azure/msal-node/src/request/CommonDeviceCodeRequest.ts
generated
vendored
Normal file
32
backend/node_modules/@azure/msal-node/src/request/CommonDeviceCodeRequest.ts
generated
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import {
|
||||
DeviceCodeResponse,
|
||||
StringDict,
|
||||
BaseAuthRequest,
|
||||
} from "@azure/msal-common/node";
|
||||
|
||||
/**
|
||||
* Parameters for Oauth2 device code flow.
|
||||
*/
|
||||
export type CommonDeviceCodeRequest = BaseAuthRequest & {
|
||||
/**
|
||||
* Callback containing device code response. Message should be shown to end user. End user can then navigate to the verification_uri, input the user_code, and input credentials.
|
||||
*/
|
||||
deviceCodeCallback: (response: DeviceCodeResponse) => void;
|
||||
/**
|
||||
* Boolean to cancel polling of device code endpoint. While the user authenticates on a separate device, MSAL polls the the token endpoint of security token service for the interval specified in the device code response (usually 15 minutes). To stop polling and cancel the request, set cancel=true.
|
||||
*/
|
||||
cancel?: boolean;
|
||||
/**
|
||||
* Timeout period in seconds which the user explicitly configures for the polling of the device code endpoint. At the end of this period; assuming the device code has not expired yet; the device code polling is stopped and the request cancelled. The device code expiration window will always take precedence over this set period.
|
||||
*/
|
||||
timeout?: number;
|
||||
/**
|
||||
* String to string map of custom query parameters added to outgoing token service requests.
|
||||
*/
|
||||
extraQueryParameters?: StringDict;
|
||||
};
|
||||
23
backend/node_modules/@azure/msal-node/src/request/CommonOnBehalfOfRequest.ts
generated
vendored
Normal file
23
backend/node_modules/@azure/msal-node/src/request/CommonOnBehalfOfRequest.ts
generated
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import { BaseAuthRequest } from "@azure/msal-common/node";
|
||||
|
||||
/**
|
||||
* CommonOnBehalfOfRequest
|
||||
*/
|
||||
export type CommonOnBehalfOfRequest = Omit<
|
||||
BaseAuthRequest,
|
||||
"extraQueryParameters" | "extraParameters"
|
||||
> & {
|
||||
/**
|
||||
* The access token that was sent to the middle-tier API. This token must have an audience of the app making this OBO request.
|
||||
*/
|
||||
oboAssertion: string;
|
||||
/**
|
||||
* Skip token cache lookup and force request to authority to get a a new token. Defaults to false.
|
||||
*/
|
||||
skipCache?: boolean;
|
||||
};
|
||||
21
backend/node_modules/@azure/msal-node/src/request/CommonUsernamePasswordRequest.ts
generated
vendored
Normal file
21
backend/node_modules/@azure/msal-node/src/request/CommonUsernamePasswordRequest.ts
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import { BaseAuthRequest } from "@azure/msal-common/node";
|
||||
|
||||
/**
|
||||
* CommonUsernamePassword parameters passed by the user to retrieve credentials
|
||||
* Note: The latest OAuth 2.0 Security Best Current Practice disallows the password grant entirely. This flow is added for internal testing.
|
||||
*/
|
||||
export type CommonUsernamePasswordRequest = BaseAuthRequest & {
|
||||
/**
|
||||
* Username of the client
|
||||
*/
|
||||
username: string;
|
||||
/**
|
||||
* Credentials
|
||||
*/
|
||||
password: string;
|
||||
};
|
||||
31
backend/node_modules/@azure/msal-node/src/request/DeviceCodeRequest.ts
generated
vendored
Normal file
31
backend/node_modules/@azure/msal-node/src/request/DeviceCodeRequest.ts
generated
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import { DeviceCodeResponse } from "@azure/msal-common/node";
|
||||
import { CommonDeviceCodeRequest } from "./CommonDeviceCodeRequest.js";
|
||||
|
||||
/**
|
||||
* Parameters for Oauth2 device code flow.
|
||||
* @public
|
||||
*/
|
||||
export type DeviceCodeRequest = Partial<
|
||||
Omit<
|
||||
CommonDeviceCodeRequest,
|
||||
| "scopes"
|
||||
| "deviceCodeCallback"
|
||||
| "resourceRequestMethod"
|
||||
| "resourceRequestUri"
|
||||
| "storeInCache"
|
||||
>
|
||||
> & {
|
||||
/**
|
||||
* Array of scopes the application is requesting access to.
|
||||
*/
|
||||
scopes: Array<string>;
|
||||
/**
|
||||
* Callback containing device code response. Message should be shown to end user. End user can then navigate to the verification_uri, input the user_code, and input credentials.
|
||||
*/
|
||||
deviceCodeCallback: (response: DeviceCodeResponse) => void;
|
||||
};
|
||||
40
backend/node_modules/@azure/msal-node/src/request/InteractiveRequest.ts
generated
vendored
Normal file
40
backend/node_modules/@azure/msal-node/src/request/InteractiveRequest.ts
generated
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import { CommonAuthorizationUrlRequest } from "@azure/msal-common/node";
|
||||
import { ILoopbackClient } from "../network/ILoopbackClient.js";
|
||||
|
||||
/**
|
||||
* Request object passed by user to configure acquireTokenInteractive API
|
||||
* @public
|
||||
*/
|
||||
export type InteractiveRequest = Partial<
|
||||
Omit<CommonAuthorizationUrlRequest, "scopes" | "storeInCache">
|
||||
> & {
|
||||
/**
|
||||
* Function to open a browser instance on user's system.
|
||||
*/
|
||||
openBrowser: (url: string) => Promise<void>;
|
||||
/**
|
||||
* Array of scopes the application is requesting access to.
|
||||
*/
|
||||
scopes?: Array<string>;
|
||||
/**
|
||||
* Template to be displayed on the opened browser instance upon successful token acquisition.
|
||||
*/
|
||||
successTemplate?: string;
|
||||
/**
|
||||
* Template to be displayed on the opened browser instance upon token acquisition failure.
|
||||
*/
|
||||
errorTemplate?: string;
|
||||
/**
|
||||
* Used in native broker flows to properly parent the native broker window
|
||||
*/
|
||||
windowHandle?: Buffer; // Relevant only to brokered requests
|
||||
/**
|
||||
* Custom implementation for a loopback server to listen for authorization code response.
|
||||
*/
|
||||
loopbackClient?: ILoopbackClient;
|
||||
};
|
||||
22
backend/node_modules/@azure/msal-node/src/request/ManagedIdentityRequest.ts
generated
vendored
Normal file
22
backend/node_modules/@azure/msal-node/src/request/ManagedIdentityRequest.ts
generated
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import { CommonClientCredentialRequest } from "./CommonClientCredentialRequest.js";
|
||||
import { ManagedIdentityRequestParams } from "./ManagedIdentityRequestParams.js";
|
||||
|
||||
/**
|
||||
* ManagedIdentityRequest
|
||||
*/
|
||||
export type ManagedIdentityRequest = ManagedIdentityRequestParams &
|
||||
CommonClientCredentialRequest & {
|
||||
/**
|
||||
* An array of capabilities to be added to all network requests as part of the `xms_cc` claim
|
||||
*/
|
||||
clientCapabilities?: Array<string>;
|
||||
/**
|
||||
* A SHA256 hash of the token that was revoked. The managed identity will revoke the token based on the SHA256 hash of the token, not the token itself. This is to prevent the token from being leaked in transit.
|
||||
*/
|
||||
revokedTokenSha256Hash?: string;
|
||||
};
|
||||
23
backend/node_modules/@azure/msal-node/src/request/ManagedIdentityRequestParams.ts
generated
vendored
Normal file
23
backend/node_modules/@azure/msal-node/src/request/ManagedIdentityRequestParams.ts
generated
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* ManagedIdentityRequest
|
||||
* @public
|
||||
*/
|
||||
export type ManagedIdentityRequestParams = {
|
||||
/**
|
||||
* A stringified claims request which will be used to determine whether or not the cache should be skipped
|
||||
*/
|
||||
claims?: string;
|
||||
/**
|
||||
* Forces managed identity requests to skip the cache and make network calls if true
|
||||
*/
|
||||
forceRefresh?: boolean;
|
||||
/**
|
||||
* Resource requested to access the protected API. It should be of the form "ResourceIdUri" or "ResourceIdUri/.default". For instance https://management.azure.net or, for Microsoft Graph, https://graph.microsoft.com/.default
|
||||
*/
|
||||
resource: string;
|
||||
};
|
||||
30
backend/node_modules/@azure/msal-node/src/request/OnBehalfOfRequest.ts
generated
vendored
Normal file
30
backend/node_modules/@azure/msal-node/src/request/OnBehalfOfRequest.ts
generated
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import { CommonOnBehalfOfRequest } from "./CommonOnBehalfOfRequest.js";
|
||||
|
||||
/**
|
||||
* OnBehalfOfRequest
|
||||
* @public
|
||||
*/
|
||||
export type OnBehalfOfRequest = Partial<
|
||||
Omit<
|
||||
CommonOnBehalfOfRequest,
|
||||
| "oboAssertion"
|
||||
| "scopes"
|
||||
| "resourceRequestMethod"
|
||||
| "resourceRequestUri"
|
||||
| "storeInCache"
|
||||
>
|
||||
> & {
|
||||
/**
|
||||
* The access token that was sent to the middle-tier API. This token must have an audience of the app making this OBO request.
|
||||
*/
|
||||
oboAssertion: string;
|
||||
/**
|
||||
* Array of scopes the application is requesting access to.
|
||||
*/
|
||||
scopes: Array<string>;
|
||||
};
|
||||
35
backend/node_modules/@azure/msal-node/src/request/RefreshTokenRequest.ts
generated
vendored
Normal file
35
backend/node_modules/@azure/msal-node/src/request/RefreshTokenRequest.ts
generated
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import { CommonRefreshTokenRequest } from "@azure/msal-common/node";
|
||||
|
||||
/**
|
||||
* CommonRefreshTokenRequest
|
||||
* @public
|
||||
*/
|
||||
export type RefreshTokenRequest = Partial<
|
||||
Omit<
|
||||
CommonRefreshTokenRequest,
|
||||
| "scopes"
|
||||
| "refreshToken"
|
||||
| "authenticationScheme"
|
||||
| "resourceRequestMethod"
|
||||
| "resourceRequestUri"
|
||||
| "storeInCache"
|
||||
>
|
||||
> & {
|
||||
/**
|
||||
* Array of scopes the application is requesting access to.
|
||||
*/
|
||||
scopes: Array<string>;
|
||||
/**
|
||||
* A refresh token returned from a previous request to the Identity provider.
|
||||
*/
|
||||
refreshToken: string;
|
||||
/**
|
||||
* Force MSAL to cache a refresh token flow response when there is no account in the cache. Used for migration scenarios.
|
||||
*/
|
||||
forceCache?: boolean;
|
||||
};
|
||||
12
backend/node_modules/@azure/msal-node/src/request/SignOutRequest.ts
generated
vendored
Normal file
12
backend/node_modules/@azure/msal-node/src/request/SignOutRequest.ts
generated
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import { AccountInfo } from "@azure/msal-common/node";
|
||||
|
||||
/** @public */
|
||||
export type SignOutRequest = {
|
||||
account: AccountInfo;
|
||||
correlationId?: string;
|
||||
};
|
||||
23
backend/node_modules/@azure/msal-node/src/request/SilentFlowRequest.ts
generated
vendored
Normal file
23
backend/node_modules/@azure/msal-node/src/request/SilentFlowRequest.ts
generated
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import { AccountInfo, CommonSilentFlowRequest } from "@azure/msal-common/node";
|
||||
|
||||
/**
|
||||
* SilentFlow parameters passed by the user to retrieve credentials silently
|
||||
* @public
|
||||
*/
|
||||
export type SilentFlowRequest = Partial<
|
||||
Omit<CommonSilentFlowRequest, "account" | "scopes" | "storeInCache">
|
||||
> & {
|
||||
/**
|
||||
* Account entity to lookup the credentials.
|
||||
*/
|
||||
account: AccountInfo;
|
||||
/**
|
||||
* Array of scopes the application is requesting access to.
|
||||
*/
|
||||
scopes: Array<string>;
|
||||
};
|
||||
36
backend/node_modules/@azure/msal-node/src/request/UsernamePasswordRequest.ts
generated
vendored
Normal file
36
backend/node_modules/@azure/msal-node/src/request/UsernamePasswordRequest.ts
generated
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import { CommonUsernamePasswordRequest } from "./CommonUsernamePasswordRequest.js";
|
||||
|
||||
/**
|
||||
* UsernamePassword parameters passed by the user to retrieve credentials
|
||||
* Note: The latest OAuth 2.0 Security Best Current Practice disallows the password grant entirely. This flow is added for internal testing.
|
||||
* @public
|
||||
*/
|
||||
export type UsernamePasswordRequest = Partial<
|
||||
Omit<
|
||||
CommonUsernamePasswordRequest,
|
||||
| "scopes"
|
||||
| "resourceRequestMethod"
|
||||
| "resourceRequestUri"
|
||||
| "username"
|
||||
| "password"
|
||||
| "storeInCache"
|
||||
>
|
||||
> & {
|
||||
/**
|
||||
* Array of scopes the application is requesting access to.
|
||||
*/
|
||||
scopes: Array<string>;
|
||||
/**
|
||||
* Username of the client
|
||||
*/
|
||||
username: string;
|
||||
/**
|
||||
* Credentials
|
||||
*/
|
||||
password: string;
|
||||
};
|
||||
55
backend/node_modules/@azure/msal-node/src/response/ManagedIdentityTokenResponse.ts
generated
vendored
Normal file
55
backend/node_modules/@azure/msal-node/src/response/ManagedIdentityTokenResponse.ts
generated
vendored
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import { Constants } from "@azure/msal-common/node";
|
||||
|
||||
/**
|
||||
* Deserialized response object from server managed identity request.
|
||||
*
|
||||
* In case of success:
|
||||
* - access_token - The requested access token. When called via a secured REST API, the token is embedded in the Authorization request header field as a "bearer" token, allowing the API to authenticate the caller
|
||||
* - client_id - A unique identifier generated by Azure AD for the Azure Resource. The Client ID is a GUID value that uniquely identifies the application and its configuration within the identity platform
|
||||
* - expires_on - The timespan when the access token expires. The date is represented as the number of seconds from "1970-01-01T0:0:0Z UTC" (corresponds to the token's exp claim)
|
||||
* - resource - The resource the access token was requested for. It matches the resource query string parameter of the request
|
||||
* - token_type - The type of token returned by the Managed Identity endpoint. It's a "Bearer" access token, which means the resource can give access to the bearer of this token
|
||||
*
|
||||
* In case of error:
|
||||
* - message: A specific error message that can help a developer identify the root cause of an authentication error.
|
||||
* - correlationId: A unique identifier for the request that can help in diagnostics across components.
|
||||
*/
|
||||
export type ManagedIdentityTokenResponse = {
|
||||
// success
|
||||
access_token?: string;
|
||||
client_id?: string;
|
||||
expires_on?: number; // will be converted to expires_in
|
||||
resource?: string; // equivalent to ServerAuthorizationTokenResponse's "scope" field
|
||||
token_type?: Constants.AuthenticationScheme;
|
||||
|
||||
// error
|
||||
|
||||
/*
|
||||
* (Web/Function) App Service
|
||||
* 500 errors can return this from all MI sources as well
|
||||
*/
|
||||
message?: string;
|
||||
correlationId?: string;
|
||||
|
||||
// IMDS, Azure Arc, Service Fabric (unconfirmed)
|
||||
error?: string | ErrorObject;
|
||||
error_description?: string;
|
||||
error_codes?: Array<string>;
|
||||
correlation_id?: string;
|
||||
timestamp?: string;
|
||||
trace_id?: string;
|
||||
};
|
||||
|
||||
/*
|
||||
* This is the only error property that exists for Cloud Shell
|
||||
* It can also be the only thing App Service will return
|
||||
*/
|
||||
export type ErrorObject = {
|
||||
code: string;
|
||||
message: string;
|
||||
};
|
||||
71
backend/node_modules/@azure/msal-node/src/retry/DefaultManagedIdentityRetryPolicy.ts
generated
vendored
Normal file
71
backend/node_modules/@azure/msal-node/src/retry/DefaultManagedIdentityRetryPolicy.ts
generated
vendored
Normal file
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import { IncomingHttpHeaders } from "http";
|
||||
import { Constants, Logger } from "@azure/msal-common/node";
|
||||
import { IHttpRetryPolicy } from "./IHttpRetryPolicy.js";
|
||||
import { LinearRetryStrategy } from "./LinearRetryStrategy.js";
|
||||
|
||||
export const DEFAULT_MANAGED_IDENTITY_MAX_RETRIES: number = 3; // referenced in unit test
|
||||
const DEFAULT_MANAGED_IDENTITY_RETRY_DELAY_MS: number = 1000;
|
||||
const DEFAULT_MANAGED_IDENTITY_HTTP_STATUS_CODES_TO_RETRY_ON: Array<number> = [
|
||||
Constants.HTTP_NOT_FOUND,
|
||||
Constants.HTTP_REQUEST_TIMEOUT,
|
||||
Constants.HTTP_TOO_MANY_REQUESTS,
|
||||
Constants.HTTP_SERVER_ERROR,
|
||||
Constants.HTTP_SERVICE_UNAVAILABLE,
|
||||
Constants.HTTP_GATEWAY_TIMEOUT,
|
||||
];
|
||||
|
||||
export class DefaultManagedIdentityRetryPolicy implements IHttpRetryPolicy {
|
||||
/*
|
||||
* this is defined here as a static variable despite being defined as a constant outside of the
|
||||
* class because it needs to be overridden in the unit tests so that the unit tests run faster
|
||||
*/
|
||||
static get DEFAULT_MANAGED_IDENTITY_RETRY_DELAY_MS(): number {
|
||||
return DEFAULT_MANAGED_IDENTITY_RETRY_DELAY_MS;
|
||||
}
|
||||
|
||||
private linearRetryStrategy: LinearRetryStrategy =
|
||||
new LinearRetryStrategy();
|
||||
|
||||
async pauseForRetry(
|
||||
httpStatusCode: number,
|
||||
currentRetry: number,
|
||||
logger: Logger,
|
||||
retryAfterHeader: IncomingHttpHeaders["retry-after"]
|
||||
): Promise<boolean> {
|
||||
if (
|
||||
DEFAULT_MANAGED_IDENTITY_HTTP_STATUS_CODES_TO_RETRY_ON.includes(
|
||||
httpStatusCode
|
||||
) &&
|
||||
currentRetry < DEFAULT_MANAGED_IDENTITY_MAX_RETRIES
|
||||
) {
|
||||
const retryAfterDelay: number =
|
||||
this.linearRetryStrategy.calculateDelay(
|
||||
retryAfterHeader,
|
||||
DefaultManagedIdentityRetryPolicy.DEFAULT_MANAGED_IDENTITY_RETRY_DELAY_MS
|
||||
);
|
||||
|
||||
logger.verbose(
|
||||
`Retrying request in ${retryAfterDelay}ms (retry attempt: ${
|
||||
currentRetry + 1
|
||||
})`,
|
||||
""
|
||||
);
|
||||
|
||||
// pause execution for the calculated delay
|
||||
await new Promise((resolve) => {
|
||||
// retryAfterHeader value of 0 evaluates to false, and DEFAULT_MANAGED_IDENTITY_RETRY_DELAY_MS will be used
|
||||
return setTimeout(resolve, retryAfterDelay);
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// if the status code is not retriable or max retries have been reached, do not retry
|
||||
return false;
|
||||
}
|
||||
}
|
||||
53
backend/node_modules/@azure/msal-node/src/retry/ExponentialRetryStrategy.ts
generated
vendored
Normal file
53
backend/node_modules/@azure/msal-node/src/retry/ExponentialRetryStrategy.ts
generated
vendored
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
export class ExponentialRetryStrategy {
|
||||
// Minimum backoff time in milliseconds
|
||||
private minExponentialBackoff: number;
|
||||
// Maximum backoff time in milliseconds
|
||||
private maxExponentialBackoff: number;
|
||||
// Maximum backoff time in milliseconds
|
||||
private exponentialDeltaBackoff: number;
|
||||
|
||||
constructor(
|
||||
minExponentialBackoff: number,
|
||||
maxExponentialBackoff: number,
|
||||
exponentialDeltaBackoff: number
|
||||
) {
|
||||
this.minExponentialBackoff = minExponentialBackoff;
|
||||
this.maxExponentialBackoff = maxExponentialBackoff;
|
||||
this.exponentialDeltaBackoff = exponentialDeltaBackoff;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the exponential delay based on the current retry attempt.
|
||||
*
|
||||
* @param {number} currentRetry - The current retry attempt number.
|
||||
* @returns {number} - The calculated exponential delay in milliseconds.
|
||||
*
|
||||
* The delay is calculated using the formula:
|
||||
* - If `currentRetry` is 0, it returns the minimum backoff time.
|
||||
* - Otherwise, it calculates the delay as the minimum of:
|
||||
* - `(2^(currentRetry - 1)) * deltaBackoff`
|
||||
* - `maxBackoff`
|
||||
*
|
||||
* This ensures that the delay increases exponentially with each retry attempt,
|
||||
* but does not exceed the maximum backoff time.
|
||||
*/
|
||||
public calculateDelay(currentRetry: number): number {
|
||||
// Attempt 1
|
||||
if (currentRetry === 0) {
|
||||
return this.minExponentialBackoff;
|
||||
}
|
||||
|
||||
// Attempt 2+
|
||||
const exponentialDelay = Math.min(
|
||||
Math.pow(2, currentRetry - 1) * this.exponentialDeltaBackoff,
|
||||
this.maxExponentialBackoff
|
||||
);
|
||||
|
||||
return exponentialDelay;
|
||||
}
|
||||
}
|
||||
27
backend/node_modules/@azure/msal-node/src/retry/IHttpRetryPolicy.ts
generated
vendored
Normal file
27
backend/node_modules/@azure/msal-node/src/retry/IHttpRetryPolicy.ts
generated
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import { IncomingHttpHeaders } from "http";
|
||||
import { Logger } from "@azure/msal-common/node";
|
||||
|
||||
export interface IHttpRetryPolicy {
|
||||
_isNewRequest?: boolean;
|
||||
// set isNewRequest(value: boolean);
|
||||
|
||||
/**
|
||||
* Pauses execution for a specified amount of time before retrying an HTTP request.
|
||||
*
|
||||
* @param httpStatusCode - The HTTP status code of the response.
|
||||
* @param currentRetry - The current retry attempt number.
|
||||
* @param retryAfterHeader - The value of the `retry-after` HTTP header, if present.
|
||||
* @returns A promise that resolves to a boolean indicating whether to retry the request.
|
||||
*/
|
||||
pauseForRetry(
|
||||
httpStatusCode: number,
|
||||
currentRetry: number,
|
||||
logger: Logger,
|
||||
retryAfterHeader?: IncomingHttpHeaders["retry-after"]
|
||||
): Promise<boolean>;
|
||||
}
|
||||
122
backend/node_modules/@azure/msal-node/src/retry/ImdsRetryPolicy.ts
generated
vendored
Normal file
122
backend/node_modules/@azure/msal-node/src/retry/ImdsRetryPolicy.ts
generated
vendored
Normal file
@ -0,0 +1,122 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import { Constants, Logger } from "@azure/msal-common/node";
|
||||
import { ExponentialRetryStrategy } from "./ExponentialRetryStrategy.js";
|
||||
import { IHttpRetryPolicy } from "./IHttpRetryPolicy.js";
|
||||
|
||||
const HTTP_STATUS_400_CODES_FOR_EXPONENTIAL_STRATEGY: Array<number> = [
|
||||
Constants.HTTP_NOT_FOUND,
|
||||
Constants.HTTP_REQUEST_TIMEOUT,
|
||||
Constants.HTTP_GONE,
|
||||
Constants.HTTP_TOO_MANY_REQUESTS,
|
||||
];
|
||||
|
||||
const EXPONENTIAL_STRATEGY_NUM_RETRIES = 3;
|
||||
const LINEAR_STRATEGY_NUM_RETRIES = 7;
|
||||
|
||||
const MIN_EXPONENTIAL_BACKOFF_MS: number = 1000;
|
||||
const MAX_EXPONENTIAL_BACKOFF_MS: number = 4000;
|
||||
const EXPONENTIAL_DELTA_BACKOFF_MS: number = 2000;
|
||||
|
||||
const HTTP_STATUS_GONE_RETRY_AFTER_MS: number = 10 * 1000; // 10 seconds
|
||||
|
||||
export class ImdsRetryPolicy implements IHttpRetryPolicy {
|
||||
/*
|
||||
* these are defined here as static variables despite being defined as constants outside of the
|
||||
* class because they need to be overridden in the unit tests so that the unit tests run faster
|
||||
*/
|
||||
static get MIN_EXPONENTIAL_BACKOFF_MS(): number {
|
||||
return MIN_EXPONENTIAL_BACKOFF_MS;
|
||||
}
|
||||
static get MAX_EXPONENTIAL_BACKOFF_MS(): number {
|
||||
return MAX_EXPONENTIAL_BACKOFF_MS;
|
||||
}
|
||||
static get EXPONENTIAL_DELTA_BACKOFF_MS(): number {
|
||||
return EXPONENTIAL_DELTA_BACKOFF_MS;
|
||||
}
|
||||
static get HTTP_STATUS_GONE_RETRY_AFTER_MS(): number {
|
||||
return HTTP_STATUS_GONE_RETRY_AFTER_MS;
|
||||
}
|
||||
|
||||
public _isNewRequest: boolean;
|
||||
set isNewRequest(value: boolean) {
|
||||
this._isNewRequest = value;
|
||||
}
|
||||
|
||||
private maxRetries: number;
|
||||
|
||||
private exponentialRetryStrategy: ExponentialRetryStrategy =
|
||||
new ExponentialRetryStrategy(
|
||||
ImdsRetryPolicy.MIN_EXPONENTIAL_BACKOFF_MS,
|
||||
ImdsRetryPolicy.MAX_EXPONENTIAL_BACKOFF_MS,
|
||||
ImdsRetryPolicy.EXPONENTIAL_DELTA_BACKOFF_MS
|
||||
);
|
||||
|
||||
/**
|
||||
* Pauses execution for a calculated delay before retrying a request.
|
||||
*
|
||||
* @param httpStatusCode - The HTTP status code of the response.
|
||||
* @param currentRetry - The current retry attempt number.
|
||||
* @param retryAfterHeader - The value of the "retry-after" header from the response.
|
||||
* @returns A promise that resolves to a boolean indicating whether a retry should be attempted.
|
||||
*/
|
||||
async pauseForRetry(
|
||||
httpStatusCode: number,
|
||||
currentRetry: number,
|
||||
logger: Logger
|
||||
): Promise<boolean> {
|
||||
if (this._isNewRequest) {
|
||||
this._isNewRequest = false;
|
||||
|
||||
// calculate the maxRetries based on the status code, once per request
|
||||
this.maxRetries =
|
||||
httpStatusCode === Constants.HTTP_GONE
|
||||
? LINEAR_STRATEGY_NUM_RETRIES
|
||||
: EXPONENTIAL_STRATEGY_NUM_RETRIES;
|
||||
}
|
||||
|
||||
/**
|
||||
* (status code is one of the retriable 400 status code
|
||||
* or
|
||||
* status code is >= 500 and <= 599)
|
||||
* and
|
||||
* current count of retries is less than the max number of retries
|
||||
*/
|
||||
if (
|
||||
(HTTP_STATUS_400_CODES_FOR_EXPONENTIAL_STRATEGY.includes(
|
||||
httpStatusCode
|
||||
) ||
|
||||
(httpStatusCode >= Constants.HTTP_SERVER_ERROR_RANGE_START &&
|
||||
httpStatusCode <= Constants.HTTP_SERVER_ERROR_RANGE_END &&
|
||||
currentRetry < this.maxRetries)) &&
|
||||
currentRetry < this.maxRetries
|
||||
) {
|
||||
const retryAfterDelay: number =
|
||||
httpStatusCode === Constants.HTTP_GONE
|
||||
? ImdsRetryPolicy.HTTP_STATUS_GONE_RETRY_AFTER_MS
|
||||
: this.exponentialRetryStrategy.calculateDelay(
|
||||
currentRetry
|
||||
);
|
||||
|
||||
logger.verbose(
|
||||
`Retrying request in ${retryAfterDelay}ms (retry attempt: ${
|
||||
currentRetry + 1
|
||||
})`,
|
||||
""
|
||||
);
|
||||
|
||||
// pause execution for the calculated delay
|
||||
await new Promise((resolve) => {
|
||||
return setTimeout(resolve, retryAfterDelay);
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// if the status code is not retriable or max retries have been reached, do not retry
|
||||
return false;
|
||||
}
|
||||
}
|
||||
40
backend/node_modules/@azure/msal-node/src/retry/LinearRetryStrategy.ts
generated
vendored
Normal file
40
backend/node_modules/@azure/msal-node/src/retry/LinearRetryStrategy.ts
generated
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import { IncomingHttpHeaders } from "http";
|
||||
|
||||
export class LinearRetryStrategy {
|
||||
/**
|
||||
* Calculates the number of milliseconds to sleep based on the `retry-after` HTTP header.
|
||||
*
|
||||
* @param retryHeader - The value of the `retry-after` HTTP header. This can be either a number of seconds
|
||||
* or an HTTP date string.
|
||||
* @returns The number of milliseconds to sleep before retrying the request. If the `retry-after` header is not
|
||||
* present or cannot be parsed, returns 0.
|
||||
*/
|
||||
public calculateDelay(
|
||||
retryHeader: IncomingHttpHeaders["retry-after"],
|
||||
minimumDelay: number
|
||||
): number {
|
||||
if (!retryHeader) {
|
||||
return minimumDelay;
|
||||
}
|
||||
|
||||
// retry-after header is in seconds
|
||||
let millisToSleep = Math.round(parseFloat(retryHeader) * 1000);
|
||||
|
||||
/*
|
||||
* retry-after header is in HTTP Date format
|
||||
* <day-name>, <day> <month> <year> <hour>:<minute>:<second> GMT
|
||||
*/
|
||||
if (isNaN(millisToSleep)) {
|
||||
// .valueOf() is needed to subtract dates in TypeScript
|
||||
millisToSleep =
|
||||
new Date(retryHeader).valueOf() - new Date().valueOf();
|
||||
}
|
||||
|
||||
return Math.max(minimumDelay, millisToSleep);
|
||||
}
|
||||
}
|
||||
190
backend/node_modules/@azure/msal-node/src/utils/Constants.ts
generated
vendored
Normal file
190
backend/node_modules/@azure/msal-node/src/utils/Constants.ts
generated
vendored
Normal file
@ -0,0 +1,190 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import { AADServerParamKeys } from "@azure/msal-common/node";
|
||||
import { DefaultManagedIdentityRetryPolicy } from "../retry/DefaultManagedIdentityRetryPolicy.js";
|
||||
import { ImdsRetryPolicy } from "../retry/ImdsRetryPolicy.js";
|
||||
|
||||
// MSI Constants. Docs for MSI are available here https://docs.microsoft.com/azure/app-service/overview-managed-identity
|
||||
export const DEFAULT_MANAGED_IDENTITY_ID = "system_assigned_managed_identity";
|
||||
export const MANAGED_IDENTITY_DEFAULT_TENANT = "managed_identity";
|
||||
export const DEFAULT_AUTHORITY_FOR_MANAGED_IDENTITY = `https://login.microsoftonline.com/${MANAGED_IDENTITY_DEFAULT_TENANT}/`;
|
||||
|
||||
/**
|
||||
* Managed Identity Headers - used in network requests
|
||||
*/
|
||||
export const ManagedIdentityHeaders = {
|
||||
AUTHORIZATION_HEADER_NAME: "Authorization",
|
||||
METADATA_HEADER_NAME: "Metadata",
|
||||
APP_SERVICE_SECRET_HEADER_NAME: "X-IDENTITY-HEADER",
|
||||
ML_AND_SF_SECRET_HEADER_NAME: "secret",
|
||||
CLIENT_SKU: AADServerParamKeys.X_CLIENT_SKU,
|
||||
CLIENT_VER: AADServerParamKeys.X_CLIENT_VER,
|
||||
CLIENT_REQUEST_ID: "x-ms-client-request-id",
|
||||
} as const;
|
||||
export type ManagedIdentityHeaders =
|
||||
(typeof ManagedIdentityHeaders)[keyof typeof ManagedIdentityHeaders];
|
||||
|
||||
/**
|
||||
* Managed Identity Query Parameters - used in network requests
|
||||
*/
|
||||
export const ManagedIdentityQueryParameters = {
|
||||
API_VERSION: "api-version",
|
||||
RESOURCE: "resource",
|
||||
SHA256_TOKEN_TO_REFRESH: "token_sha256_to_refresh",
|
||||
XMS_CC: "xms_cc",
|
||||
} as const;
|
||||
export type ManagedIdentityQueryParameters =
|
||||
(typeof ManagedIdentityQueryParameters)[keyof typeof ManagedIdentityQueryParameters];
|
||||
|
||||
/**
|
||||
* Managed Identity Environment Variable Names
|
||||
*/
|
||||
export const ManagedIdentityEnvironmentVariableNames = {
|
||||
AZURE_POD_IDENTITY_AUTHORITY_HOST: "AZURE_POD_IDENTITY_AUTHORITY_HOST",
|
||||
DEFAULT_IDENTITY_CLIENT_ID: "DEFAULT_IDENTITY_CLIENT_ID",
|
||||
IDENTITY_ENDPOINT: "IDENTITY_ENDPOINT",
|
||||
IDENTITY_HEADER: "IDENTITY_HEADER",
|
||||
IDENTITY_SERVER_THUMBPRINT: "IDENTITY_SERVER_THUMBPRINT",
|
||||
IMDS_ENDPOINT: "IMDS_ENDPOINT",
|
||||
MSI_ENDPOINT: "MSI_ENDPOINT",
|
||||
MSI_SECRET: "MSI_SECRET",
|
||||
} as const;
|
||||
export type ManagedIdentityEnvironmentVariableNames =
|
||||
(typeof ManagedIdentityEnvironmentVariableNames)[keyof typeof ManagedIdentityEnvironmentVariableNames];
|
||||
|
||||
/**
|
||||
* Managed Identity Source Names
|
||||
* @public
|
||||
*/
|
||||
export const ManagedIdentitySourceNames = {
|
||||
APP_SERVICE: "AppService",
|
||||
AZURE_ARC: "AzureArc",
|
||||
CLOUD_SHELL: "CloudShell",
|
||||
DEFAULT_TO_IMDS: "DefaultToImds",
|
||||
IMDS: "Imds",
|
||||
MACHINE_LEARNING: "MachineLearning",
|
||||
SERVICE_FABRIC: "ServiceFabric",
|
||||
} as const;
|
||||
/**
|
||||
* The ManagedIdentitySourceNames type
|
||||
* @public
|
||||
*/
|
||||
export type ManagedIdentitySourceNames =
|
||||
(typeof ManagedIdentitySourceNames)[keyof typeof ManagedIdentitySourceNames];
|
||||
|
||||
/**
|
||||
* Managed Identity Ids
|
||||
*/
|
||||
export const ManagedIdentityIdType = {
|
||||
SYSTEM_ASSIGNED: "system-assigned",
|
||||
USER_ASSIGNED_CLIENT_ID: "user-assigned-client-id",
|
||||
USER_ASSIGNED_RESOURCE_ID: "user-assigned-resource-id",
|
||||
USER_ASSIGNED_OBJECT_ID: "user-assigned-object-id",
|
||||
} as const;
|
||||
export type ManagedIdentityIdType =
|
||||
(typeof ManagedIdentityIdType)[keyof typeof ManagedIdentityIdType];
|
||||
|
||||
/**
|
||||
* http methods
|
||||
*/
|
||||
export const HttpMethod = {
|
||||
GET: "GET",
|
||||
POST: "POST",
|
||||
} as const;
|
||||
export type HttpMethod = (typeof HttpMethod)[keyof typeof HttpMethod];
|
||||
|
||||
/**
|
||||
* Constants used for region discovery
|
||||
*/
|
||||
export const REGION_ENVIRONMENT_VARIABLE = "REGION_NAME";
|
||||
export const MSAL_FORCE_REGION = "MSAL_FORCE_REGION";
|
||||
|
||||
/**
|
||||
* Constant used for PKCE
|
||||
*/
|
||||
export const RANDOM_OCTET_SIZE = 32;
|
||||
|
||||
/**
|
||||
* Constants used in PKCE
|
||||
*/
|
||||
export const Hash = {
|
||||
SHA256: "sha256",
|
||||
};
|
||||
|
||||
/**
|
||||
* Constants for encoding schemes
|
||||
*/
|
||||
export const CharSet = {
|
||||
CV_CHARSET:
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~",
|
||||
};
|
||||
|
||||
/**
|
||||
* Cache Constants
|
||||
*/
|
||||
export const CACHE = {
|
||||
FILE_CACHE: "fileCache",
|
||||
EXTENSION_LIB: "extenstion_library",
|
||||
KEY_SEPARATOR: "-",
|
||||
};
|
||||
|
||||
/**
|
||||
* Constants
|
||||
*/
|
||||
export const Constants = {
|
||||
MSAL_SKU: "msal.js.node",
|
||||
JWT_BEARER_ASSERTION_TYPE:
|
||||
"urn:ietf:params:oauth:client-assertion-type:jwt-bearer",
|
||||
AUTHORIZATION_PENDING: "authorization_pending",
|
||||
HTTP_PROTOCOL: "http://",
|
||||
LOCALHOST: "localhost",
|
||||
};
|
||||
|
||||
/**
|
||||
* API Codes for Telemetry purposes.
|
||||
* Before adding a new code you must claim it in the MSAL Telemetry tracker as these number spaces are shared across all MSALs
|
||||
* 0-99 Silent Flow
|
||||
* 600-699 Device Code Flow
|
||||
* 800-899 Auth Code Flow
|
||||
*/
|
||||
export const ApiId = {
|
||||
acquireTokenSilent: 62,
|
||||
acquireTokenByUsernamePassword: 371,
|
||||
acquireTokenByDeviceCode: 671,
|
||||
acquireTokenByClientCredential: 771,
|
||||
acquireTokenByOBO: 772,
|
||||
acquireTokenWithManagedIdentity: 773,
|
||||
acquireTokenByCode: 871,
|
||||
acquireTokenByRefreshToken: 872,
|
||||
};
|
||||
export type ApiId = (typeof ApiId)[keyof typeof ApiId];
|
||||
|
||||
/**
|
||||
* JWT constants
|
||||
*/
|
||||
export const JwtConstants = {
|
||||
ALGORITHM: "alg",
|
||||
RSA_256: "RS256",
|
||||
PSS_256: "PS256",
|
||||
X5T_256: "x5t#S256",
|
||||
X5T: "x5t",
|
||||
X5C: "x5c",
|
||||
AUDIENCE: "aud",
|
||||
EXPIRATION_TIME: "exp",
|
||||
ISSUER: "iss",
|
||||
SUBJECT: "sub",
|
||||
NOT_BEFORE: "nbf",
|
||||
JWT_ID: "jti",
|
||||
};
|
||||
|
||||
export const LOOPBACK_SERVER_CONSTANTS = {
|
||||
INTERVAL_MS: 100,
|
||||
TIMEOUT_MS: 5000,
|
||||
};
|
||||
|
||||
export const AZURE_ARC_SECRET_FILE_MAX_SIZE_BYTES: number = 4096; // 4 KB
|
||||
|
||||
export type RetryPolicies = DefaultManagedIdentityRetryPolicy | ImdsRetryPolicy;
|
||||
54
backend/node_modules/@azure/msal-node/src/utils/EncodingUtils.ts
generated
vendored
Normal file
54
backend/node_modules/@azure/msal-node/src/utils/EncodingUtils.ts
generated
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import { Constants } from "@azure/msal-common/node";
|
||||
|
||||
export class EncodingUtils {
|
||||
/**
|
||||
* 'utf8': Multibyte encoded Unicode characters. Many web pages and other document formats use UTF-8.
|
||||
* 'base64': Base64 encoding.
|
||||
*
|
||||
* @param str text
|
||||
*/
|
||||
static base64Encode(str: string, encoding?: BufferEncoding): string {
|
||||
return Buffer.from(str, encoding).toString(
|
||||
Constants.EncodingTypes.BASE64
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* encode a URL
|
||||
* @param str
|
||||
*/
|
||||
static base64EncodeUrl(str: string, encoding?: BufferEncoding): string {
|
||||
return EncodingUtils.base64Encode(str, encoding)
|
||||
.replace(/=/g, "")
|
||||
.replace(/\+/g, "-")
|
||||
.replace(/\//g, "_");
|
||||
}
|
||||
|
||||
/**
|
||||
* 'utf8': Multibyte encoded Unicode characters. Many web pages and other document formats use UTF-8.
|
||||
* 'base64': Base64 encoding.
|
||||
*
|
||||
* @param base64Str Base64 encoded text
|
||||
*/
|
||||
static base64Decode(base64Str: string): string {
|
||||
return Buffer.from(base64Str, Constants.EncodingTypes.BASE64).toString(
|
||||
"utf8"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param base64Str Base64 encoded Url
|
||||
*/
|
||||
static base64DecodeUrl(base64Str: string): string {
|
||||
let str = base64Str.replace(/-/g, "+").replace(/_/g, "/");
|
||||
while (str.length % 4) {
|
||||
str += "=";
|
||||
}
|
||||
return EncodingUtils.base64Decode(str);
|
||||
}
|
||||
}
|
||||
61
backend/node_modules/@azure/msal-node/src/utils/NetworkUtils.ts
generated
vendored
Normal file
61
backend/node_modules/@azure/msal-node/src/utils/NetworkUtils.ts
generated
vendored
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import { NetworkResponse } from "@azure/msal-common/node";
|
||||
|
||||
export type UrlToHttpRequestOptions = {
|
||||
protocol: string;
|
||||
hostname: string;
|
||||
hash: string;
|
||||
search: string;
|
||||
pathname: string;
|
||||
path: string;
|
||||
href: string;
|
||||
port?: number;
|
||||
auth?: string;
|
||||
};
|
||||
|
||||
export class NetworkUtils {
|
||||
static getNetworkResponse<T>(
|
||||
headers: Record<string, string>,
|
||||
body: T,
|
||||
statusCode: number
|
||||
): NetworkResponse<T> {
|
||||
return {
|
||||
headers: headers,
|
||||
body: body,
|
||||
status: statusCode,
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
* Utility function that converts a URL object into an ordinary options object as expected by the
|
||||
* http.request and https.request APIs.
|
||||
* https://github.com/nodejs/node/blob/main/lib/internal/url.js#L1090
|
||||
*/
|
||||
static urlToHttpOptions(url: URL): UrlToHttpRequestOptions {
|
||||
const options: UrlToHttpRequestOptions = {
|
||||
protocol: url.protocol,
|
||||
hostname:
|
||||
url.hostname && url.hostname.startsWith("[")
|
||||
? url.hostname.slice(1, -1)
|
||||
: url.hostname,
|
||||
hash: url.hash,
|
||||
search: url.search,
|
||||
pathname: url.pathname,
|
||||
path: `${url.pathname || ""}${url.search || ""}`,
|
||||
href: url.href,
|
||||
};
|
||||
if (url.port !== "") {
|
||||
options.port = Number(url.port);
|
||||
}
|
||||
if (url.username || url.password) {
|
||||
options.auth = `${decodeURIComponent(
|
||||
url.username
|
||||
)}:${decodeURIComponent(url.password)}`;
|
||||
}
|
||||
return options;
|
||||
}
|
||||
}
|
||||
20
backend/node_modules/@azure/msal-node/src/utils/TimeUtils.ts
generated
vendored
Normal file
20
backend/node_modules/@azure/msal-node/src/utils/TimeUtils.ts
generated
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* Checks if a given date string is in ISO 8601 format.
|
||||
*
|
||||
* @param dateString - The date string to be checked.
|
||||
* @returns boolean - Returns true if the date string is in ISO 8601 format, otherwise false.
|
||||
*/
|
||||
export function isIso8601(dateString: number | string): boolean {
|
||||
if (typeof dateString !== "string") {
|
||||
return false;
|
||||
}
|
||||
|
||||
const date = new Date(dateString);
|
||||
return !isNaN(date.getTime()) && date.toISOString() === dateString;
|
||||
}
|
||||
Reference in New Issue
Block a user