From c71bc4f11eb758e56508fb05768eb52e115633a5 Mon Sep 17 00:00:00 2001 From: Gautam Sheth Date: Fri, 5 May 2023 14:00:20 +0300 Subject: [PATCH] Fix #3089: issue with retrieving access token for specified URL. (#3091) * 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 --- CHANGELOG.md | 1 + src/Commands/Base/GetAccessToken.cs | 7 +++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f59acec3..1c8f5fcc5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 ` 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 diff --git a/src/Commands/Base/GetAccessToken.cs b/src/Commands/Base/GetAccessToken.cs index 76509cef5..bc41d4257 100644 --- a/src/Commands/Base/GetAccessToken.cs +++ b/src/Commands/Base/GetAccessToken.cs @@ -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 @@ -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)