-
Notifications
You must be signed in to change notification settings - Fork 2.7k
10000
Show file tree
Hide file tree
Mar 11, 2025
Mar 12, 2025
Mar 12, 2025
Mar 12, 2025
Mar 18, 2025
Mar 18, 2025
Mar 19, 2025
Mar 31, 2025
Apr 10, 2025
Apr 10, 2025
Apr 16, 2025
Apr 22, 2025
Apr 23, 2025
Apr 23, 2025
Apr 23, 2025
Apr 29, 2025
Apr 29, 2025
Apr 29, 2025
May 1, 2025
May 1, 2025
May 1, 2025
May 2, 2025
May 2, 2025
May 6, 2025
May 6, 2025
May 6, 2025
May 6, 2025
May 6, 2025
May 6, 2025
May 6, 2025
May 6, 2025
May 6, 2025
May 7, 2025
May 7, 2025
May 9, 2025
May 9, 2025
May 9, 2025
May 12, 2025
May 12, 2025
May 12, 2025
May 12, 2025
May 12, 2025
May 14, 2025
May 15, 2025
Loading
Add support for new platform broker flow via DOM API #7632
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
Merged
Merged
Changes from all commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
5e6321f
added isPlatformBrokerAvailable API
lalimasharda ce0d102
updated isPlatformBrokerAvailable implementation
lalimasharda a1b0fa1
code cleanup
lalimasharda 883daa4
Merge branch 'dev' of https://github.com/AzureAD/microsoft-authentica…
lalimasharda 381473c
updated isPlatformBrokerAvailable()
lalimasharda 1f9481c
Merge branch 'dev' of https://github.com/AzureAD/microsoft-authentica…
lalimasharda 0707c51
Merge branch 'dev' into addEdgeNativeApi
sameerag 15dcb07
added initializeNativeDOMRequest
lalimasharda 259f730
resolving merge conflicts
lalimasharda 1ffd693
updated StandardController with latest changes
lalimasharda 97c61f6
Merge branch 'dev' of https://github.com/AzureAD/microsoft-authentica…
lalimasharda 623c4b2
Merge branch 'dev' of https://github.com/AzureAD/microsoft-authentica…
lalimasharda e0c368a
native dom api updates
lalimasharda bffb842
Merge branch 'dev' of https://github.com/AzureAD/microsoft-authentica…
lalimasharda 88d9323
saving updates
lalimasharda 7a29309
updates to dom native support and added feature flag to enable dom n…
lalimasharda 86d5753
Merge branch 'addEdgeNativeApi' of https://github.com/AzureAD/microso…
lalimasharda ff88027
Merge branch 'dev' of https://github.com/AzureAD/microsoft-authentica…
lalimasharda ecf1b3a
refactoring NativeInteractionClient and addressing some comments
lalimasharda 00b6cb5
Merge branch 'dev' of https://github.com/AzureAD/microsoft-authentica…
lalimasharda 074e618
added IPlatformBrokerHandler interface
lalimasharda 0811338
added IPlatformAuthHandler interface and renamed Native to PlatformAuth
lalimasharda fb078dc
addressing comments
lalimasharda 6feef52
addressing comments
lalimasharda 9bcc2a8
added support for enabling dom api feature through sessionStorage
lalimasharda 0aa2809
resolving merge conflicts
lalimasharda 1a6541c
updated sample with isPlatformBrokerAvailable usage
lalimasharda e3d0606
updating comment
lalimasharda 94007c2
Change files
lalimasharda 635dbbe
change file updates
lalimasharda 6e7443c
hardcoding brokerId param
lalimasharda 5ad7546
fixing isDomEnabledForPlatformAuth
lalimasharda 7643939
addressed commits and fixed unit tests
lalimasharda 63e27f6
Merge branch 'dev' of https://github.com/AzureAD/microsoft-authentica…
lalimasharda 6a519bc
added tests for PlatformAuthDOMHandler
lalimasharda 75f3721
removing console statement
lalimasharda d4339e9
small updates
lalimasharda 3f0455e
addressing comments and added unit tests
lalimasharda 05570d3
Update lib/msal-browser/src/broker/nativeBroker/PlatformAuthProvider.ts
lalimasharda e975305
updating msal-browser-api
lalimasharda 2c5400b
Merge branch 'addEdgeNativeApi' of https://github.com/AzureAD/microso…
lalimasharda bcb22a5
undoing prettier formatting changes
lalimasharda b4391f7
Merge branch 'dev' of https://github.com/AzureAD/microsoft-authentica…
lalimasharda 05e23d6
updating logger statements
lalimasharda File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@azure-msal-browser-a202c777-7916-40aa-a0fe-81b7a800d1c7.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "minor", | ||
"comment": "Add support for new platform broker flow via DOM API #7632", | ||
"packageName": "@azure/msal-browser", | ||
"email": "lalimasharda@microsoft.com", | ||
"dependentChangeType": "patch" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
lib/msal-browser/src/broker/nativeBroker/IPlatformAuthHandler.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. | ||
*/ | ||
|
||
import { PlatformBrokerRequest } from "./PlatformBrokerRequest.js"; | ||
import { PlatformBrokerResponse } from "./PlatformBrokerResponse.js"; | ||
|
||
/** | ||
* Interface for the Platform Broker Handlers | ||
*/ | ||
export interface IPlatformAuthHandler { | ||
getExtensionId(): string | undefined; | ||
getExtensionVersion(): string | undefined; | ||
getExtensionName(): string | undefined; | ||
sendMessage( | ||
request: PlatformBrokerRequest | ||
): Promise<PlatformBrokerResponse>; | ||
} |
241 changes: 241 additions & 0 deletions
241
lib/msal-browser/src/broker/nativeBroker/PlatformAuthDOMHandler.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,241 @@ | ||
/* | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. | ||
*/ | ||
|
||
import { | ||
Logger, | ||
createAuthError, | ||
AuthErrorCodes, | ||
IPerformanceClient, | ||
StringDict, | ||
} from "@azure/msal-common/browser"; | ||
import { | ||
PlatformBrokerRequest, | ||
PlatformDOMTokenRequest, | ||
} from "./PlatformBrokerRequest.js"; | ||
import { PlatformAuthConstants } from "../../utils/BrowserConstants.js"; | ||
import { | ||
PlatformBrokerResponse, | ||
PlatformDOMTokenResponse, | ||
} from "./PlatformBrokerResponse.js"; | ||
import { createNativeAuthError } from "../../error/NativeAuthError.js"; | ||
import { IPlatformAuthHandler } from "./IPlatformAuthHandler.js"; | ||
|
||
export class PlatformAuthDOMHandler implements IPlatformAuthHandler { | ||
protected logger: Logger; | ||
protected performanceClient: IPerformanceClient; | ||
protected correlationId: string; | ||
platformAuthType: string; | ||
|
||
constructor( | ||
logger: Logger, | ||
performanceClient: IPerformanceClient, | ||
correlationId: string | ||
) { | ||
this.logger = logger; | ||
this.performanceClient = performanceClient; | ||
this.correlationId = correlationId; | ||
this.platformAuthType = PlatformAuthConstants.PLATFORM_DOM_PROVIDER; | ||
} | ||
|
||
static async createProvider( | ||
logger: Logger, | ||
performanceClient: IPerformanceClient, | ||
correlationId: string | ||
): Promise<PlatformAuthDOMHandler | undefined> { | ||
logger.trace("PlatformAuthDOMHandler: createProvider called"); | ||
|
||
// @ts-ignore | ||
if (window.navigator?.platformAuthentication) { | ||
const supportedContracts = | ||
// @ts-ignore | ||
await window.navigator.platformAuthentication.getSupportedContracts( | ||
PlatformAuthConstants.MICROSOFT_ENTRA_BROKERID | ||
); | ||
if ( | ||
supportedContracts?.includes( | ||
PlatformAuthConstants.PLATFORM_DOM_APIS | ||
) | ||
) { | ||
logger.trace("Platform auth api available in DOM"); | ||
return new PlatformAuthDOMHandler( | ||
logger, | ||
performanceClient, | ||
correlationId | ||
); | ||
} | ||
} | ||
return undefined; | ||
} | ||
|
||
/** | ||
* Returns the Id for the broker extension this handler is communicating with | ||
* @returns | ||
*/ | ||
getExtensionId(): string { | ||
return PlatformAuthConstants.MICROSOFT_ENTRA_BROKERID; | ||
} | ||
|
||
getExtensionVersion(): string | undefined { | ||
return ""; | ||
} | ||
|
||
getExtensionName(): string | undefined { | ||
return PlatformAuthConstants.DOM_API_NAME; | ||
} | ||
|
||
/** | ||
* Send token request to platform broker via browser DOM API | ||
* @param request | ||
* @returns | ||
*/ | ||
async sendMessage( | ||
request: PlatformBrokerRequest | ||
): Promise<PlatformBrokerResponse> { | ||
this.logger.trace( | ||
this.platformAuthType + " - Sending request to browser DOM API" | ||
); | ||
|
||
try { | ||
const platformDOMRequest: PlatformDOMTokenRequest = | ||
this.initializePlatformDOMRequest(request); | ||
const response: object = | ||
// @ts-ignore | ||
await window.navigator.platformAuthentication.executeGetToken( | ||
platformDOMRequest | ||
); | ||
return this.validatePlatformBrokerResponse(response); | ||
} catch (e) { | ||
this.logger.error( | ||
this.platformAuthType + " - executeGetToken DOM API error" | ||
); | ||
throw e; | ||
} | ||
} | ||
|
||
private initializePlatformDOMRequest( | ||
request: PlatformBrokerRequest | ||
): PlatformDOMTokenRequest { | ||
this.logger.trace( | ||
this.platformAuthType + " - initializeNativeDOMRequest called" | ||
); | ||
|
||
const { | ||
accountId, | ||
clientId, | ||
authority, | ||
scope, | ||
redirectUri, | ||
correlationId, | ||
state, | ||
storeInCache, | ||
embeddedClientId, | ||
extraParameters, | ||
...remainingProperties | ||
lalimasharda marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} = request; | ||
|
||
const validExtraParameters = | ||
this.stringifyExtraParameters(remainingProperties); | ||
|
||
const platformDOMRequest: PlatformDOMTokenRequest = { | ||
accountId: accountId, | ||
brokerId: this.getExtensionId(), | ||
authority: authority, | ||
clientId: clientId, | ||
correlationId: correlationId || this.correlationId, | ||
extraParameters: { ...extraParameters, ...validExtraParameters }, | ||
isSecurityTokenService: false, | ||
redirectUri: redirectUri, | ||
scope: scope, | ||
state: state, | ||
storeInCache: storeInCache, | ||
embeddedClientId: embeddedClientId, | ||
}; | ||
|
||
return platformDOMRequest; | ||
} | ||
|
||
private validatePlatformBrokerResponse( | ||
response: object | ||
): PlatformBrokerResponse { | ||
if (response.hasOwnProperty("isSuccess")) { | ||
if ( | ||
response.hasOwnProperty("accessToken") && | ||
response.hasOwnProperty("idToken") && | ||
response.hasOwnProperty("clientInfo") && | ||
response.hasOwnProperty("account") && | ||
response.hasOwnProperty("scopes") && | ||
response.hasOwnProperty("expiresIn") | ||
) { | ||
this.logger.trace( | ||
this.platformAuthType + | ||
" - platform broker returned successful and valid response" | ||
); | ||
return this.convertToPlatformBrokerResponse( | ||
response as PlatformDOMTokenResponse | ||
); | ||
} else if (response.hasOwnProperty("error")) { | ||
const errorResponse = response as PlatformDOMTokenResponse; | ||
if ( | ||
errorResponse.isSuccess === false && | ||
errorResponse.error && | ||
errorResponse.error.code | ||
) { | ||
this.logger.trace( | ||
this.platformAuthType + | ||
" - platform broker returned error response" | ||
); | ||
throw createNativeAuthError( | ||
errorResponse.error.code, | ||
errorResponse.error.description, | ||
{ | ||
error: parseInt(errorResponse.error.errorCode), | ||
protocol_error: errorResponse.error.protocolError, | ||
status: errorResponse.error.status, | ||
properties: errorResponse.error.properties, | ||
} | ||
); | ||
} | ||
} | ||
} | ||
throw createAuthError( | ||
AuthErrorCodes.unexpectedError, | ||
"Response missing expected properties." | ||
); | ||
} | ||
|
||
private convertToPlatformBrokerResponse( | ||
response: PlatformDOMTokenResponse | ||
): PlatformBrokerResponse { | ||
this.logger.trace( | ||
this.platformAuthType + " - convertToNativeResponse called" | ||
); | ||
const nativeResponse: PlatformBrokerResponse = { | ||
access_token: response.accessToken, | ||
id_token: response.idToken, | ||
client_info: response.clientInfo, | ||
account: response.account, | ||
expires_in: response.expiresIn, | ||
scope: response.scopes, | ||
state: response.state || "", | ||
properties: response.properties || {}, | ||
extendedLifetimeToken: response.extendedLifetimeToken ?? false, | ||
shr: response.proofOfPossessionPayload, | ||
}; | ||
|
||
return nativeResponse; | ||
} | ||
|
||
private stringifyExtraParameters( | ||
extraParameters: Record<string, unknown> | ||
): StringDict { | ||
return Object.entries(extraParameters).reduce( | ||
(record, [key, value]) => { | ||
record[key] = String(value); | ||
return record; | ||
}, | ||
{} as StringDict | ||
); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.