Commit iniziale

This commit is contained in:
Paolo A
2025-02-18 22:59:07 +00:00
commit 4bbf35cefb
6879 changed files with 623784 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
export type AccountInfo = {
homeAccountId?: string;
environment: string;
tenantId?: string;
username: string;
localAccountId?: string;
name?: string;
idToken?: string;
platformBrokerId?: string;
idTokenClaims?: object;
};
//# sourceMappingURL=AccountInfo.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"AccountInfo.d.ts","sourceRoot":"","sources":["../../src/naa/AccountInfo.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,WAAW,GAAG;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,aAAa,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC"}

View File

@@ -0,0 +1,9 @@
export type AuthBridgeResponse = string | {
data: string;
};
export interface AuthBridge {
addEventListener: (eventName: string, callback: (response: AuthBridgeResponse) => void) => void;
postMessage: (message: string) => void;
removeEventListener: (eventName: string, callback: (response: AuthBridgeResponse) => void) => void;
}
//# sourceMappingURL=AuthBridge.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"AuthBridge.d.ts","sourceRoot":"","sources":["../../src/naa/AuthBridge.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAC3D,MAAM,WAAW,UAAU;IACvB,gBAAgB,EAAE,CACd,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,CAAC,QAAQ,EAAE,kBAAkB,KAAK,IAAI,KAC/C,IAAI,CAAC;IACV,WAAW,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,mBAAmB,EAAE,CACjB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,CAAC,QAAQ,EAAE,kBAAkB,KAAK,IAAI,KAC/C,IAAI,CAAC;CACb"}

View File

@@ -0,0 +1,7 @@
import { AccountInfo } from "./AccountInfo.js";
import { TokenResponse } from "./TokenResponse.js";
export type AuthResult = {
token: TokenResponse;
account: AccountInfo;
};
//# sourceMappingURL=AuthResult.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"AuthResult.d.ts","sourceRoot":"","sources":["../../src/naa/AuthResult.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,MAAM,MAAM,UAAU,GAAG;IACrB,KAAK,EAAE,aAAa,CAAC;IACrB,OAAO,EAAE,WAAW,CAAC;CACxB,CAAC"}

View File

@@ -0,0 +1,13 @@
/**
* AccountContext is used to pass account information when the bridge is initialized
*
* NAA (MetaOS) apps are created and destroyed for the same session multiple times.
* `AccountContext` helps in booting up the cached account when the bridge
* is recreated for a new NAA instance in the same auth session.
*/
export interface AccountContext {
homeAccountId: string;
environment: string;
tenantId: string;
}
//# sourceMappingURL=BridgeAccountContext.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"BridgeAccountContext.d.ts","sourceRoot":"","sources":["../../src/naa/BridgeAccountContext.ts"],"names":[],"mappings":"AAKA;;;;;;GAMG;AACH,MAAM,WAAW,cAAc;IAC3B,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;CACpB"}

View File

@@ -0,0 +1,4 @@
export interface BridgeCapabilities {
queryAccount?: boolean;
}
//# sourceMappingURL=BridgeCapabilities.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"BridgeCapabilities.d.ts","sourceRoot":"","sources":["../../src/naa/BridgeCapabilities.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,kBAAkB;IAC/B,YAAY,CAAC,EAAE,OAAO,CAAC;CAC1B"}

View File

@@ -0,0 +1,10 @@
import { BridgeStatusCode } from "./BridgeStatusCode.js";
export type BridgeError = {
status: BridgeStatusCode;
code?: string;
subError?: string;
description?: string;
properties?: object;
};
export declare function isBridgeError(error: unknown): error is BridgeError;
//# sourceMappingURL=BridgeError.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"BridgeError.d.ts","sourceRoot":"","sources":["../../src/naa/BridgeError.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,MAAM,MAAM,WAAW,GAAG;IACtB,MAAM,EAAE,gBAAgB,CAAC;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,WAAW,CAElE"}

View File

@@ -0,0 +1,12 @@
/*! @azure/msal-browser v4.2.1 2025-02-11 */
'use strict';
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
function isBridgeError(error) {
return error.status !== undefined;
}
export { isBridgeError };
//# sourceMappingURL=BridgeError.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"BridgeError.mjs","sources":["../../src/naa/BridgeError.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAAA;;;AAGG;AAYG,SAAU,aAAa,CAAC,KAAc,EAAA;AACxC,IAAA,OAAQ,KAAqB,CAAC,MAAM,KAAK,SAAS,CAAC;AACvD;;;;"}

View File

