private async Task RegisterTokenCacheAsync(IPublicClientApplication app) { Context.Trace.WriteLine( "Configuring Microsoft Authentication token cache to instance shared with Microsoft developer tools..."); if (!PlatformUtils.IsWindows() && !PlatformUtils.IsPosix()) { string osType = PlatformUtils.GetPlatformInformation().OperatingSystemType; Context.Trace.WriteLine($"Token cache integration is not supported on {osType}."); return; } // We use the MSAL extension library to provide us consistent cache file access semantics (synchronisation, etc) // as other Microsoft developer tools such as the Azure PowerShell CLI. MsalCacheHelper helper = null; try { var storageProps = CreateTokenCacheProps(useLinuxFallback: false); helper = await MsalCacheHelper.CreateAsync(storageProps); // Test that cache access is working correctly helper.VerifyPersistence(); } catch (MsalCachePersistenceException ex) { Context.Streams.Error.WriteLine("warning: cannot persist Microsoft authentication token cache securely!"); Context.Trace.WriteLine("Cannot persist Microsoft Authentication data securely!"); Context.Trace.WriteException(ex); if (PlatformUtils.IsMacOS()) { // On macOS sometimes the Keychain returns the "errSecAuthFailed" error - we don't know why // but it appears to be something to do with not being able to access the keychain. // Locking and unlocking (or restarting) often fixes this. Context.Streams.Error.WriteLine( "warning: there is a problem accessing the login Keychain - either manually lock and unlock the " + "login Keychain, or restart the computer to remedy this"); } else if (PlatformUtils.IsLinux()) { // On Linux the SecretService/keyring might not be available so we must fall-back to a plaintext file. Context.Streams.Error.WriteLine("warning: using plain-text fallback token cache"); Context.Trace.WriteLine("Using fall-back plaintext token cache on Linux."); var storageProps = CreateTokenCacheProps(useLinuxFallback: true); helper = await MsalCacheHelper.CreateAsync(storageProps); } } if (helper is null) { Context.Streams.Error.WriteLine("error: failed to set up Microsoft Authentication token cache!"); Context.Trace.WriteLine("Failed to integrate with shared token cache!"); } else { helper.RegisterCache(app.UserTokenCache); Context.Trace.WriteLine("Microsoft developer tools token cache configured."); } }
private void OpenDefaultBrowser(Uri uri) { if (!uri.Scheme.Equals(Uri.UriSchemeHttp, StringComparison.OrdinalIgnoreCase) && !uri.Scheme.Equals(Uri.UriSchemeHttps, StringComparison.OrdinalIgnoreCase)) { throw new ArgumentException("Can only open HTTP/HTTPS URIs", nameof(uri)); } string url = uri.ToString(); ProcessStartInfo psi = null; if (PlatformUtils.IsLinux()) { // On Linux, 'shell execute' utilities like xdg-open launch a process without // detaching from the standard in/out descriptors. Some applications (like // Chromium) write messages to stdout, which is currently hooked up and being // consumed by Git, and cause errors. // // Sadly, the Framework does not allow us to redirect standard streams if we // set ProcessStartInfo::UseShellExecute = true, so we must manually launch // these utilities and redirect the standard streams manually. // // We try and use the same 'shell execute' utilities as the Framework does, // searching for them in the same order until we find one. foreach (string shellExec in new[] { "xdg-open", "gnome-open", "kfmclient" }) { if (_environment.TryLocateExecutable(shellExec, out string shellExecPath)) { psi = new ProcessStartInfo(shellExecPath, url) { RedirectStandardOutput = true, RedirectStandardError = true }; // We found a way to open the URI; stop searching! break; } } if (psi is null) { throw new Exception("Failed to locate a utility to launch the default web browser."); } } else { // On Windows and macOS, `ShellExecute` and `/usr/bin/open` disconnect the child process // from our standard in/out streams, so we can just use the Framework to do this. psi = new ProcessStartInfo(url) { UseShellExecute = true }; } Process.Start(psi); }
private async Task RegisterTokenCacheAsync(IPublicClientApplication app) { Context.Trace.WriteLine( "Configuring Microsoft Authentication token cache to instance shared with Microsoft developer tools..."); if (!PlatformUtils.IsWindows() && !PlatformUtils.IsPosix()) { string osType = PlatformUtils.GetPlatformInformation().OperatingSystemType; Context.Trace.WriteLine($"Token cache integration is not supported on {osType}."); return; } string clientId = app.AppConfig.ClientId; // We use the MSAL extension library to provide us consistent cache file access semantics (synchronisation, etc) // as other Microsoft developer tools such as the Azure PowerShell CLI. MsalCacheHelper helper = null; try { var storageProps = CreateTokenCacheProps(clientId, useLinuxFallback: false); helper = await MsalCacheHelper.CreateAsync(storageProps); // Test that cache access is working correctly helper.VerifyPersistence(); } catch (MsalCachePersistenceException ex) { Context.Streams.Error.WriteLine("warning: cannot persist Microsoft Authentication data securely!"); Context.Trace.WriteLine("Cannot persist Microsoft Authentication data securely!"); Context.Trace.WriteException(ex); // On Linux the SecretService/keyring might not be available so we must fall-back to a plaintext file. if (PlatformUtils.IsLinux()) { Context.Trace.WriteLine("Using fall-back plaintext token cache on Linux."); var storageProps = CreateTokenCacheProps(clientId, useLinuxFallback: true); helper = await MsalCacheHelper.CreateAsync(storageProps); } } if (helper is null) { Context.Streams.Error.WriteLine("error: failed to set up Microsoft Authentication token cache!"); Context.Trace.WriteLine("Failed to integrate with shared token cache!"); } else { helper.RegisterCache(app.UserTokenCache); Context.Trace.WriteLine("Microsoft developer tools token cache configured."); } }
static TizenSDKUtilities() { if (PlatformUtils.IsLinux()) { SDKDirectory = new NPath(NPath.HomeDirectory + "/tizen-2.4.0-linux"); } else { if (!PlatformUtils.IsOSX()) { throw new NotSupportedException("Building Tizen on Windows is not supported."); } SDKDirectory = new NPath(NPath.HomeDirectory + "/tizen-2.4.0-macosx"); } }
public TestEnvironment(IFileSystem fileSystem = null, string envPathSeparator = null, IEqualityComparer <string> pathComparer = null, IEqualityComparer <string> envarComparer = null) { _fileSystem = fileSystem ?? new TestFileSystem(); // Use the current platform separators and comparison types by default _envPathSeparator = envPathSeparator ?? (PlatformUtils.IsWindows() ? ";" : ":"); _envarComparer = envarComparer ?? (PlatformUtils.IsWindows() ? StringComparer.OrdinalIgnoreCase : StringComparer.Ordinal); _pathComparer = pathComparer ?? (PlatformUtils.IsLinux() ? StringComparer.Ordinal : StringComparer.OrdinalIgnoreCase); Variables = new Dictionary <string, string>(_envarComparer); Symlinks = new Dictionary <string, string>(_pathComparer); }
public override bool CanBuildInCurrentEnvironment() => PlatformUtils.IsLinux();
protected override async Task <bool> RunInternalAsync(StringBuilder log, IList <string> additionalFiles) { if (MicrosoftAuthentication.CanUseBroker(_context)) { log.Append("Checking broker initialization state..."); if (MicrosoftAuthentication.IsBrokerInitialized) { log.AppendLine(" Initialized"); } else { log.AppendLine(" Not initialized"); log.Append("Initializing broker..."); MicrosoftAuthentication.InitializeBroker(); log.AppendLine("OK"); } } else { log.AppendLine("Broker not supported."); } var msAuth = new MicrosoftAuthentication(_context); log.AppendLine($"Flow type is: {msAuth.GetFlowType()}"); log.Append("Gathering MSAL token cache data..."); StorageCreationProperties cacheProps = msAuth.CreateTokenCacheProps(true); log.AppendLine(" OK"); log.AppendLine($"CacheDirectory: {cacheProps.CacheDirectory}"); log.AppendLine($"CacheFileName: {cacheProps.CacheFileName}"); log.AppendLine($"CacheFilePath: {cacheProps.CacheFilePath}"); if (PlatformUtils.IsMacOS()) { log.AppendLine($"MacKeyChainAccountName: {cacheProps.MacKeyChainAccountName}"); log.AppendLine($"MacKeyChainServiceName: {cacheProps.MacKeyChainServiceName}"); } else if (PlatformUtils.IsLinux()) { log.AppendLine($"KeyringCollection: {cacheProps.KeyringCollection}"); log.AppendLine($"KeyringSchemaName: {cacheProps.KeyringSchemaName}"); log.AppendLine($"KeyringSecretLabel: {cacheProps.KeyringSecretLabel}"); log.AppendLine($"KeyringAttribute1: ({cacheProps.KeyringAttribute1.Key},{cacheProps.KeyringAttribute1.Value})"); log.AppendLine($"KeyringAttribute2: ({cacheProps.KeyringAttribute2.Key},{cacheProps.KeyringAttribute2.Value})"); } log.Append("Creating cache helper..."); var cacheHelper = await MsalCacheHelper.CreateAsync(cacheProps); log.AppendLine(" OK"); try { log.Append("Verifying MSAL token cache persistence..."); cacheHelper.VerifyPersistence(); log.AppendLine(" OK"); } catch (Exception) { log.AppendLine(" Failed"); throw; } return(true); }