Skip to content

Commit

Permalink
Fixes get accesstoken on different site
Browse files Browse the repository at this point in the history
  • Loading branch information
milanholemans authored and gautamdsheth committed Aug 23, 2022
1 parent 04bcfc0 commit 92ae6eb
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/Commands/Base/GetAccessToken.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Management.Automation;
using PnP.PowerShell.Commands.Attributes;
using PnP.PowerShell.Commands.Attributes;
using PnP.PowerShell.Commands.Enums;
using System;
using System.Management.Automation;

namespace PnP.PowerShell.Commands.Base
{
Expand Down Expand Up @@ -43,7 +44,13 @@ protected override void ExecuteCmdlet()
accessTokenValue = AccessToken;
break;
case ResourceTypeName.SharePoint:
accessTokenValue = TokenHandler.GetAccessToken(null, Connection?.Context?.Url?.TrimEnd('/') + "/.default", Connection);
var currentUrl = Connection?.Context?.Url?.TrimEnd('/');
if (string.IsNullOrEmpty(currentUrl))
{
throw new PSArgumentException("No connection found, please login first.");
}
var rootUrl = new Uri(currentUrl).GetLeftPart(UriPartial.Authority);
accessTokenValue = TokenHandler.GetAccessToken(null, rootUrl + "/.default", Connection);
break;
case ResourceTypeName.ARM:
accessTokenValue = TokenHandler.GetAccessToken(null, "https://management.azure.com/.default", Connection);
Expand Down

0 comments on commit 92ae6eb

Please sign in to comment.