@@ -0,0 +1,69 @@
import { AuthBridge } from "./AuthBridge.js";
import { AuthResult } from "./AuthResult.js";
import { BridgeCapabilities } from "./BridgeCapabilities.js";
import { AccountContext } from "./BridgeAccountContext.js";
import { BridgeRequest } from "./BridgeRequest.js";
import { IBridgeProxy } from "./IBridgeProxy.js";
import { InitContext } from "./InitContext.js";
import { TokenRequest } from "./TokenRequest.js";
declare global {
interface Window {
nestedAppAuthBridge: AuthBridge;
}
}
/**
* BridgeProxy
* Provides a proxy for accessing a bridge to a host app and/or
* platform broker
*/
export declare class BridgeProxy implements IBridgeProxy {
static bridgeRequests: BridgeRequest[];
sdkName: string;
sdkVersion: string;
capabilities?: BridgeCapabilities;
accountContext?: AccountContext;
/**
* initializeNestedAppAuthBridge - Initializes the bridge to the host app
* @returns a promise that resolves to an InitializeBridgeResponse or rejects with an Error
* @remarks This method will be called by the create factory method
* @remarks If the bridge is not available, this method will throw an error
*/
protected static initializeNestedAppAuthBridge(): Promise<InitContext>;
/**
* getTokenInteractive - Attempts to get a token interactively from the bridge
* @param request A token request
* @returns a promise that resolves to an auth result or rejects with a BridgeError
*/
getTokenInteractive(request: TokenRequest): Promise<AuthResult>;
/**
* getTokenSilent Attempts to get a token silently from the bridge
* @param request A token request
* @returns a promise that resolves to an auth result or rejects with a BridgeError
*/
getTokenSilent(request: TokenRequest): Promise<AuthResult>;
private getToken;
getHostCapabilities(): BridgeCapabilities | null;
getAccountContext(): AccountContext | null;
private static buildRequest;
/**
* A method used to send a request to the bridge
* @param request A token request
* @returns a promise that resolves to a response of provided type or rejects with a BridgeError
*/
private sendRequest;
private static validateBridgeResultOrThrow;
/**
* Private constructor for BridgeProxy
* @param sdkName The name of the SDK being used to make requests on behalf of the app
* @param sdkVersion The version of the SDK being used to make requests on behalf of the app
* @param capabilities The capabilities of the bridge / SDK / platform broker
*/
private constructor();
/**
* Factory method for creating an implementation of IBridgeProxy
* @returns A promise that resolves to a BridgeProxy implementation
*/
static create(): Promise<IBridgeProxy>;
}
export default BridgeProxy;
//# sourceMappingURL=BridgeProxy.d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CAAC,WAAW;IAsBnB,OAAO,CAAC,MAAM,CAAC,2BAA2B;IAU1C;;;;;OAKG;IACH,OAAO;IAYP;;;OAGG;WACiB,MAAM,IAAI,OAAO,CAAC,YAAY,CAAC;CAStD;AAED,eAAe,WAAW,CAAC"}

View File

