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

Client Assertion implementation now accepts an async callback as well as a string argument #7014

Merged
merged 25 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c8e9c68
client assertion accepts callback instead of string argument
Robbie-Microsoft Apr 9, 2024
ab837fa
Change files
Robbie-Microsoft Apr 9, 2024
95781be
Merge branch 'dev' into client_assertion
Robbie-Microsoft Apr 9, 2024
f07f039
fixed broken unit tests
Robbie-Microsoft Apr 9, 2024
db71561
Merge branch 'dev' into client_assertion
Robbie-Microsoft Apr 9, 2024
efb092e
Merge branch 'dev' into client_assertion
Robbie-Microsoft Apr 9, 2024
8b70f4d
Pinned identity version in e2e samples
Robbie-Microsoft Apr 10, 2024
e23fe53
undo accidental package bump
Robbie-Microsoft Apr 10, 2024
e182749
Merge branch 'dev' into client_assertion
Robbie-Microsoft Apr 10, 2024
08ff604
Merge branch 'dev' into client_assertion
Robbie-Microsoft Apr 11, 2024
db2154b
Implemented Feedback in msal-common files
Robbie-Microsoft Apr 11, 2024
a1a91eb
Moved confidential client's setClientCredential from its contructor t…
Robbie-Microsoft Apr 23, 2024
a4dad0d
Merge branch 'dev' into client_assertion
Robbie-Microsoft Apr 23, 2024
7968ac3
Implemented GitHub Feedback
Robbie-Microsoft Apr 24, 2024
e303ea3
unit tests
Robbie-Microsoft Apr 25, 2024
76829e5
Updated tests
Robbie-Microsoft Apr 25, 2024
3250219
Merge branch 'dev' into client_assertion
Robbie-Microsoft Apr 26, 2024
561d01d
refactored code and made improvements
Robbie-Microsoft Apr 26, 2024
973f705
removed comment
Robbie-Microsoft Apr 26, 2024
e90cea2
Merge branch 'dev' into client_assertion
Robbie-Microsoft Apr 26, 2024
dd7bef9
Merge branch 'dev' into client_assertion
Robbie-Microsoft Apr 30, 2024
0de0a86
Merge branch 'dev' into client_assertion
Robbie-Microsoft Apr 30, 2024
6b23035
Merge branch 'dev' into client_assertion
Robbie-Microsoft Apr 30, 2024
d0e6c95
updated comment
Robbie-Microsoft Apr 30, 2024
f4a6721
fixed broken unit tests
Robbie-Microsoft Apr 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "Client Assertion Implementation now accepts a callback instead of a string argument",
"packageName": "@azure/msal-common",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "Client Assertion Implementation now accepts a callback instead of a string argument",
"packageName": "@azure/msal-node",
"email": "[email protected]",
"dependentChangeType": "patch"
}
5 changes: 4 additions & 1 deletion lib/msal-common/src/account/ClientCredentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
* Licensed under the MIT License.
*/

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type ClientAssertionCallbackFunction = (...args: any[]) => string;
Robbie-Microsoft marked this conversation as resolved.
Show resolved Hide resolved

/**
* Client Assertion credential for Confidential Clients
*/
export type ClientAssertion = {
assertion: string;
Robbie-Microsoft marked this conversation as resolved.
Show resolved Hide resolved
assertion: ClientAssertionCallbackFunction;
assertionType: string;
};

Expand Down
5 changes: 3 additions & 2 deletions lib/msal-common/src/client/AuthorizationCodeClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import { RequestValidator } from "../request/RequestValidator";
import { IPerformanceClient } from "../telemetry/performance/IPerformanceClient";
import { PerformanceEvents } from "../telemetry/performance/PerformanceEvent";
import { invokeAsync } from "../utils/FunctionWrappers";
import { ClientAssertion } from "../account/ClientCredentials";

