Skip to content

Commit

Permalink
Merge branch 'dev' into dependabot/npm_and_yarn/webpack-5.94.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tnorling committed Sep 10, 2024
2 parents 9f5e32a + e07b676 commit ef2e186
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Add clientLibrary and clientLibraryVersion parameters to NAA Request (#7297)",
"packageName": "@azure/msal-browser",
"email": "dasau@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Add __initializeNestedAppAuth function for Nested App Auth (#7289)",
"packageName": "@azure/msal-browser",
"email": "dasau@microsoft.com",
"dependentChangeType": "patch"
}
33 changes: 20 additions & 13 deletions lib/msal-browser/src/naa/BridgeProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { IBridgeProxy } from "./IBridgeProxy";
import { InitContext } from "./InitContext";
import { TokenRequest } from "./TokenRequest";
import * as BrowserCrypto from "../crypto/BrowserCrypto";
import { BrowserConstants } from "../utils/BrowserConstants";
import { version } from "../packageMetadata";

declare global {
interface Window {
Expand Down Expand Up @@ -77,12 +79,8 @@ export class BridgeProxy implements IBridgeProxy {

const bridgeResponse = await new Promise<BridgeResponseEnvelope>(
(resolve, reject) => {
const message: BridgeRequestEnvelope = {
messageType: "NestedAppAuthRequest",
method: "GetInitContext",
requestId: BrowserCrypto.createNewGuid(),
sendTime: Date.now(),
};
const message = BridgeProxy.buildRequest("GetInitContext");

const request: BridgeRequest = {
requestId: message.requestId,
method: message.method,
Expand Down Expand Up @@ -144,6 +142,21 @@ export class BridgeProxy implements IBridgeProxy {
return this.accountContext ? this.accountContext : null;
}

private static buildRequest(
method: BridgeMethods,
requestParams?: Partial<BridgeRequestEnvelope>
): BridgeRequestEnvelope {
return {
messageType: "NestedAppAuthRequest",
method: method,
requestId: BrowserCrypto.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
Expand All @@ -153,13 +166,7 @@ export class BridgeProxy implements IBridgeProxy {
method: BridgeMethods,
requestParams?: Partial<BridgeRequestEnvelope>
): Promise<BridgeResponseEnvelope> {
const message: BridgeRequestEnvelope = {
messageType: "NestedAppAuthRequest",
method: method,
requestId: BrowserCrypto.createNewGuid(),
sendTime: Date.now(),
...requestParams,
};
const message = BridgeProxy.buildRequest(method, requestParams);

const promise = new Promise<BridgeResponseEnvelope>(
(resolve, reject) => {
Expand Down
15 changes: 10 additions & 5 deletions lib/msal-browser/src/operatingcontext/NestedAppOperatingContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ import { IBridgeProxy } from "../naa/IBridgeProxy";
import { BridgeProxy } from "../naa/BridgeProxy";
import { AccountContext } from "../naa/BridgeAccountContext";

declare global {
interface Window {
__initializeNestedAppAuth?(): Promise<void>;
}
}

export class NestedAppOperatingContext extends BaseOperatingContext {
protected bridgeProxy: IBridgeProxy | undefined = undefined;
protected accountContext: AccountContext | null = null;
Expand Down Expand Up @@ -54,13 +60,12 @@ export class NestedAppOperatingContext extends BaseOperatingContext {
* @returns Promise<boolean> indicating whether this operating context is currently available.
*/
async initialize(): Promise<boolean> {
/*
* TODO: Add implementation to check for presence of inject Nested App Auth Bridge JavaScript interface
*
*/

try {
if (typeof window !== "undefined") {
if (typeof window.__initializeNestedAppAuth === "function") {
await window.__initializeNestedAppAuth();
}

const bridgeProxy: IBridgeProxy = await BridgeProxy.create();
/*
* Because we want single sign on we expect the host app to provide the account context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ export const msalPlugin = {
const inProgress = InteractionStatus.Startup;
const accounts = msalInstance.getAllAccounts();

const state = reactive({
const state = reactive<{
instance: PublicClientApplication
inProgress: InteractionStatus
accounts: AccountInfo[]
}>({
instance: msalInstance,
inProgress: inProgress,
accounts: accounts
Expand Down

0 comments on commit ef2e186

Please sign in to comment.