Skip to content

Manifest v3 POC #7802

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/msal-browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-terser": "^0.4.0",
"@rollup/plugin-typescript": "^11.0.0",
"@types/chrome": "^0.0.306",
"@types/jest": "^29.5.0",
"@types/node": "^20.3.1",
"dotenv": "^8.2.0",
Expand Down
8 changes: 8 additions & 0 deletions lib/msal-browser/src/app/IPublicClientApplication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export interface IPublicClientApplication {
handleRedirectPromise(hash?: string): Promise<AuthenticationResult | null>;
loginPopup(request?: PopupRequest): Promise<AuthenticationResult>;
loginRedirect(request?: RedirectRequest): Promise<void>;
loginExtension(request?: RedirectRequest): Promise<AuthenticationResult>;
logout(logoutRequest?: EndSessionRequest): Promise<void>;
logoutRedirect(logoutRequest?: EndSessionRequest): Promise<void>;
logoutPopup(logoutRequest?: EndSessionPopupRequest): Promise<void>;
Expand Down Expand Up @@ -154,6 +155,13 @@ export const stubbedPublicClientApplication: IPublicClientApplication = {
)
);
},
loginExtension: () => {
return Promise.reject(
createBrowserConfigurationAuthError(
BrowserConfigurationAuthErrorCodes.stubbedPublicClientApplicationCalled
)
);
},
logout: () => {
return Promise.reject(
createBrowserConfigurationAuthError(
Expand Down
40 changes: 40 additions & 0 deletions lib/msal-browser/src/app/PublicClientApplication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import { NestedAppAuthController } from "../controllers/NestedAppAuthController.
import { NestedAppOperatingContext } from "../operatingcontext/NestedAppOperatingContext.js";
import { InitializeApplicationRequest } from "../request/InitializeApplicationRequest.js";
import { EventType } from "../event/EventType.js";
import { BrowserExtensionOperatingContext } from "../operatingcontext/BrowserExtensionOperatingContext.js";
import { BrowserExtensionController } from "../controllers/BrowserExtensionController.js";

/**
* The PublicClientApplication class is the object exposed by the library to perform authentication and authorization functions in Single Page Applications
Expand Down Expand Up @@ -284,6 +286,17 @@ export class PublicClientApplication implements IPublicClientApplication {
return this.controller.loginPopup(request);
}

/**
* Use when initiating the login process from a browser extension
* @param request
*
*/
loginExtension(
request?: PopupRequest | undefined
): Promise<AuthenticationResult> {
return this.controller.loginExtension(request);
}

/**
* Use when initiating the login process by redirecting the user's browser to the authorization endpoint. This function redirects the page, so
* any code that follows this function will not execute.
Expand Down Expand Up @@ -457,6 +470,33 @@ export async function createNestablePublicClientApplication(
return createStandardPublicClientApplication(configuration);
}

/**
* creates BrowserExtensionController and passes it to the PublicClientApplication,
* falls back to StandardController if BrowserExtensionController is not available
*
* @param configuration
* @returns IPublicClientApplication
*
*/
export async function createBrowserExtensionPublicClientApplication(
configuration: Configuration
): Promise<IPublicClientApplication> {
const browserExtension = new BrowserExtensionOperatingContext(configuration);
await browserExtension.initialize();

if (browserExtension.isAvailable()) {
const controller = new BrowserExtensionController(browserExtension);
const browserExtensionPCA = new PublicClientApplication(
configuration,
controller
);
await browserExtensionPCA.initialize();
return browserExtensionPCA;
}

return createStandardPublicClientApplication(configuration);
}

/**
* creates PublicClientApplication using StandardController
*
Expand Down
4 changes: 4 additions & 0 deletions lib/msal-browser/src/app/PublicClientNext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,10 @@ export class PublicClientNext implements IPublicClientApplication {
return this.controller.loginRedirect(request);
}

loginExtension(request?: RedirectRequest): Promise<AuthenticationResult> {
return this.controller.loginExtension(request);
}

/**
* Deprecated logout function. Use logoutRedirect or logoutPopup instead
* @param logoutRequest
Expand Down
2 changes: 1 addition & 1 deletion lib/msal-browser/src/cache/LocalStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class LocalStorage implements IWindowStorage<string> {
logger: Logger,
performanceClient: IPerformanceClient
) {
if (!window.localStorage) {
if (!window?.localStorage) {
throw createBrowserConfigurationAuthError(
BrowserConfigurationAuthErrorCodes.storageNotSupported
);
Expand Down
Loading