Skip to content

Commit

Permalink
Fix #3089: issue with retrieving access token for specified URL. (#3091)
Browse files Browse the repository at this point in the history
* Feature: additional params to Set-PnPTenantSite and Set-PnPSite cmdlet

* Fix #3089: issue with retrieving access token for specified resource URL

* Update CHANGELOG.md

---------

Co-authored-by: Gautam Sheth <[email protected]>
  • Loading branch information
gautamdsheth and Gautam Sheth authored May 5, 2023
1 parent 5317eac commit c71bc4f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Fixed regressions within the following cmdlets `Get-PnPTenantCdnEnabled`, `Get-PnPTenantCdnOrigin`, `Get-PnPTenantCdnPolicies`, `Get-PnPTenantDeletedSite`, `Get-PnPTenantInstance` [#3030](https://github.com/pnp/powershell/pull/3030)
- Fixed issue where `Add-PnPSiteCollectionAdmin -PrimarySiteCollectionAdmin <user>` would require owners to be specified as well. [#3035](https://github.com/pnp/powershell/pull/3035)
- Fixed `Get-PnPAzureADGroup` returns only 100 results even if there are more groups present in Azure AD. [#3085](https://github.com/pnp/powershell/pull/3085)
- Fixed `Get-PnPAccessToken` cmdlet to correctly retrieve the access token for the specified resource URL. [#3091](https://github.com/pnp/powershell/pull/3091)

### Changed

Expand Down
7 changes: 3 additions & 4 deletions src/Commands/Base/GetAccessToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
namespace PnP.PowerShell.Commands.Base
{
[Cmdlet(VerbsCommon.Get, "PnPAccessToken", DefaultParameterSetName = ResourceTypeParam)]
[RequiredMinimalApiPermissions("https://graph.microsoft.com/.default")]
[OutputType(typeof(System.IdentityModel.Tokens.Jwt.JwtSecurityToken), ParameterSetName = new[] { ResourceTypeParam_Decoded, ResourceUrlParam_Decoded })]
[OutputType(typeof(string), ParameterSetName = new[] { ResourceTypeParam, ResourceUrlParam })]
public class GetPnPAccessToken : PnPGraphCmdlet
Expand Down Expand Up @@ -46,16 +45,16 @@ protected override void ExecuteCmdlet()
throw new PSArgumentException("No connection found, please login first.");
}
var rootUrl = new Uri(currentUrl).GetLeftPart(UriPartial.Authority);
accessTokenValue = TokenHandler.GetAccessToken(null, rootUrl + "/.default", Connection);
accessTokenValue = TokenHandler.GetAccessToken(this, rootUrl + "/.default", Connection);
break;
case ResourceTypeName.ARM:
accessTokenValue = TokenHandler.GetAccessToken(null, "https://management.azure.com/.default", Connection);
accessTokenValue = TokenHandler.GetAccessToken(this, "https://management.azure.com/.default", Connection);
break;
}
}
else if (ParameterSetName == ResourceUrlParam || ParameterSetName == ResourceUrlParam_Decoded)
{
accessTokenValue = TokenHandler.GetAccessToken(null, ResourceUrl, Connection);
accessTokenValue = TokenHandler.GetAccessToken(this, ResourceUrl, Connection);
}

if (accessTokenValue == null)
Expand Down

0 comments on commit c71bc4f

Please sign in to comment.