Microsoft 365 : PowerShell – Connect-PnPOnline – resolving error – AADSTS50126: Error validating credentials due to invalid username or passwordMicrosoft – even though user name and password are correct

fig : Microsoft 365 - Connect-PnPOnline - exception while connecting to site, this exception is because MFA is enabled for the current user
fig : Microsoft 365 - Connect-PnPOnline - exception while connecting to site, this exception is because MFA is enabled for the current user

Hi All,

Greetings for the day!!! Today new issue and solution !!!

Use Case / Background

  • We need to connect one of our SharePoint site in our tenant
  • Though we can use Connect-SPOService and Get-SPOSite but we are using PnP CMDLETs since for further operations its easy with PnP Online
  • So we are using Connect-PnPOnline CMDLET to connect to our SiteCollections
  • We are connecting with our UserName and Password
  • While connecting to our SharePoint site with Connect-PnPOnline CMDLET with correct user name and password but then we are getting an error – error validating credentials

Connect-PnPOnline -Url https://knowledgejunction1.sharepoint.com/demoremoveuserpermissions 

  • The above CMDLET prompt for user name and password and we were sure that we entered correct user name and password

Issue / Error :

Connect-PnPOnline : AADSTS50126: Error validating credentials due to invalid username or password.
Trace ID: b49df603-9ccc-4d49-be1e-803b51431501
Correlation ID: d714ca32-14c9-4a90-9c4f-51a2e4312ebb
Timestamp: 2023-04-02 23:59:51Z
At line:1 char:1

  • Connect-PnPOnline
  • ~~~~~
    • CategoryInfo : NotSpecified: (:) [Connect-PnPOnline], MsalUiRequiredException
    • FullyQualifiedErrorId : Microsoft.Identity.Client.MsalUiRequiredException,PnP.PowerShell.Commands.Base.ConnectOnline
fig : Microsoft 365 - Connect-PnPOnline - exception while connecting to site, this exception is because MFA is enabled for the current user
fig : Microsoft 365 – Connect-PnPOnline – exception while connecting to site, this exception is because MFA is enabled for the current user

Cause / Why such issue

  • This is the error because we are connecting the site with user which has “multi-factor authentication” enabled
  • So when we have multi-factor authentication is in place for users and we try to do normal connection we get an issue / error

Solution

  • To avoid this error we can connect with either of following two parameters
    • UseWebLogin
      • With this parameter we connect to SharePoint site using cookie based legacy authentication
      • With this type authentication we are limited to few functionality
      • We can not use GRAPH APIs with this type of authentication
      • Also few functionality related to provisioning templates like – Get-PnPSiteTemplate, Get-PnPTenantTemplate, Invoke-PnPSiteTemplate, Invoke-PnPTenantTemplate can not be used
    • Interactive
      • With this parameter we connect to SharePoint site and can use GRPAH APIs as well
      • Basically it connects to Azure AD and acquires access token
Connect-PnPOnline -UseWebLogin -Url 

Connect-PnPOnline -Interactive -Url
fig : Microsoft 365 - Connect-PnPOnline using -UseWebLogin or -Interactive parameter
fig : Microsoft 365 – Connect-PnPOnline using -UseWebLogin or -Interactive parameter

We have very good articles on Connect-PnPOnline, have a look once

References

Prasham Sabadra

LIFE IS VERY BEAUTIFUL :) ENJOY THE WHOLE JOURNEY :) Founder of Knowledge Junction and live-beautiful-life.com, Author, Learner, Passionate Techie, avid reader. Certified Professional Workshop Facilitator / Public Speaker. Scrum Foundation Professional certificated. Motivational, Behavioral , Technical speaker. Speaks in various events including SharePoint Saturdays, Boot camps, Collages / Schools, local chapter. Can reach me for Microsoft 365, Azure, DevOps, SharePoint, Teams, Power Platform, JavaScript.

You may also like...

2 Responses

  1. April 13, 2023

    […] We have one more another article – connecting Microsoft 365 tenant using PnP PowerShell when MFA is enabled – Microsoft 365 : PowerShell – Connect-PnPOnline – resolving error – AADSTS50126: Error validating credentials due to invalid username or password Microsoft – even though user name and password are correct – https://knowledge-junction.in/2023/04/03/microsoft-365-powershell-connect-pnponline-resolving-error-… […]

  2. April 19, 2023

    […] Microsoft 365 : PowerShell – Connect-PnPOnline – resolving error – AADSTS50126: Error validating credentials due to invalid username or password – even though user name and password are correct – https://knowledge-junction.in/2023/04/03/microsoft-365-powershell-connect-pnponline-resolving-error-… […]

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: