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 filters to the event callbacks #7351

Merged
merged 11 commits into from
Oct 7, 2024
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "Add optional event type filter to addEventCallback #7351",
"packageName": "@azure/msal-browser",
"email": "[email protected]",
"dependentChangeType": "patch"
}
49 changes: 30 additions & 19 deletions lib/msal-browser/apiReview/msal-browser.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import { CommonAuthorizationUrlRequest } from '@azure/msal-common/browser';
import { CommonEndSessionRequest } from '@azure/msal-common/browser';
import { CommonSilentFlowRequest } from '@azure/msal-common/browser';
import { ExternalTokenResponse } from '@azure/msal-common/browser';
import { ICrypto } from '@azure/msal-common/browser';
import { IdTokenClaims } from '@azure/msal-common/browser';
import { ILoggerCallback } from '@azure/msal-common/browser';
import { INetworkModule } from '@azure/msal-common/browser';
Expand Down Expand Up @@ -773,6 +772,21 @@ export type EventCallbackFunction = (message: EventMessage) => void;
// @public (undocumented)
export type EventError = AuthError | Error | null;

// Warning: (ae-missing-release-tag) "EventHandler" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export class EventHandler {
constructor(logger?: Logger);
addEventCallback(callback: EventCallbackFunction, eventTypes?: Array<EventType>, callbackId?: string): string | null;
// Warning: (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen
// Warning: (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen
// Warning: (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen
// Warning: (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen
emitEvent(eventType: EventType, interactionType?: InteractionType, payload?: EventPayload, error?: EventError): void;
// Warning: (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen
removeEventCallback(callbackId: string): void;
}

