Please can any one help me with this? I was trying to login to portal.microsoftonline.com with the credentials needed but it gets me that error. Is my URL is wrong or what? Because i am trying to impersonate and give a role to a user. Thank you and btw i am new here, please forgive me the way i post my problem. Please see the comment where the error is.
class SecurityHelpers
{
private SecurityHelpers() { }
[DllImport("advapi32.dll", SetLastError = true)]
private static extern bool LogonUser(string lpszUsername,
string lpszDomain, string lpszPassword,
int dwLogonType, int dwLogonProvider, ref IntPtr phToken);
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
private extern static bool CloseHandle(IntPtr handle);
public static WindowsIdentity CreateIdentity(
string userName, string domain, string password)
{
IntPtr tokenHandle = new IntPtr(0);
const int LOGON32_PROVIDER_DEFAULT = 0;
const int LOGON32_LOGON_NETWORK_CLEARTEXT = 3;
tokenHandle = IntPtr.Zero;
bool returnValue = LogonUser(userName, domain, password,
LOGON32_LOGON_NETWORK_CLEARTEXT,
LOGON32_PROVIDER_DEFAULT,
ref tokenHandle);
if (false == returnValue)
{
int ret = Marshal.GetLastWin32Error();
// THIS WHERE THE ERROR IS - "LogonUser failed with error code: 1326"
throw new Exception("LogonUser failed with error code: " + ret);
}
WindowsIdentity id = new WindowsIdentity(tokenHandle);
CloseHandle(tokenHandle);
return id;
}
}