Exemple #1
0
        private string GetUserPrincipalName(int nameFormat)
        {
            if (IsWindowsPlatform())
            {
                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());
            }

            throw new PlatformNotSupportedException(
                      "MSAL cannot determine the username (UPN) of the currently logged in user." +
                      "For Integrated Windows Authentication and Username/Password flows, please use .WithUsername() before calling ExecuteAsync(). " +
                      "For more details see https://aka.ms/msal-net-iwa");
        }
Exemple #2
0
 protected override string InternalGetProcessorArchitecture()
 {
     return(DesktopOsHelper.IsWindows() ? WindowsNativeMethods.GetProcessorArchitecture() : null);
 }