@@ -0,0 +1,158 @@
/*! @azure/msal-browser v4.2.1 2025-02-11 */
'use strict';
import { BridgeStatusCode } from './BridgeStatusCode.mjs';
import { createNewGuid } from '../crypto/BrowserCrypto.mjs';
import { BrowserConstants } from '../utils/BrowserConstants.mjs';
import { version } from '../packageMetadata.mjs';
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
/**
* BridgeProxy
* Provides a proxy for accessing a bridge to a host app and/or
* platform broker
*/
class BridgeProxy {
/**
* initializeNestedAppAuthBridge - Initializes the bridge to the host app
* @returns a promise that resolves to an InitializeBridgeResponse or rejects with an Error
* @remarks This method will be called by the create factory method
* @remarks If the bridge is not available, this method will throw an error
*/
static async initializeNestedAppAuthBridge() {
if (window === undefined) {
throw new Error("window is undefined");
}
if (window.nestedAppAuthBridge === undefined) {
throw new Error("window.nestedAppAuthBridge is undefined");
}
try {
window.nestedAppAuthBridge.addEventListener("message", (response) => {
const responsePayload = typeof response === "string" ? response : response.data;
const responseEnvelope = JSON.parse(responsePayload);
const request = BridgeProxy.bridgeRequests.find((element) => element.requestId === responseEnvelope.requestId);
if (request !== undefined) {
BridgeProxy.bridgeRequests.splice(BridgeProxy.bridgeRequests.indexOf(request), 1);
if (responseEnvelope.success) {
request.resolve(responseEnvelope);
}
else {
request.reject(responseEnvelope.error);
}
}
});
const bridgeResponse = await new Promise((resolve, reject) => {
const message = BridgeProxy.buildRequest("GetInitContext");
const request = {
requestId: message.requestId,
method: message.method,
resolve: resolve,
reject: reject,
};
BridgeProxy.bridgeRequests.push(request);
window.nestedAppAuthBridge.postMessage(JSON.stringify(message));
});
return BridgeProxy.validateBridgeResultOrThrow(bridgeResponse.initContext);
}
catch (error) {
window.console.log(error);
throw error;
}
}
/**
* getTokenInteractive - Attempts to get a token interactively from the bridge
* @param request A token request
* @returns a promise that resolves to an auth result or rejects with a BridgeError
*/
getTokenInteractive(request) {
return this.getToken("GetTokenPopup", request);
}
/**
* getTokenSilent Attempts to get a token silently from the bridge
* @param request A token request
* @returns a promise that resolves to an auth result or rejects with a BridgeError
*/
getTokenSilent(request) {
return this.getToken("GetToken", request);
}
async getToken(requestType, request) {
const result = await this.sendRequest(requestType, {
tokenParams: request,
});
return {
token: BridgeProxy.validateBridgeResultOrThrow(result.token),
account: BridgeProxy.validateBridgeResultOrThrow(result.account),
};
}
getHostCapabilities() {
return this.capabilities ?? null;
}
getAccountContext() {
return this.accountContext ? this.accountContext : null;
}
static buildRequest(method, requestParams) {
return {
messageType: "NestedAppAuthRequest",
method: method,
requestId: createNewGuid(),
sendTime: Date.now(),
clientLibrary: BrowserConstants.MSAL_SKU,
clientLibraryVersion: version,
...requestParams,
};
}
/**
* A method used to send a request to the bridge
* @param request A token request
* @returns a promise that resolves to a response of provided type or rejects with a BridgeError
*/
sendRequest(method, requestParams) {
const message = BridgeProxy.buildRequest(method, requestParams);
const promise = new Promise((resolve, reject) => {
const request = {
requestId: message.requestId,
method: message.method,
resolve: resolve,
reject: reject,
};
BridgeProxy.bridgeRequests.push(request);
window.nestedAppAuthBridge.postMessage(JSON.stringify(message));
});
return promise;
}
static validateBridgeResultOrThrow(input) {
if (input === undefined) {
const bridgeError = {
status: BridgeStatusCode.NestedAppAuthUnavailable,
};
throw bridgeError;
}
return input;
}
/**
* Private constructor for BridgeProxy
* @param sdkName The name of the SDK being used to make requests on behalf of the app
* @param sdkVersion The version of the SDK being used to make requests on behalf of the app
* @param capabilities The capabilities of the bridge / SDK / platform broker
*/
constructor(sdkName, sdkVersion, accountContext, capabilities) {
this.sdkName = sdkName;
this.sdkVersion = sdkVersion;
this.accountContext = accountContext;
this.capabilities = capabilities;
}
/**
* Factory method for creating an implementation of IBridgeProxy
* @returns A promise that resolves to a BridgeProxy implementation
*/
static async create() {
const response = await BridgeProxy.initializeNestedAppAuthBridge();
return new BridgeProxy(response.sdkName, response.sdkVersion, response.accountContext, response.capabilities);
}
}
BridgeProxy.bridgeRequests = [];
export { BridgeProxy, BridgeProxy as default };
//# sourceMappingURL=BridgeProxy.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"BridgeProxy.mjs","sources":["../../src/naa/BridgeProxy.ts"],"sourcesContent":[null],"names":["BrowserCrypto.createNewGuid"],"mappings":";;;;;;;AAAA;;;AAGG;AA2BH;;;;AAIG;MACU,WAAW,CAAA;AAOpB;;;;;AAKG;IACO,aAAa,6BAA6B,GAAA;QAChD,IAAI,MAAM,KAAK,SAAS,EAAE;AACtB,YAAA,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;AAC1C,SAAA;AACD,QAAA,IAAI,MAAM,CAAC,mBAAmB,KAAK,SAAS,EAAE;AAC1C,YAAA,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;AAC9D,SAAA;QAED,IAAI;YACA,MAAM,CAAC,mBAAmB,CAAC,gBAAgB,CACvC,SAAS,EACT,CAAC,QAA4B,KAAI;AAC7B,gBAAA,MAAM,eAAe,GACjB,OAAO,QAAQ,KAAK,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC,IAAI,CAAC;gBAC5D,MAAM,gBAAgB,GAClB,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;gBAChC,MAAM,OAAO,GAAG,WAAW,CAAC,cAAc,CAAC,IAAI,CAC3C,CAAC,OAAO,KACJ,OAAO,CAAC,SAAS,KAAK,gBAAgB,CAAC,SAAS,CACvD,CAAC;gBACF,IAAI,OAAO,KAAK,SAAS,EAAE;AACvB,oBAAA,WAAW,CAAC,cAAc,CAAC,MAAM,CAC7B,WAAW,CAAC,cAAc,CAAC,OAAO,CAAC,OAAO,CAAC,EAC3C,CAAC,CACJ,CAAC;oBACF,IAAI,gBAAgB,CAAC,OA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jB,CAAC;AACF,YAAA,WAAW,CAAC,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AACzC,YAAA,MAAM,CAAC,mBAAmB,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;AACpE,SAAC,CACJ,CAAC;AAEF,QAAA,OAAO,OAAO,CAAC;KAClB;IAEO,OAAO,2BAA2B,CAAI,KAAoB,EAAA;QAC9D,IAAI,KAAK,KAAK,SAAS,EAAE;AACrB,YAAA,MAAM,WAAW,GAAgB;gBAC7B,MAAM,EAAE,gBAAgB,CAAC,wBAAwB;aACpD,CAAC;AACF,YAAA,MAAM,WAAW,CAAC;AACrB,SAAA;AACD,QAAA,OAAO,KAAK,CAAC;KAChB;AAED;;;;;AAKG;AACH,IAAA,WAAA,CACI,OAAe,EACf,UAAkB,EAClB,cAA+B,EAC/B,YAAiC,EAAA;AAEjC,QAAA,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;AACvB,QAAA,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;AAC7B,QAAA,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;AACrC,QAAA,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;KACpC;AAED;;;AAGG;IACI,aAAa,MAAM,GAAA;AACtB,QAAA,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,6BAA6B,EAAE,CAAC;AACnE,QAAA,OAAO,IAAI,WAAW,CAClB,QAAQ,CAAC,OAAO,EAChB,QAAQ,CAAC,UAAU,EACnB,QAAQ,CAAC,cAAc,EACvB,QAAQ,CAAC,YAAY,CACxB,CAAC;KACL;;AAjMM,WAAc,CAAA,cAAA,GAAoB,EAAE;;;;"}

