private string GetUserPrincipalName(int nameFormat) { // TODO: there is discrepancy between the implementation of this method on net45 - throws if upn not found - and uap and // the rest of the platforms - returns "" uint userNameSize = 0; WindowsNativeMethods.GetUserNameEx(nameFormat, null, ref userNameSize); if (userNameSize == 0) { throw new MsalClientException( MsalError.GetUserNameFailed, MsalErrorMessage.GetUserNameFailed, new Win32Exception(Marshal.GetLastWin32Error())); } var sb = new StringBuilder((int)userNameSize); if (!WindowsNativeMethods.GetUserNameEx(nameFormat, sb, ref userNameSize)) { throw new MsalClientException( MsalError.GetUserNameFailed, MsalErrorMessage.GetUserNameFailed, new Win32Exception(Marshal.GetLastWin32Error())); } return(sb.ToString()); }
/// <summary> /// Get the user logged in to Windows or throws /// </summary> /// <returns>Upn or throws</returns> public async Task <string> GetUserPrincipalNameAsync() { // TODO: there is discrepancy between the implementation of this method on net45 - throws if upn not found - and uap and // the rest of the platforms - returns "" return(await Task.Factory.StartNew(() => { const int NameUserPrincipal = 8; uint userNameSize = 0; WindowsNativeMethods.GetUserNameEx(NameUserPrincipal, null, ref userNameSize); if (userNameSize == 0) { throw MsalExceptionFactory.GetClientException( CoreErrorCodes.GetUserNameFailed, CoreErrorMessages.GetUserNameFailed, new Win32Exception(Marshal.GetLastWin32Error())); } StringBuilder sb = new StringBuilder((int)userNameSize); if (!WindowsNativeMethods.GetUserNameEx(NameUserPrincipal, sb, ref userNameSize)) { throw MsalExceptionFactory.GetClientException( CoreErrorCodes.GetUserNameFailed, CoreErrorMessages.GetUserNameFailed, new Win32Exception(Marshal.GetLastWin32Error())); } return sb.ToString(); }).ConfigureAwait(false)); }
public override bool IsDomainJoined() { if (!IsWindows) { return(false); } bool returnValue = false; try { int result = WindowsNativeMethods.NetGetJoinInformation(null, out var pDomain, out var status); if (pDomain != IntPtr.Zero) { WindowsNativeMethods.NetApiBufferFree(pDomain); } returnValue = result == WindowsNativeMethods.ErrorSuccess && status == WindowsNativeMethods.NetJoinStatus.NetSetupDomainName; } catch (Exception ex) { Logger.WarningPii(ex); // ignore the exception as the result is already set to false; } return(returnValue); }
/// <inheritdoc /> protected override string InternalGetProcessorArchitecture() { return(IsWindows ? WindowsNativeMethods.GetProcessorArchitecture() : null); }
public string GetProcessorArchitecture() { return(IsWindows ? WindowsNativeMethods.GetProcessorArchitecture() : null); }