Skip to content

Commit

Permalink
PoP Support for Node when brokered (#7360)
Browse files Browse the repository at this point in the history
Fixes PoP support for Node when using the native broker
  • Loading branch information
tnorling authored Oct 8, 2024
1 parent 367915c commit 34c3970
Show file tree
Hide file tree
Showing 6 changed files with 212 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "Fix POP token acquisition via MsalRuntime",
"packageName": "@azure/msal-node-extensions",
"email": "[email protected]",
"dependentChangeType": "patch"
}
2 changes: 1 addition & 1 deletion extensions/msal-node-extensions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
},
"dependencies": {
"@azure/msal-common": "14.15.0",
"@azure/msal-node-runtime": "^0.13.6-alpha.0",
"@azure/msal-node-runtime": "^0.17.1",
"keytar": "^7.8.0"
},
"devDependencies": {
Expand Down
24 changes: 16 additions & 8 deletions extensions/msal-node-extensions/src/broker/NativeBrokerPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,19 +466,18 @@ export class NativeBrokerPlugin implements INativeBrokerPlugin {
if (request.authenticationScheme === AuthenticationScheme.POP) {
if (
!request.resourceRequestMethod ||
!request.resourceRequestUri ||
!request.shrNonce
!request.resourceRequestUri
) {
throw new Error(
"Authentication Scheme set to POP but one or more of the following parameters are missing: resourceRequestMethod, resourceRequestUri, shrNonce"
"Authentication Scheme set to POP but one or more of the following parameters are missing: resourceRequestMethod, resourceRequestUri"
);
}
const resourceUrl = new URL(request.resourceRequestUri);
authParams.SetPopParams(
request.resourceRequestMethod,
resourceUrl.host,
resourceUrl.pathname,
request.shrNonce
request.shrNonce || ""
);
}

Expand Down Expand Up @@ -548,6 +547,17 @@ export class NativeBrokerPlugin implements INativeBrokerPlugin {
idTokenClaims
);

let accessToken;
let tokenType;
if (authResult.isPopAuthorization) {
// Header includes 'pop ' prefix
accessToken = authResult.authorizationHeader.split(" ")[1];
tokenType = AuthenticationScheme.POP;
} else {
accessToken = authResult.accessToken;
tokenType = AuthenticationScheme.BEARER;
}

const result: AuthenticationResult = {
authority: request.authority,
uniqueId: idTokenClaims.oid || idTokenClaims.sub || "",
Expand All @@ -556,12 +566,10 @@ export class NativeBrokerPlugin implements INativeBrokerPlugin {
account: accountInfo,
idToken: authResult.rawIdToken,
idTokenClaims: idTokenClaims,
accessToken: authResult.accessToken,
accessToken: accessToken,
fromCache: fromCache,
expiresOn: new Date(authResult.expiresOn),
tokenType: authResult.isPopAuthorization
? AuthenticationScheme.POP
: AuthenticationScheme.BEARER,
tokenType: tokenType,
correlationId: request.correlationId,
fromNativeBroker: true,
};
Expand Down
Loading

0 comments on commit 34c3970

Please sign in to comment.