View File

@@ -0,0 +1,8 @@
import { BridgeResponseEnvelope } from "./BridgeResponseEnvelope.js";
export type BridgeRequest = {
requestId: string;
method: string;
resolve: (value: BridgeResponseEnvelope | PromiseLike<BridgeResponseEnvelope>) => void;
reject: (reason?: any) => void;
};
//# sourceMappingURL=BridgeRequest.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"BridgeRequest.d.ts","sourceRoot":"","sources":["../../src/naa/BridgeRequest.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAErE,MAAM,MAAM,aAAa,GAAG;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,CACL,KAAK,EAAE,sBAAsB,GAAG,WAAW,CAAC,sBAAsB,CAAC,KAClE,IAAI,CAAC;IAEV,MAAM,EAAE,CAAC,MAAM,CAAC,EAAE,GAAG,KAAK,IAAI,CAAC;CAClC,CAAC"}

View File

@@ -0,0 +1,13 @@
import { TokenRequest } from "./TokenRequest.js";
export type BridgeMethods = "GetToken" | "GetInitContext" | "GetTokenPopup";
export type BridgeRequestEnvelope = {
messageType: "NestedAppAuthRequest";
method: BridgeMethods;
sendTime?: number;
clientLibrary?: string;
clientLibraryVersion?: string;
requestId: string;
tokenParams?: TokenRequest;
};
export declare function isBridgeRequestEnvelope(obj: unknown): obj is BridgeRequestEnvelope;
//# sourceMappingURL=BridgeRequestEnvelope.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"BridgeRequestEnvelope.d.ts","sourceRoot":"","sources":["../../src/naa/BridgeRequestEnvelope.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,MAAM,MAAM,aAAa,GAAG,UAAU,GAAG,gBAAgB,GAAG,eAAe,CAAC;AAE5E,MAAM,MAAM,qBAAqB,GAAG;IAChC,WAAW,EAAE,sBAAsB,CAAC;IACpC,MAAM,EAAE,aAAa,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,YAAY,CAAC;CAC9B,CAAC;AAEF,wBAAgB,uBAAuB,CACnC,GAAG,EAAE,OAAO,GACb,GAAG,IAAI,qBAAqB,CAO9B"}

