Skip to content

Fixed bug where dev-provided certificate was not being attached to client assertion #7088

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 6 commits into from
May 13, 2024

Conversation

Robbie-Microsoft
Copy link
Collaborator

@Robbie-Microsoft Robbie-Microsoft commented May 9, 2024

Fixes acquireTokenByClientCredential broken for clientCertificate #7082

Applied boy-scout-rule to ConfidentialClientApplication.spec.ts (contains unit tests). I've been waiting for a good opportunity to do this. The ConfidentialClientApplication tests are now in line with the other test files: All Managed Identity sources, ClientCredentialClient, OnBehalfOfClient and UsernamePasswordClient.

@github-actions github-actions bot added the msal-node Related to msal-node package label May 9, 2024
});

test("acquireTokenByClientCredential handles AuthErrors as expected", async () => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Deleted the test acquireTokenByClientCredential handles AuthErrors as expected.

This test doesn't accomplish anything

Comment on lines 358 to 391
test("ensures that developer-provided certificate is attached to client assertion", async () => {
const getClientAssertionSpy: jest.SpyInstance = jest.spyOn(
ClientApplication.prototype,
<any>"getClientAssertion"
);
};

const appConfig: Configuration = {
auth: {
clientId: TEST_CONSTANTS.CLIENT_ID,
authority: TEST_CONSTANTS.DEFAULT_AUTHORITY, // contains "common"
clientAssertion: "testAssertion",
},
};
const cryptoKeys: CryptoKeys = new CryptoKeys();
config.auth.clientCertificate = {
thumbprint: cryptoKeys.thumbprint,
privateKey: cryptoKeys.privateKey,
};
delete config.auth.clientSecret;
const client: ConfidentialClientApplication =
new ConfidentialClientApplication(config);

const request: ClientCredentialRequest = {
scopes: TEST_CONSTANTS.DEFAULT_GRAPH_SCOPE,
skipCache: false,
};
const request: ClientCredentialRequest = {
scopes: TEST_CONSTANTS.DEFAULT_GRAPH_SCOPE,
skipCache: false,
};

const authApp = new ConfidentialClientApplication(appConfig);
authApp.SetAppTokenProvider(testProvider);
const authResult = (await client.acquireTokenByClientCredential(
request
)) as AuthenticationResult;
expect(authResult.accessToken).toEqual(
CONFIDENTIAL_CLIENT_AUTHENTICATION_RESULT.body.access_token
);

await expect(
authApp.acquireTokenByClientCredential(request)
).rejects.toMatchObject(
createClientAuthError(ClientAuthErrorCodes.missingTenantIdError)
);
const clientAssertion: ClientAssertion = await getClientAssertionSpy
.mock.results[0].value;
expect(clientAssertion.assertion.length).toBeGreaterThan(1);
expect(clientAssertion.assertionType).toBe(
Constants.JWT_BEARER_ASSERTION_TYPE
);
});
Copy link
Collaborator Author

@Robbie-Microsoft Robbie-Microsoft May 9, 2024

Choose a reason for hiding this comment

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

This is the relevant unit test I added for the bug fix

@Robbie-Microsoft Robbie-Microsoft merged commit cacfcba into dev May 13, 2024
8 of 9 checks passed
@Robbie-Microsoft Robbie-Microsoft deleted the client_cert_broken branch May 13, 2024 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
msal-node Related to msal-node package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

acquireTokenByClientCredential broken for clientCertificate
2 participants