Skip to content

Add tenantId if not specified by fetching it from URL #4998

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion documentation/Connect-PnPOnline.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Connect-PnPOnline [-ReturnConnection] [-Url] <String> [-CreateDrive] [-DriveName

### DeviceLogin
```powershell
Connect-PnPOnline [-ReturnConnection] [-Url] <String> [-PersistLogin] [-CreateDrive] [-DriveName <String>] [-DeviceLogin]
Connect-PnPOnline [-ReturnConnection] [-Url] <String> [-PersistLogin] [-CreateDrive] [-DriveName <String>] [-DeviceLogin] -Tenant <String>
[-ClientId <String>] [-AzureEnvironment <AzureEnvironment>]
[-ValidateConnection] [-MicrosoftGraphEndPoint <string>]
[-AzureADLoginEndPoint <string>] [-Connection <PnPConnection>]
Expand Down
2 changes: 1 addition & 1 deletion pages/articles/authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ In some scenarios it can happen that you need to authenticate to PnP PowerShell
Connecting can be done using:

```powershell
Connect-PnPOnline [yourtenant].sharepoint.com -DeviceLogin -Tenant <tenant>.onmicrosoft.com -ClientId <client id of your Entra ID Application Registration>
Connect-PnPOnline [yourtenant].sharepoint.com -DeviceLogin -ClientId <client id of your Entra ID Application Registration>
```

When running this line, it will prompt in text to go to https://microsoft.com/devicelogin on any device and log in using a specific code which will be shown in the text. You can perform this step on any device. This does not have to be the same device as you're using PnP PowerShell on. After going to that website and entering the code shown in the text, you can complete the interactive login process as normal, including any multi factor authentication requirements that might have been set up for your account. Once the authentication completes, PnP PowerShell will automatically detect this and will be ready to be used.
Expand Down
4 changes: 4 additions & 0 deletions src/Commands/Base/ConnectOnline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,10 @@ private PnPConnection ConnectDeviceLogin()
messageWriter.LogDebug("Using Managed AppId from secure store");
}
}
if (string.IsNullOrWhiteSpace(Tenant))
{
Tenant = TenantExtensions.GetTenantIdByUrl(Url, AzureEnvironment);
}

var returnedConnection = PnPConnection.CreateWithDeviceLogin(clientId, Url, Tenant, messageWriter, AzureEnvironment, cancellationTokenSource, PersistLogin, Host);
connection = returnedConnection;
Expand Down
Loading