-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Client Assertion implementation now accepts an async callback as well…
… as a string argument (#7014) Client assertion can currently be provided by a developer as a string. This PR allows a developer to provide an async callback (which will resolve to a string) as the client assertion. The client assertion initialization has been removed from ConfidentialClient's constructor and is now initialized inside of buildOauthClientConfiguration, called during every acquireToken call. Note: Applied Boy-Scout-Rule on UsernamePasswordClient.spec.ts. Only the last test in the file is relevant for this review. Now this test file is up-to-date and mirrors ClientCredentialsClient.spec.ts and OnBehalfOfClient.spec.ts.
- Loading branch information
1 parent
37633b4
commit e6d18c5
Showing
24 changed files
with
843 additions
and
467 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@azure-msal-common-d9223c68-d959-4da8-8a74-caa4f751c48a.json
This file contains 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": "Client Assertion Implementation now accepts a callback instead of a string argument", | ||
"packageName": "@azure/msal-common", | ||
"email": "[email protected]", | ||
"dependentChangeType": "patch" | ||
} |
7 changes: 7 additions & 0 deletions
7
change/@azure-msal-node-93a9e21c-c628-4ae1-ad55-2e1217792f32.json
This file contains 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": "Client Assertion Implementation now accepts a callback instead of a string argument", | ||
"packageName": "@azure/msal-node", | ||
"email": "[email protected]", | ||
"dependentChangeType": "patch" | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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,25 @@ | ||
/* | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. | ||
*/ | ||
|
||
import { | ||
ClientAssertionCallback, | ||
ClientAssertionConfig, | ||
} from "../account/ClientCredentials"; | ||
|
||
export async function getClientAssertion( | ||
clientAssertion: string | ClientAssertionCallback, | ||
clientId: string, | ||
tokenEndpoint?: string | ||
): Promise<string> { | ||
if (typeof clientAssertion === "string") { | ||
return clientAssertion; | ||
} else { | ||
const config: ClientAssertionConfig = { | ||
clientId: clientId, | ||
tokenEndpoint: tokenEndpoint, | ||
}; | ||
return clientAssertion(config); | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
|
@@ -33,6 +33,9 @@ import { | |
createClientAuthError, | ||
ClientAuthErrorCodes, | ||
buildStaticAuthorityOptions, | ||
ClientAssertion as ClientAssertionType, | ||
getClientAssertion, | ||
ClientAssertionCallback, | ||
} from "@azure/msal-common"; | ||
import { | ||
Configuration, | ||
|
@@ -77,6 +80,9 @@ export abstract class ClientApplication { | |
* Client assertion passed by the user for confidential client flows | ||
*/ | ||
protected clientAssertion: ClientAssertion; | ||
protected developerProvidedClientAssertion: | ||
| string | ||
| ClientAssertionCallback; | ||
/** | ||
* Client secret passed by the user for confidential client flows | ||
*/ | ||
|
@@ -451,8 +457,8 @@ export abstract class ClientApplication { | |
serverTelemetryManager: serverTelemetryManager, | ||
clientCredentials: { | ||
clientSecret: this.clientSecret, | ||
clientAssertion: this.clientAssertion | ||
? this.getClientAssertion(discoveredAuthority) | ||
clientAssertion: this.developerProvidedClientAssertion | ||
? await this.getClientAssertion(discoveredAuthority) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
Robbie-Microsoft
Author
Collaborator
|
||
: undefined, | ||
}, | ||
libraryInfo: { | ||
|
@@ -469,10 +475,17 @@ export abstract class ClientApplication { | |
return clientConfiguration; | ||
} | ||
|
||
private getClientAssertion(authority: Authority): { | ||
assertion: string; | ||
assertionType: string; | ||
} { | ||
private async getClientAssertion( | ||
authority: Authority | ||
): Promise<ClientAssertionType> { | ||
this.clientAssertion = ClientAssertion.fromAssertion( | ||
await getClientAssertion( | ||
this.developerProvidedClientAssertion, | ||
this.config.auth.clientId, | ||
authority.tokenEndpoint | ||
) | ||
); | ||
|
||
return { | ||
assertion: this.clientAssertion.getJwt( | ||
this.cryptoProvider, | ||
|
Oops, something went wrong.
@Robbie-Microsoft
I'm thinking that this change may be related to the problem in #7082 . The certificate is translated into a client assertion (in msal-node\src\client\ConfidentialClientApplication.ts in the setClientCredential method:
this.clientAssertion = ClientAssertion.fromCertificate( certificate.thumbprint, certificate.privateKey, configuration.auth.clientCertificate?.x5c );
With the change to developerProvidedClientAssertion, I am thinking the clientAssertion is no longer included in the configuration. The changes to the getClientAssertion method overwrite the clientAssertion property so that method may also need to address the existence of a clientAssertion for the certificate