View File

@@ -0,0 +1,14 @@
import { BridgeError } from "./BridgeError.js";
import { TokenResponse } from "./TokenResponse.js";
import { AccountInfo } from "./AccountInfo.js";
import { InitContext } from "./InitContext.js";
export type BridgeResponseEnvelope = {
messageType: "NestedAppAuthResponse";
requestId: string;
success: boolean;
token?: TokenResponse;
error?: BridgeError;
account?: AccountInfo;
initContext?: InitContext;
};
//# sourceMappingURL=BridgeResponseEnvelope.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"BridgeResponseEnvelope.d.ts","sourceRoot":"","sources":["../../src/naa/BridgeResponseEnvelope.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,MAAM,MAAM,sBAAsB,GAAG;IACjC,WAAW,EAAE,uBAAuB,CAAC;IACrC,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,WAAW,CAAC,EAAE,WAAW,CAAC;CAC7B,CAAC"}

View File

@@ -0,0 +1,12 @@
export declare const BridgeStatusCode: {
readonly UserInteractionRequired: "USER_INTERACTION_REQUIRED";
readonly UserCancel: "USER_CANCEL";
readonly NoNetwork: "NO_NETWORK";
readonly TransientError: "TRANSIENT_ERROR";
readonly PersistentError: "PERSISTENT_ERROR";
readonly Disabled: "DISABLED";
readonly AccountUnavailable: "ACCOUNT_UNAVAILABLE";
readonly NestedAppAuthUnavailable: "NESTED_APP_AUTH_UNAVAILABLE";
};
export type BridgeStatusCode = (typeof BridgeStatusCode)[keyof typeof BridgeStatusCode];
//# sourceMappingURL=BridgeStatusCode.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"BridgeStatusCode.d.ts","sourceRoot":"","sources":["../../src/naa/BridgeStatusCode.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,gBAAgB;;;;;;;;;CASnB,CAAC;AACX,MAAM,MAAM,gBAAgB,GACxB,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,OAAO,gBAAgB,CAAC,CAAC"}

View File

@@ -0,0 +1,19 @@
/*! @azure/msal-browser v4.2.1 2025-02-11 */
'use strict';
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
const BridgeStatusCode = {
UserInteractionRequired: "USER_INTERACTION_REQUIRED",
UserCancel: "USER_CANCEL",
NoNetwork: "NO_NETWORK",
TransientError: "TRANSIENT_ERROR",
PersistentError: "PERSISTENT_ERROR",
Disabled: "DISABLED",
AccountUnavailable: "ACCOUNT_UNAVAILABLE",
NestedAppAuthUnavailable: "NESTED_APP_AUTH_UNAVAILABLE", // NAA is unavailable in the current context, can retry with standard browser based auth
};
export { BridgeStatusCode };
//# sourceMappingURL=BridgeStatusCode.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"BridgeStatusCode.mjs","sources":["../../src/naa/BridgeStatusCode.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAAA;;;AAGG;AAEU,MAAA,gBAAgB,GAAG;AAC5B,IAAA,uBAAuB,EAAE,2BAA2B;AACpD,IAAA,UAAU,EAAE,aAAa;AACzB,IAAA,SAAS,EAAE,YAAY;AACvB,IAAA,cAAc,EAAE,iBAAiB;AACjC,IAAA,eAAe,EAAE,kBAAkB;AACnC,IAAA,QAAQ,EAAE,UAAU;AACpB,IAAA,kBAAkB,EAAE,qBAAqB;IACzC,wBAAwB,EAAE,6BAA6B;;;;;"}

View File

@@ -0,0 +1,11 @@
import { AuthResult } from "./AuthResult.js";
import { AccountContext } from "./BridgeAccountContext.js";
import { BridgeCapabilities } from "./BridgeCapabilities.js";
import { TokenRequest } from "./TokenRequest.js";
export interface IBridgeProxy {
getTokenInteractive(request: TokenRequest): Promise<AuthResult>;
getTokenSilent(request: TokenRequest): Promise<AuthResult>;
getHostCapabilities(): BridgeCapabilities | null;
getAccountContext(): AccountContext | null;
}
//# sourceMappingURL=IBridgeProxy.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"IBridgeProxy.d.ts","sourceRoot":"","sources":["../../src/naa/IBridgeProxy.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,MAAM,WAAW,YAAY;IACzB,mBAAmB,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IAChE,cAAc,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IAC3D,mBAAmB,IAAI,kBAAkB,GAAG,IAAI,CAAC;IACjD,iBAAiB,IAAI,cAAc,GAAG,IAAI,CAAC;CAC9C"}