// Warning: (ae-missing-release-tag) "EventMessage" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
Expand Down Expand Up @@ -881,7 +895,7 @@ export interface IController {
// (undocumented)
acquireTokenSilent(silentRequest: SilentRequest): Promise<AuthenticationResult>;
// (undocumented)
addEventCallback(callback: EventCallbackFunction): string | null;
addEventCallback(callback: EventCallbackFunction, eventTypes?: Array<EventType>): string | null;
// (undocumented)
addPerformanceCallback(callback: PerformanceCallbackFunction): string;
// (undocumented)
Expand All @@ -904,10 +918,6 @@ export interface IController {
getAllAccounts(accountFilter?: AccountFilter): AccountInfo[];
// @internal (undocumented)
getConfiguration(): BrowserConfiguration;
// Warning: (ae-forgotten-export) The symbol "EventHandler" needs to be exported by the entry point index.d.ts
//
// @internal (undocumented)
getEventHandler(): EventHandler;
// (undocumented)
getLogger(): Logger;
// @internal (undocumented)
Expand Down Expand Up @@ -1057,7 +1067,7 @@ export interface IPublicClientApplication {
// (undocumented)
acquireTokenSilent(silentRequest: SilentRequest): Promise<AuthenticationResult>;
// (undocumented)
addEventCallback(callback: EventCallbackFunction): string | null;
addEventCallback(callback: EventCallbackFunction, eventTypes?: Array<EventType>): string | null;
// (undocumented)
addPerformanceCallback(callback: PerformanceCallbackFunction): string;
// (undocumented)
Expand Down Expand Up @@ -1359,7 +1369,8 @@ export class PublicClientApplication implements IPublicClientApplication {
// Warning: (tsdoc-malformed-inline-tag) Expecting a TSDoc tag starting with "{@"
acquireTokenSilent(silentRequest: SilentRequest): Promise<AuthenticationResult>;
// Warning: (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen
addEventCallback(callback: EventCallbackFunction): string | null;
// Warning: (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen
addEventCallback(callback: EventCallbackFunction, eventTypes?: Array<EventType>): string | null;
// Warning: (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen
// Warning: (tsdoc-param-tag-with-invalid-type) The @param block should not include a JSDoc-style '{type}'
// Warning: (tsdoc-escape-right-brace) The "}" character should be escaped using a backslash to avoid confusion with a TSDoc inline tag
Expand Down Expand Up @@ -1449,7 +1460,7 @@ export class PublicClientNext implements IPublicClientApplication {
// Warning: (tsdoc-malformed-inline-tag) Expecting a TSDoc tag starting with "{@"
acquireTokenSilent(silentRequest: SilentRequest): Promise<AuthenticationResult>;
// Warning: (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen
addEventCallback(callback: EventCallbackFunction): string | null;
addEventCallback(callback: EventCallbackFunction, eventTypes?: Array<EventType>): string | null;
// Warning: (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen
// Warning: (tsdoc-param-tag-with-invalid-type) The @param block should not include a JSDoc-style '{type}'
// Warning: (tsdoc-escape-right-brace) The "}" character should be escaped using a backslash to avoid confusion with a TSDoc inline tag
Expand Down Expand Up @@ -1692,17 +1703,17 @@ export type WrapperSKU = (typeof WrapperSKU)[keyof typeof WrapperSKU];

// Warnings were encountered during analysis:
//
// src/app/PublicClientNext.ts:69:8 - (tsdoc-undefined-tag) The TSDoc tag "@constructor" is not defined in this configuration
// src/app/PublicClientNext.ts:78:87 - (tsdoc-escape-right-brace) The "}" character should be escaped using a backslash to avoid confusion with a TSDoc inline tag
// src/app/PublicClientNext.ts:78:60 - (tsdoc-malformed-inline-tag) Expecting a TSDoc tag starting with "{@"
// src/app/PublicClientNext.ts:84:64 - (tsdoc-escape-right-brace) The "}" character should be escaped using a backslash to avoid confusion with a TSDoc inline tag
// src/app/PublicClientNext.ts:84:77 - (tsdoc-escape-right-brace) The "}" character should be escaped using a backslash to avoid confusion with a TSDoc inline tag
// src/app/PublicClientNext.ts:84:90 - (tsdoc-escape-right-brace) The "}" character should be escaped using a backslash to avoid confusion with a TSDoc inline tag
// src/app/PublicClientNext.ts:84:55 - (tsdoc-malformed-inline-tag) Expecting a TSDoc tag starting with "{@"
// src/app/PublicClientNext.ts:84:70 - (tsdoc-malformed-inline-tag) Expecting a TSDoc tag starting with "{@"
// src/app/PublicClientNext.ts:84:79 - (tsdoc-malformed-inline-tag) Expecting a TSDoc tag starting with "{@"
// src/app/PublicClientNext.ts:87:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen
// src/app/PublicClientNext.ts:70:8 - (tsdoc-undefined-tag) The TSDoc tag "@constructor" is not defined in this configuration
// src/app/PublicClientNext.ts:79:87 - (tsdoc-escape-right-brace) The "}" character should be escaped using a backslash to avoid confusion with a TSDoc inline tag
// src/app/PublicClientNext.ts:79:60 - (tsdoc-malformed-inline-tag) Expecting a TSDoc tag starting with "{@"
// src/app/PublicClientNext.ts:85:64 - (tsdoc-escape-right-brace) The "}" character should be escaped using a backslash to avoid confusion with a TSDoc inline tag
// src/app/PublicClientNext.ts:85:77 - (tsdoc-escape-right-brace) The "}" character should be escaped using a backslash to avoid confusion with a TSDoc inline tag
// src/app/PublicClientNext.ts:85:90 - (tsdoc-escape-right-brace) The "}" character should be escaped using a backslash to avoid confusion with a TSDoc inline tag
// src/app/PublicClientNext.ts:85:55 - (tsdoc-malformed-inline-tag) Expecting a TSDoc tag starting with "{@"
// src/app/PublicClientNext.ts:85:70 - (tsdoc-malformed-inline-tag) Expecting a TSDoc tag starting with "{@"
// src/app/PublicClientNext.ts:85:79 - (tsdoc-malformed-inline-tag) Expecting a TSDoc tag starting with "{@"
// src/app/PublicClientNext.ts:88:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen
// src/app/PublicClientNext.ts:89:8 - (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen
// src/config/Configuration.ts:245:5 - (ae-forgotten-export) The symbol "InternalAuthOptions" needs to be exported by the entry point index.d.ts
// src/index.ts:8:12 - (tsdoc-characters-after-block-tag) The token "@azure" looks like a TSDoc tag but contains an invalid character "/"; if it is not a tag, use a backslash to escape the "@"
// src/index.ts:8:4 - (tsdoc-undefined-tag) The TSDoc tag "@module" is not defined in this configuration
Expand Down
6 changes: 5 additions & 1 deletion lib/msal-browser/src/app/IPublicClientApplication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { AuthenticationResult } from "../response/AuthenticationResult.js";
import { EventCallbackFunction } from "../event/EventMessage.js";
import { ClearCacheRequest } from "../request/ClearCacheRequest.js";
import { InitializeApplicationRequest } from "../request/InitializeApplicationRequest.js";
import { EventType } from "../event/EventType.js";

export interface IPublicClientApplication {
// TODO: Make request mandatory in the next major version?
Expand All @@ -40,7 +41,10 @@ export interface IPublicClientApplication {
acquireTokenByCode(
request: AuthorizationCodeRequest
): Promise<AuthenticationResult>;
addEventCallback(callback: EventCallbackFunction): string | null;
addEventCallback(
callback: EventCallbackFunction,
eventTypes?: Array<EventType>
): string | null;
removeEventCallback(callbackId: string): void;
addPerformanceCallback(callback: PerformanceCallbackFunction): string;
removePerformanceCallback(callbackId: string): boolean;
Expand Down
9 changes: 7 additions & 2 deletions lib/msal-browser/src/app/PublicClientApplication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { EndSessionPopupRequest } from "../request/EndSessionPopupRequest.js";
import { NestedAppAuthController } from "../controllers/NestedAppAuthController.js";
import { NestedAppOperatingContext } from "../operatingcontext/NestedAppOperatingContext.js";
import { InitializeApplicationRequest } from "../request/InitializeApplicationRequest.js";
import { EventType } from "../event/EventType.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 @@ -151,9 +152,13 @@ export class PublicClientApplication implements IPublicClientApplication {
/**
* Adds event callbacks to array
* @param callback
* @param eventTypes
*/
addEventCallback(callback: EventCallbackFunction): string | null {
return this.controller.addEventCallback(callback);
addEventCallback(
callback: EventCallbackFunction,
eventTypes?: Array<EventType>
): string | null {
return this.controller.addEventCallback(callback, eventTypes);
}

/**
Expand Down
8 changes: 6 additions & 2 deletions lib/msal-browser/src/app/PublicClientNext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { ClearCacheRequest } from "../request/ClearCacheRequest.js";
import { AuthenticationResult } from "../response/AuthenticationResult.js";
import { UnknownOperatingContextController } from "../controllers/UnknownOperatingContextController.js";
import { UnknownOperatingContext } from "../operatingcontext/UnknownOperatingContext.js";
import { EventType } from "../event/EventType.js";

/**
* PublicClientNext is an early look at the planned implementation of PublicClientApplication in the next major version of MSAL.js.
Expand Down Expand Up @@ -176,8 +177,11 @@ export class PublicClientNext implements IPublicClientApplication {
* Adds event callbacks to array
* @param callback
*/
addEventCallback(callback: EventCallbackFunction): string | null {
return this.controller.addEventCallback(callback);
addEventCallback(
callback: EventCallbackFunction,
eventTypes?: Array<EventType>
): string | null {
return this.controller.addEventCallback(callback, eventTypes);
}

/**
Expand Down
9 changes: 5 additions & 4 deletions lib/msal-browser/src/controllers/IController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { AuthenticationResult } from "../response/AuthenticationResult.js";
import { EventCallbackFunction } from "../event/EventMessage.js";
import { ClearCacheRequest } from "../request/ClearCacheRequest.js";
import { InitializeApplicationRequest } from "../request/InitializeApplicationRequest.js";
import { EventType } from "../event/EventType.js";

export interface IController {
// TODO: Make request mandatory in the next major version?
Expand All @@ -49,7 +50,10 @@ export interface IController {
accountId?: string
): Promise<AuthenticationResult>;

addEventCallback(callback: EventCallbackFunction): string | null;
addEventCallback(
callback: EventCallbackFunction,
eventTypes?: Array<EventType>
): string | null;

removeEventCallback(callbackId: string): void;

Expand Down Expand Up @@ -118,7 +122,4 @@ export interface IController {

/** @internal */
getPerformanceClient(): IPerformanceClient;

/** @internal */
getEventHandler(): EventHandler;
}
18 changes: 7 additions & 11 deletions lib/msal-browser/src/controllers/NestedAppAuthController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export class NestedAppAuthController implements IController {
this.logger
);

this.eventHandler = new EventHandler(this.logger, this.browserCrypto);
this.eventHandler = new EventHandler(this.logger);

this.nestedAppAuthAdapter = new NestedAppAuthAdapter(
this.config.auth.clientId,
Expand All @@ -140,14 +140,6 @@ export class NestedAppAuthController implements IController {
}
}

/**
* Returns the event handler instance
* @returns EventHandler
*/
getEventHandler(): EventHandler {
return this.eventHandler;
}

/**
* Factory function to create a new instance of NestedAppAuthController
* @param operatingContext
Expand Down Expand Up @@ -588,9 +580,13 @@ export class NestedAppAuthController implements IController {
/**
* Adds event callbacks to array
* @param callback
* @param eventTypes
*/
addEventCallback(callback: EventCallbackFunction): string | null {
return this.eventHandler.addEventCallback(callback);
addEventCallback(
callback: EventCallbackFunction,
eventTypes?: Array<EventType>
): string | null {
return this.eventHandler.addEventCallback(callback, eventTypes);
}

/**
Expand Down
Loading
Loading