public void UnprotectedOptionMutuallyExclusiveWithOtherOptions() { var builder = new StorageCreationPropertiesBuilder( Path.GetFileName(CacheFilePath), Path.GetDirectoryName(CacheFilePath)); builder = builder.WithMacKeyChain(serviceName: "Microsoft.Developer.IdentityService", accountName: "MSALCache"); builder.WithUnprotectedFile(); AssertException.Throws <ArgumentException>(() => builder.Build()); builder = new StorageCreationPropertiesBuilder( Path.GetFileName(CacheFilePath), Path.GetDirectoryName(CacheFilePath)); builder = builder.WithLinuxKeyring( schemaName: "msal.cache", collection: "default", secretLabel: "MSALCache", attribute1: new KeyValuePair <string, string>("MsalClientID", "Microsoft.Developer.IdentityService"), attribute2: new KeyValuePair <string, string>("MsalClientVersion", "1.0.0.0")); builder.WithUnprotectedFile(); AssertException.Throws <ArgumentException>(() => builder.Build()); builder = new StorageCreationPropertiesBuilder( Path.GetFileName(CacheFilePath), Path.GetDirectoryName(CacheFilePath)); builder.WithLinuxUnprotectedFile(); builder.WithUnprotectedFile(); AssertException.Throws <ArgumentException>(() => builder.Build()); }
public void TestInitialize() { var storageBuilder = new StorageCreationPropertiesBuilder( Path.GetFileName(CacheFilePath), Path.GetDirectoryName(CacheFilePath)); storageBuilder = storageBuilder.WithMacKeyChain( serviceName: "Microsoft.Developer.IdentityService.Test", accountName: "MSALCacheTest"); // unit tests run on Linux boxes without LibSecret storageBuilder.WithLinuxUnprotectedFile(); // 1. Use MSAL to create an instance of the Public Client Application var app = PublicClientApplicationBuilder.Create(ClientId) .Build(); // 3. Create the high level MsalCacheHelper based on properties and a logger _cacheHelper = MsalCacheHelper.CreateAsync( storageBuilder.Build(), new TraceSource("MSAL.CacheExtension.Test")) .GetAwaiter().GetResult(); // 4. Let the cache helper handle MSAL's cache _cacheHelper.RegisterCache(app.UserTokenCache); }
public void TestInitialize() { _cacheFilePath = Path.Combine(Path.GetTempPath(), Path.GetTempFileName()); _storageCreationPropertiesBuilder = new StorageCreationPropertiesBuilder( Path.GetFileName(_cacheFilePath), Path.GetDirectoryName(_cacheFilePath)); _storageCreationPropertiesBuilder = _storageCreationPropertiesBuilder.WithMacKeyChain(serviceName: "Microsoft.Developer.IdentityService", accountName: "MSALCache"); _storageCreationPropertiesBuilder.WithLinuxUnprotectedFile(); }
public static void ClassInitialize(TestContext _) { var builder = new StorageCreationPropertiesBuilder(Path.GetFileName(CacheFilePath), Path.GetDirectoryName(CacheFilePath), "ClientIDGoesHere"); builder = builder.WithMacKeyChain(serviceName: "Microsoft.Developer.IdentityService", accountName: "MSALCache"); // Tests run on machines without Libsecret builder = builder.WithLinuxUnprotectedFile(); s_storageCreationProperties = builder.Build(); }
public void TestInitialize() { _storageCreationPropertiesBuilder = new StorageCreationPropertiesBuilder( Path.GetFileName(CacheFilePath), Path.GetDirectoryName(CacheFilePath), "1d18b3b0-251b-4714-a02a-9956cec86c2d"); _storageCreationPropertiesBuilder = _storageCreationPropertiesBuilder.WithMacKeyChain(serviceName: "Microsoft.Developer.IdentityService", accountName: "MSALCache"); _storageCreationPropertiesBuilder.WithLinuxUnprotectedFile(); }
public void ImportExport() { var storageBuilder = new StorageCreationPropertiesBuilder( Path.GetFileName(CacheFilePath), Path.GetDirectoryName(CacheFilePath), ClientId); storageBuilder = storageBuilder.WithMacKeyChain( serviceName: "Microsoft.Developer.IdentityService.Test", accountName: "MSALCacheTest"); // unit tests run on Linux boxes without LibSecret storageBuilder.WithLinuxUnprotectedFile(); // 1. Use MSAL to create an instance of the Public Client Application var app = PublicClientApplicationBuilder.Create(ClientId) .Build(); // 3. Create the high level MsalCacheHelper based on properties and a logger _cacheHelper = MsalCacheHelper.CreateAsync( storageBuilder.Build(), new TraceSource("MSAL.CacheExtension.Test")) .GetAwaiter().GetResult(); // 4. Let the cache helper handle MSAL's cache _cacheHelper.RegisterCache(app.UserTokenCache); // Act string dataString = "Hello World"; byte[] dataBytes = Encoding.UTF8.GetBytes(dataString); var result = _cacheHelper.LoadUnencryptedTokenCache(); Assert.AreEqual(0, result.Length); _cacheHelper.SaveUnencryptedTokenCache(dataBytes); byte[] actualData = _cacheHelper.LoadUnencryptedTokenCache(); Assert.AreEqual(dataString, Encoding.UTF8.GetString(actualData)); }
private StorageCreationProperties CreateTokenCacheProps(string clientId, bool useLinuxFallback) { const string cacheFileName = "msal.cache"; string cacheDirectory; if (PlatformUtils.IsWindows()) { // The shared MSAL cache is located at "%LocalAppData%\.IdentityService\msal.cache" on Windows. cacheDirectory = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), ".IdentityService" ); } else { // The shared MSAL cache metadata is located at "~/.local/.IdentityService/msal.cache" on UNIX. cacheDirectory = Path.Combine(Context.FileSystem.UserHomePath, ".local", ".IdentityService"); } // The keychain is used on macOS with the following service & account names var builder = new StorageCreationPropertiesBuilder(cacheFileName, cacheDirectory, clientId) .WithMacKeyChain("Microsoft.Developer.IdentityService", "MSALCache"); if (useLinuxFallback) { builder.WithLinuxUnprotectedFile(); } else { // The SecretService/keyring is used on Linux with the following collection name and attributes builder.WithLinuxKeyring(cacheFileName, "default", "MSALCache", new KeyValuePair <string, string>("MsalClientID", "Microsoft.Developer.IdentityService"), new KeyValuePair <string, string>("Microsoft.Developer.IdentityService", "1.0.0.0")); } return(builder.Build()); }