/**
* Oauth2.0 Authorization Code client
Expand Down Expand Up @@ -364,9 +365,9 @@ export class AuthorizationCodeClient extends BaseClient {
}

if (this.config.clientCredentials.clientAssertion) {
const clientAssertion =
const clientAssertion: ClientAssertion =
this.config.clientCredentials.clientAssertion;
parameterBuilder.addClientAssertion(clientAssertion.assertion);
parameterBuilder.addClientAssertion(clientAssertion.assertion());
parameterBuilder.addClientAssertionType(
clientAssertion.assertionType
);
Expand Down
5 changes: 3 additions & 2 deletions lib/msal-common/src/client/RefreshTokenClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import { PerformanceEvents } from "../telemetry/performance/PerformanceEvent";
import { IPerformanceClient } from "../telemetry/performance/IPerformanceClient";
import { invoke, invokeAsync } from "../utils/FunctionWrappers";
import { generateCredentialKey } from "../cache/utils/CacheHelpers";
import { ClientAssertion } from "../account/ClientCredentials";

const DEFAULT_REFRESH_TOKEN_EXPIRATION_OFFSET_SECONDS = 300; // 5 Minutes

Expand Down Expand Up @@ -385,9 +386,9 @@ export class RefreshTokenClient extends BaseClient {
}

if (this.config.clientCredentials.clientAssertion) {
const clientAssertion =
const clientAssertion: ClientAssertion =
this.config.clientCredentials.clientAssertion;
parameterBuilder.addClientAssertion(clientAssertion.assertion);
parameterBuilder.addClientAssertion(clientAssertion.assertion());
parameterBuilder.addClientAssertionType(
clientAssertion.assertionType
);
Expand Down
5 changes: 4 additions & 1 deletion lib/msal-common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ export { NativeRequest } from "./request/NativeRequest";
export { NativeSignOutRequest } from "./request/NativeSignOutRequest";
export { RequestParameterBuilder } from "./request/RequestParameterBuilder";
export { StoreInCache } from "./request/StoreInCache";
export { ClientAssertion } from "./account/ClientCredentials";
export {
ClientAssertion,
ClientAssertionCallbackFunction,
} from "./account/ClientCredentials";
// Response
export { AzureRegion } from "./authority/AzureRegion";
export { AzureRegionConfiguration } from "./authority/AzureRegionConfiguration";
Expand Down
13 changes: 7 additions & 6 deletions lib/msal-common/test/request/RequestParameterBuilder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
ClientConfigurationErrorMessage,
createClientConfigurationError,
} from "../../src/error/ClientConfigurationError";
import { ClientAssertion } from "../../src";

describe("RequestParameterBuilder unit tests", () => {
it("constructor", () => {
Expand Down Expand Up @@ -380,13 +381,13 @@ describe("RequestParameterBuilder unit tests", () => {
});

it("adds clientAssertion and assertionType if they are passed in as strings", () => {
const clientAssertion = {
assertion: "testAssertion",
const clientAssertion: ClientAssertion = {
assertion: () => "testAssertion",
assertionType: "jwt-bearer",
};

const requestParameterBuilder = new RequestParameterBuilder();
requestParameterBuilder.addClientAssertion(clientAssertion.assertion);
requestParameterBuilder.addClientAssertion(clientAssertion.assertion());
requestParameterBuilder.addClientAssertionType(
clientAssertion.assertionType
);
Expand All @@ -408,13 +409,13 @@ describe("RequestParameterBuilder unit tests", () => {
});

it("doesn't add client assertion and client assertion type if they are empty strings", () => {
const clientAssertion = {
assertion: "",
const clientAssertion: ClientAssertion = {
assertion: () => "",
assertionType: "",
};

const requestParameterBuilder = new RequestParameterBuilder();
requestParameterBuilder.addClientAssertion(clientAssertion.assertion);
requestParameterBuilder.addClientAssertion(clientAssertion.assertion());
requestParameterBuilder.addClientAssertionType(
clientAssertion.assertionType
);
Expand Down
Loading
Loading