-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Persistent service principal token cache for MSAL confidential client #11355
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
Changes from all commits
ab170e6
5939411
9a75ef9
b9bbe33
2146503
832b145
1d525f5
a10c1cc
402109c
f224a45
e33fe44
1c100d5
b606b79
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,8 +25,6 @@ | |
| */ | ||
| @Immutable | ||
| public class ClientCertificateCredential implements TokenCredential { | ||
| private final String clientCertificate; | ||
| private final String clientCertificatePassword; | ||
| private final IdentityClient identityClient; | ||
|
|
||
| /** | ||
|
|
@@ -40,22 +38,19 @@ public class ClientCertificateCredential implements TokenCredential { | |
| ClientCertificateCredential(String tenantId, String clientId, String certificatePath, String certificatePassword, | ||
| IdentityClientOptions identityClientOptions) { | ||
| Objects.requireNonNull(certificatePath, "'certificatePath' cannot be null."); | ||
| this.clientCertificate = certificatePath; | ||
| this.clientCertificatePassword = certificatePassword; | ||
| identityClient = | ||
| new IdentityClientBuilder() | ||
| .tenantId(tenantId) | ||
| .clientId(clientId) | ||
| .identityClientOptions(identityClientOptions) | ||
| .build(); | ||
| identityClient = new IdentityClientBuilder() | ||
| .tenantId(tenantId) | ||
| .clientId(clientId) | ||
| .certificatePath(certificatePath) | ||
| .certificatePassword(certificatePassword) | ||
| .identityClientOptions(identityClientOptions) | ||
| .build(); | ||
| } | ||
|
|
||
| @Override | ||
| public Mono<AccessToken> getToken(TokenRequestContext request) { | ||
| if (clientCertificatePassword != null) { | ||
| return identityClient.authenticateWithPfxCertificate(clientCertificate, clientCertificatePassword, request); | ||
| } else { | ||
| return identityClient.authenticateWithPemCertificate(clientCertificate, request); | ||
| } | ||
| return identityClient.authenticateWithConfidentialClientCache(request) | ||
| .onErrorResume(t -> Mono.empty()) | ||
| .switchIfEmpty(Mono.defer(() -> identityClient.authenticateWithConfidentialClient(request))); | ||
jianghaolu marked this conversation as resolved.
Show resolved
Hide resolved
jianghaolu marked this conversation as resolved.
Show resolved
Hide resolved
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is Mono.defer() necessary? You can simply do
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @alzimmermsft asked the same question. if we do |
||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.