View File

@@ -0,0 +1,9 @@
import { BridgeCapabilities } from "./BridgeCapabilities.js";
import { AccountContext } from "./BridgeAccountContext.js";
export interface InitContext {
capabilities?: BridgeCapabilities;
sdkName: string;
sdkVersion: string;
accountContext?: AccountContext;
}
//# sourceMappingURL=InitContext.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"InitContext.d.ts","sourceRoot":"","sources":["../../src/naa/InitContext.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAE3D,MAAM,WAAW,WAAW;IACxB,YAAY,CAAC,EAAE,kBAAkB,CAAC;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,cAAc,CAAC;CACnC"}

View File

@@ -0,0 +1,19 @@
export type TokenRequest = {
platformBrokerId?: string;
clientId: string;
authority?: string;
scope: string;
correlationId: string;
claims?: string;
state?: string;
reqCnf?: string;
keyId?: string;
authenticationScheme?: string;
shrClaims?: string;
shrNonce?: string;
resourceRequestMethod?: string;
resourceRequestUri?: string;
extendedExpiryToken?: boolean;
extraParameters?: Map<string, string>;
};
//# sourceMappingURL=TokenRequest.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"TokenRequest.d.ts","sourceRoot":"","sources":["../../src/naa/TokenRequest.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,YAAY,GAAG;IACvB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,eAAe,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACzC,CAAC"}

View File

@@ -0,0 +1,14 @@
export type TokenResponse = {
access_token: string;
expires_in: number;
id_token: string;
properties: TokenResponseProperties | null;
scope?: string;
shr?: string;
extendedLifetimeToken?: boolean;
authority?: string;
};
export type TokenResponseProperties = {
MATS?: string;
};
//# sourceMappingURL=TokenResponse.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"TokenResponse.d.ts","sourceRoot":"","sources":["../../src/naa/TokenResponse.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,aAAa,GAAG;IACxB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,uBAAuB,GAAG,IAAI,CAAC;IAC3C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IAClC,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC"}

View File

@@ -0,0 +1,36 @@
import { TokenRequest } from "../TokenRequest.js";
import { AccountInfo as NaaAccountInfo } from "../AccountInfo.js";
import { RedirectRequest } from "../../request/RedirectRequest.js";
import { PopupRequest } from "../../request/PopupRequest.js";
import { AccountInfo as MsalAccountInfo, AuthError, ClientAuthError, ClientConfigurationError, InteractionRequiredAuthError, ServerError, ICrypto, Logger, TokenClaims, AccountInfo, IdTokenEntity, AccessTokenEntity } from "@azure/msal-common/browser";
import { AuthenticationResult } from "../../response/AuthenticationResult.js";
import { AuthResult } from "../AuthResult.js";
import { SsoSilentRequest } from "../../request/SsoSilentRequest.js";
import { SilentRequest } from "../../request/SilentRequest.js";
export declare class NestedAppAuthAdapter {
protected crypto: ICrypto;
protected logger: Logger;
protected clientId: string;
protected clientCapabilities: string[];
constructor(clientId: string, clientCapabilities: string[], crypto: ICrypto, logger: Logger);
toNaaTokenRequest(request: PopupRequest | RedirectRequest | SilentRequest | SsoSilentRequest): TokenRequest;
fromNaaTokenResponse(request: TokenRequest, response: AuthResult, reqTimestamp: number): AuthenticationResult;
fromNaaAccountInfo(fromAccount: NaaAccountInfo, idToken?: string, idTokenClaims?: TokenClaims): MsalAccountInfo;
/**
*
* @param error BridgeError
* @returns AuthError, ClientAuthError, ClientConfigurationError, ServerError, InteractionRequiredError
*/
fromBridgeError(error: unknown): AuthError | ClientAuthError | ClientConfigurationError | ServerError | InteractionRequiredAuthError;
/**
* Returns an AuthenticationResult from the given cache items
*
* @param account
* @param idToken
* @param accessToken
* @param reqTimestamp
* @returns
*/
toAuthenticationResultFromCache(account: AccountInfo, idToken: IdTokenEntity, accessToken: AccessTokenEntity, request: SilentRequest, correlationId: string): AuthenticationResult;
}
//# sourceMappingURL=NestedAppAuthAdapter.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"NestedAppAuthAdapter.d.ts","sourceRoot":"","sources":["../../../src/naa/mapping/NestedAppAuthAdapter.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,WAAW,IAAI,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,EACH,WAAW,IAAI,eAAe,EAC9B,SAAS,EACT,eAAe,EACf,wBAAwB,EACxB,4BAA4B,EAC5B,WAAW,EACX,OAAO,EACP,MAAM,EAEN,WAAW,EAOX,WAAW,EACX,aAAa,EACb,iBAAiB,EAGpB,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EAAE,oBAAoB,EAAE,MAAM,wCAAwC,CAAC;AAE9E,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAE/D,qBAAa,oBAAoB;IAC7B,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC;IAC1B,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC3B,SAAS,CAAC,kBAAkB,EAAE,MAAM,EAAE,CAAC;gBAGnC,QAAQ,EAAE,MAAM,EAChB,kBAAkB,EAAE,MAAM,EAAE,EAC5B,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,MAAM;IAQX,iBAAiB,CACpB,OAAO,EACD,YAAY,GACZ,eAAe,GACf,aAAa,GACb,gBAAgB,GACvB,YAAY;IAkCR,oBAAoB,CACvB,OAAO,EAAE,YAAY,EACrB,QAAQ,EAAE,UAAU,EACpB,YAAY,EAAE,MAAM,GACrB,oBAAoB;IA8DhB,kBAAkB,CACrB,WAAW,EAAE,cAAc,EAC3B,OAAO,CAAC,EAAE,MAAM,EAChB,aAAa,CAAC,EAAE,WAAW,GAC5B,eAAe;IAgDlB;;;;OAIG;IACI,eAAe,CAClB,KAAK,EAAE,OAAO,GAEZ,SAAS,GACT,eAAe,GACf,wBAAwB,GACxB,WAAW,GACX,4BAA4B;IAyClC;;;;;;;;OAQG;IACI,+BAA+B,CAClC,OAAO,EAAE,WAAW,EACpB,OAAO,EAAE,aAAa,EACtB,WAAW,EAAE,iBAAiB,EAC9B,OAAO,EAAE,aAAa,EACtB,aAAa,EAAE,MAAM,GACtB,oBAAoB;CAkC1B"}

