Skip to content
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

Add new isPlatformBrokerAvailable() API #7632

Draft
wants to merge 6 commits into
base: dev
Choose a base branch
from
Draft

Conversation

lalimasharda
Copy link
Contributor

@lalimasharda lalimasharda commented Mar 11, 2025

This PR adds a new public facing API isPlatformBrokerAvailable() that lets the client app check if platform broker is available for to acquire tokens natively. The method checks if brokering is available via DOM APIs or the browser extension.

@github-actions github-actions bot added the msal-browser Related to msal-browser package label Mar 11, 2025
@lalimasharda lalimasharda changed the title added isPlatformBrokerAvailable API Add new isPlatformBrokerAvailable() API Mar 12, 2025
logLevel: LogLevel.Trace,
};

const temporaryLogger = new Logger(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: you can just call this logger

clientId: "test-clientid",
},
};
const temporaryTelemetryClient: IPerformanceClient =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: just call this performanceClient

// Check if DOM platform API is supported

// @ts-ignore
if (window.navigator?.platformAuthentication) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also check that window is defined and return false if not

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, may be also a trace statement. Do we identify non-DOM environments today in logs?

/**
* Public method to indicate whether platform broker is available to make native token request.
*/
export async function isPlatformBrokerAvailable(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we put this in a new file under the broker folder instead?

Copy link
Contributor Author

@lalimasharda lalimasharda Mar 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay sure, I can just add it to the new Handler file that goes under broker that will handle DOM requests.

// @ts-ignore
if (window.navigator?.platformAuthentication) {
const supportedContracts =
// @ts-ignore
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why ts-ignore?

const supportedContracts =
// @ts-ignore
await window.navigator.platformAuthentication.getSupportedContracts(
"MicrosoftEntra"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is our latest on constants for min file optimizations? Do we directly use strings? If these are standardized, I would like a constant defined elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I will add it as a constant

@@ -348,7 +430,8 @@ export class StandardController implements IController {

if (allowPlatformBroker) {
try {
this.nativeExtensionProvider =
// check if platform authentication is available via DOM or browser extension and create relevant handlers
this.platformAuthProvider =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So is the plan to expand createProvider to include DOM API calls?

@@ -156,7 +238,7 @@ export class StandardController implements IController {
>;

// Native Extension Provider
protected nativeExtensionProvider: NativeMessageHandler | undefined;
protected platformAuthProvider: NativeMessageHandler | undefined;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably should be either NativeMessageHandler or DOMHandler correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't changed the type yet because I just wanted to test isPlatformAvailable() API e2e first. I was thinking of changing the implementation to Map<String, NativeMessageHandler | DOMHandler> like we discussed before but tied to Standard controller instead of being a global variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
msal-browser Related to msal-browser package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants