@@ -270,7 +270,7 @@ public async Task<IMicrosoftAuthenticationResult> GetTokenForUserAsync(
270
270
271
271
public async Task < IMicrosoftAuthenticationResult > GetTokenForServicePrincipalAsync ( ServicePrincipalIdentity sp , string [ ] scopes )
272
272
{
273
- IConfidentialClientApplication app = CreateConfidentialClientApplication ( sp ) ;
273
+ IConfidentialClientApplication app = await CreateConfidentialClientApplicationAsync ( sp ) ;
274
274
275
275
try
276
276
{
@@ -528,7 +528,7 @@ private async Task<IPublicClientApplication> CreatePublicClientApplicationAsync(
528
528
return app ;
529
529
}
530
530
531
- private IConfidentialClientApplication CreateConfidentialClientApplication ( ServicePrincipalIdentity sp )
531
+ private async Task < IConfidentialClientApplication > CreateConfidentialClientApplicationAsync ( ServicePrincipalIdentity sp )
532
532
{
533
533
var httpFactoryAdaptor = new MsalHttpClientFactoryAdaptor ( Context . HttpClientFactory ) ;
534
534
@@ -554,6 +554,8 @@ private IConfidentialClientApplication CreateConfidentialClientApplication(Servi
554
554
555
555
IConfidentialClientApplication app = appBuilder . Build ( ) ;
556
556
557
+ await RegisterTokenCacheAsync ( app . AppTokenCache , CreateAppTokenCacheProps , Context . Trace2 ) ;
558
+
557
559
return app ;
558
560
}
559
561
@@ -713,6 +715,38 @@ internal static ManagedIdentityId GetManagedIdentity(string str)
713
715
throw new ArgumentException ( "Invalid managed identity value." , nameof ( str ) ) ;
714
716
}
715
717
718
+ /// <summary>
719
+ /// Create the properties for the application token cache. This is used by confidential client applications only
720
+ /// and is not shared between applications other than GCM.
721
+ /// </summary>
722
+ internal StorageCreationProperties CreateAppTokenCacheProps ( bool useLinuxFallback )
723
+ {
724
+ const string cacheFileName = "app.cache" ;
725
+
726
+ // The confidential client MSAL cache is located at "%UserProfile%\.gcm\msal\app.cache" on Windows
727
+ // and at "~/.gcm/msal/app.cache" on UNIX.
728
+ string cacheDirectory = Path . Combine ( Context . FileSystem . UserDataDirectoryPath , "msal" ) ;
729
+
730
+ // The keychain is used on macOS with the following service & account names
731
+ var builder = new StorageCreationPropertiesBuilder ( cacheFileName , cacheDirectory )
732
+ . WithMacKeyChain ( "GitCredentialManager.MSAL" , "AppCache" ) ;
733
+
734
+ if ( useLinuxFallback )
735
+ {
736
+ builder . WithLinuxUnprotectedFile ( ) ;
737
+ }
738
+ else
739
+ {
740
+ // The SecretService/keyring is used on Linux with the following collection name and attributes
741
+ builder . WithLinuxKeyring ( cacheFileName ,
742
+ "default" , "AppCache" ,
743
+ new KeyValuePair < string , string > ( "MsalClientID" , "GitCredentialManager.MSAL" ) ,
744
+ new KeyValuePair < string , string > ( "GitCredentialManager.MSAL" , "1.0.0.0" ) ) ;
745
+ }
746
+
747
+ return builder . Build ( ) ;
748
+ }
749
+
716
750
private static EmbeddedWebViewOptions GetEmbeddedWebViewOptions ( )
717
751
{
718
752
return new EmbeddedWebViewOptions
0 commit comments