Microsoft.SharePoint.Client.IdcrlException: 'The sign-in name or password---' Even WITH Pnp Authentication Manager

Viewed 6271

I have signed up for the Office 365 Developer Edition with Microsoft 365 E5 Developer (without Windows and Audio Conferencing). I am writing codes to connect to the Sharepoint of developer domain. Following are my codes:

   public static String GetList( ICredentials credentials)
    {
        var authManager = new OfficeDevPnP.Core.AuthenticationManager();
        using (ClientContext clientContext = 
        authManager.GetWebLoginClientContext("https://xxx.sharepoint.com"))
        {
            clientContext.Credentials = credentials;

            Web web = clientContext.Web;
            clientContext.Load(web,
            webSite => webSite.Title);

            clientContext.ExecuteQuery();
            return web.Title;


        }
    }


    public string callSharepoint()
    {


        const string userName = "Username@domain.onmicrosoft.com";  
        const string password = "xxxx";
        var securePassword = new SecureString();
        foreach (var c in password)
        {
            securePassword.AppendChar(c);
        }
        var credentials = new SharePointOnlineCredentials(userName, securePassword);

        var list = GetList(credentials); 
        return list.ToString();
    }

While running, it first asks to enter Microsoft Office credentials, and then it does verification by sending code to contact number and then after verification is completed it throws an Exception on Line clientContext.ExecuteQuery(). The Exception is as follow:

Microsoft.SharePoint.Client.IdcrlException: 'The sign-in name or password does not match one in the Microsoft account system.'

The credentials I am using is of Admin Account with role Global Administrator. I also tried to add new user account in that Active Directory and tried that credentials but still got the same exception on the same place. I even try to remove Pnp Authorization, Enable and disable Multi factor Authorization, but no success. However, I can successfully log in into the Sharepoint site on browser by using exactly same credentials.

What I think is, there is most likely a problem in the setup which I did while setting office account developer subscription. And maybe nothing is wrong with the code because I used the same codes to log in to my organization's Sharepoint and it works perfectly fine. Maybe I need something else to be configured in my developer's Office Account.

Please let me know if anyone already has some knowledge about this problem.

2 Answers

You have init the credential so you could use it directly, if issue exists, should be related to your user account or license.

public static String GetList(ICredentials credentials)
        {
            //var authManager = new OfficeDevPnP.Core.AuthenticationManager();
            //using (ClientContext clientContext =
            //authManager.GetWebLoginClientContext("https://xxx.sharepoint.com/sites/lee"))
            //{

            //}

            using (ClientContext clientContext = new ClientContext("https://xxx.sharepoint.com/sites/lee"))
            {
                clientContext.Credentials = credentials;

                Web web = clientContext.Web;
                clientContext.Load(web,
                webSite => webSite.Title);

                clientContext.ExecuteQuery();
                return web.Title;
            }
        }


        public string callSharepoint()
        {


            const string userName = "user@xxx.onmicrosoft.com";
            const string password = "password";
            var securePassword = new SecureString();
            foreach (var c in password)
            {
                securePassword.AppendChar(c);
            }
            var credentials = new SharePointOnlineCredentials(userName, securePassword);

            var list = GetList(credentials);
            return list.ToString();
        }

Ok I found the solution. That is I don't need this line of code:

     clientContext.Credentials = credentials;

Since MFA is enabled, so when I logged in via Pnp Authenticator, it should use that user account. Instead of the one which is passed via SharePointOnlineCredentials.

Related