View File

@@ -0,0 +1,187 @@
/*! @azure/msal-browser v4.2.1 2025-02-11 */
'use strict';
import { RequestParameterBuilder, StringUtils, AuthenticationScheme, createClientAuthError, ClientAuthErrorCodes, AuthToken, buildTenantProfile, AuthError, InteractionRequiredAuthError, ServerError, ClientAuthError, OIDC_DEFAULT_SCOPES } from '@azure/msal-common/browser';
import { isBridgeError } from '../BridgeError.mjs';
import { BridgeStatusCode } from '../BridgeStatusCode.mjs';
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
class NestedAppAuthAdapter {
constructor(clientId, clientCapabilities, crypto, logger) {
this.clientId = clientId;
this.clientCapabilities = clientCapabilities;
this.crypto = crypto;
this.logger = logger;
}
toNaaTokenRequest(request) {
let extraParams;
if (request.extraQueryParameters === undefined) {
extraParams = new Map();
}
else {
extraParams = new Map(Object.entries(request.extraQueryParameters));
}
const correlationId = request.correlationId || this.crypto.createNewGuid();
const requestBuilder = new RequestParameterBuilder(correlationId);
const claims = requestBuilder.addClientCapabilitiesToClaims(request.claims, this.clientCapabilities);
const scopes = request.scopes || OIDC_DEFAULT_SCOPES;
const tokenRequest = {
platformBrokerId: request.account?.homeAccountId,
clientId: this.clientId,
authority: request.authority,
scope: scopes.join(" "),
correlationId,
claims: !StringUtils.isEmptyObj(claims) ? claims : undefined,
state: request.state,
authenticationScheme: request.authenticationScheme || AuthenticationScheme.BEARER,
extraParameters: extraParams,
};
return tokenRequest;
}
fromNaaTokenResponse(request, response, reqTimestamp) {
if (!response.token.id_token || !response.token.access_token) {
throw createClientAuthError(ClientAuthErrorCodes.nullOrEmptyToken);
}
const expiresOn = new Date((reqTimestamp + (response.token.expires_in || 0)) * 1000);
const idTokenClaims = AuthToken.extractTokenClaims(response.token.id_token, this.crypto.base64Decode);
const account = this.fromNaaAccountInfo(response.account, response.token.id_token, idTokenClaims);
const scopes = response.token.scope || request.scope;
const authenticationResult = {
authority: response.token.authority || account.environment,
uniqueId: account.localAccountId,
tenantId: account.tenantId,
scopes: scopes.split(" "),
account,
idToken: response.token.id_token,
idTokenClaims,
accessToken: response.token.access_token,
fromCache: false,
expiresOn: expiresOn,
tokenType: request.authenticationScheme || AuthenticationScheme.BEARER,
correlationId: request.correlationId,
extExpiresOn: expiresOn,
state: request.state,
};
return authenticationResult;
}
/*
* export type AccountInfo = {
* homeAccountId: string;
* environment: string;
* tenantId: string;
* username: string;
* localAccountId: string;
* name?: string;
* idToken?: string;
* idTokenClaims?: TokenClaims & {
* [key: string]:
* | string
* | number
* | string[]
* | object
* | undefined
* | unknown;
* };
* nativeAccountId?: string;
* authorityType?: string;
* };
*/
fromNaaAccountInfo(fromAccount, idToken, idTokenClaims) {
const effectiveIdTokenClaims = idTokenClaims || fromAccount.idTokenClaims;
const localAccountId = fromAccount.localAccountId ||
effectiveIdTokenClaims?.oid ||
effectiveIdTokenClaims?.sub ||
"";
const tenantId = fromAccount.tenantId || effectiveIdTokenClaims?.tid || "";
const homeAccountId = fromAccount.homeAccountId || `${localAccountId}.${tenantId}`;
const username = fromAccount.username ||
effectiveIdTokenClaims?.preferred_username ||
"";
const name = fromAccount.name || effectiveIdTokenClaims?.name;
const tenantProfiles = new Map();
const tenantProfile = buildTenantProfile(homeAccountId, localAccountId, tenantId, effectiveIdTokenClaims);
tenantProfiles.set(tenantId, tenantProfile);
const account = {
homeAccountId,
environment: fromAccount.environment,
tenantId,
username,
localAccountId,
name,
idToken: idToken,
idTokenClaims: effectiveIdTokenClaims,
tenantProfiles,
};
return account;
}
/**
*
* @param error BridgeError
* @returns AuthError, ClientAuthError, ClientConfigurationError, ServerError, InteractionRequiredError
*/
fromBridgeError(error) {
if (isBridgeError(error)) {
switch (error.status) {
case BridgeStatusCode.UserCancel:
return new ClientAuthError(ClientAuthErrorCodes.userCanceled);
case BridgeStatusCode.NoNetwork:
return new ClientAuthError(ClientAuthErrorCodes.noNetworkConnectivity);
case BridgeStatusCode.AccountUnavailable:
return new ClientAuthError(ClientAuthErrorCodes.noAccountFound);
case BridgeStatusCode.Disabled:
return new ClientAuthError(ClientAuthErrorCodes.nestedAppAuthBridgeDisabled);
case BridgeStatusCode.NestedAppAuthUnavailable:
return new ClientAuthError(error.code ||
ClientAuthErrorCodes.nestedAppAuthBridgeDisabled, error.description);
case BridgeStatusCode.TransientError:
case BridgeStatusCode.PersistentError:
return new ServerError(error.code, error.description);
case BridgeStatusCode.UserInteractionRequired:
return new InteractionRequiredAuthError(error.code, error.description);
default:
return new AuthError(error.code, error.description);
}
}
else {
return new AuthError("unknown_error", "An unknown error occurred");
}
}
/**
* Returns an AuthenticationResult from the given cache items
*
* @param account
* @param idToken
* @param accessToken
* @param reqTimestamp
* @returns
*/
toAuthenticationResultFromCache(account, idToken, accessToken, request, correlationId) {
if (!idToken || !accessToken) {
throw createClientAuthError(ClientAuthErrorCodes.nullOrEmptyToken);
}
const idTokenClaims = AuthToken.extractTokenClaims(idToken.secret, this.crypto.base64Decode);
const scopes = accessToken.target || request.scopes.join(" ");
const authenticationResult = {
authority: accessToken.environment || account.environment,
uniqueId: account.localAccountId,
tenantId: account.tenantId,
scopes: scopes.split(" "),
account,
idToken: idToken.secret,
idTokenClaims: idTokenClaims || {},
accessToken: accessToken.secret,
fromCache: true,
expiresOn: new Date(Number(accessToken.expiresOn) * 1000),
tokenType: request.authenticationScheme || AuthenticationScheme.BEARER,
correlationId,
extExpiresOn: new Date(Number(accessToken.extendedExpiresOn) * 1000),
state: request.state,
};
return authenticationResult;
}
}
export { NestedAppAuthAdapter };
//# sourceMappingURL=NestedAppAuthAdapter.mjs.map

File diff suppressed because one or more lines are too long