Skip to content
This repository was archived by the owner on Jan 19, 2021. It is now read-only.

Commit c645ec7

Browse files
committed
July 2020 Intermediate Release 1
1 parent 713d3dc commit c645ec7

File tree

5 files changed

+67
-29
lines changed

5 files changed

+67
-29
lines changed

CHANGELOG.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,16 @@ All notable changes to this project will be documented in this file.
55

66
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
77

8-
## [3.24.2008.0]
8+
## [3.24.2008.0] not yet released
9+
10+
11+
## [3.23.2007.1]
12+
13+
### Changed
14+
- Fixed issue with Remove-PnPTeamsTab not working as intended
15+
- Fixed issue with Add-PnPTeamsChannel -Private not working as intended. We now require you to specify an owner.
16+
- Fixed authentication issues when using Connect-PnPOnline and mixed Resource permissions scopes (e.g. Graph and Office 365 Management API)
17+
- Fixed issue where Disconnect-PnPOnline would not clear the in memory token cache when using Disconnect-PnPOnline
918

1019
## [3.23.2007.0]
1120

Commands/Base/DisconnectOnline.cs

+9-6
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ public class DisconnectOnline : PSCmdlet
2525
protected override void ProcessRecord()
2626
{
2727
// If no specific connection has been passed in, take the connection from the current context
28-
if(Connection == null)
28+
if (Connection == null)
2929
{
3030
Connection = PnPConnection.CurrentConnection;
3131
}
3232
#if !ONPREMISES
33-
if(Connection?.Certificate != null)
33+
if (Connection?.Certificate != null)
3434
{
3535
#if !NETSTANDARD2_1
3636
if (Connection != null && Connection.DeleteCertificateFromCacheOnDisconnect)
@@ -80,14 +80,17 @@ internal static bool DisconnectProvidedService(PnPConnection connection)
8080
{
8181
return false;
8282
}
83+
8384
GraphToken.ClearCaches();
85+
OfficeManagementApiToken.ClearCaches();
86+
8487
connection.Context = null;
8588
connection = null;
8689
return true;
8790
}
8891

8992
internal static bool DisconnectCurrentService()
90-
{
93+
{
9194
Environment.SetEnvironmentVariable("PNPPSHOST", string.Empty);
9295
Environment.SetEnvironmentVariable("PNPPSSITE", string.Empty);
9396

@@ -100,10 +103,10 @@ internal static bool DisconnectCurrentService()
100103
PnPConnection.CurrentConnection.ClearTokens();
101104
PnPConnection.CurrentConnection.Context = null;
102105
PnPConnection.CurrentConnection = null;
103-
104-
106+
107+
105108
return true;
106-
}
109+
}
107110
}
108111
}
109112
}

Commands/Base/PnPConnection.cs

-20
Original file line numberDiff line numberDiff line change
@@ -187,26 +187,6 @@ internal GenericToken TryGetToken(TokenAudience tokenAudience, string[] orRoles
187187
{
188188
GenericToken token = null;
189189

190-
//Validate if we have a token already
191-
//if (AccessTokens.ContainsKey(tokenAudience))
192-
//{
193-
// // We have a token already, ensure it is still valid
194-
// token = AccessTokens[tokenAudience];
195-
196-
// if (token.ExpiresOn > DateTime.Now)
197-
// {
198-
// var validationResults = ValidateTokenForPermissions(token, tokenAudience, orRoles, andRoles, tokenType);
199-
// if (validationResults.valid)
200-
// {
201-
// return token;
202-
// }
203-
// throw new PSSecurityException($"Access to {tokenAudience} failed because the app registration {ClientId} in tenant {Tenant} is not granted {validationResults.message}");
204-
// }
205-
206-
// // Token was no longer valid, proceed with trying to create a new token
207-
//}
208-
209-
// We do not have a token for the requested audience yet or it was no longer valid, try to create (a new) one
210190
switch (tokenAudience)
211191
{
212192
case TokenAudience.MicrosoftGraph:

Commands/Model/GraphToken.cs

+22-2
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,28 @@ public static GenericToken AcquireDelegatedTokenWithCredentials(string clientId,
273273

274274
public static void ClearCaches()
275275
{
276-
GraphToken.publicClientApplication = null;
277-
GraphToken.confidentialClientApplication = null;
276+
if (publicClientApplication != null)
277+
{
278+
var accounts = publicClientApplication.GetAccountsAsync().GetAwaiter().GetResult().ToList();
279+
280+
// clear the cache
281+
while (accounts.Any())
282+
{
283+
publicClientApplication.RemoveAsync(accounts.First());
284+
accounts = publicClientApplication.GetAccountsAsync().GetAwaiter().GetResult().ToList();
285+
}
286+
}
287+
if(confidentialClientApplication != null)
288+
{
289+
var accounts = confidentialClientApplication.GetAccountsAsync().GetAwaiter().GetResult().ToList();
290+
291+
// clear the cache
292+
while (accounts.Any())
293+
{
294+
confidentialClientApplication.RemoveAsync(accounts.First());
295+
accounts = confidentialClientApplication.GetAccountsAsync().GetAwaiter().GetResult().ToList();
296+
}
297+
}
278298
}
279299
}
280300
}

Commands/Model/OfficeManagementApiToken.cs

+26
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,32 @@ public static GenericToken AcquireDelegatedTokenWithCredentials(string clientId,
213213
}
214214
return new OfficeManagementApiToken(tokenResult.AccessToken);
215215
}
216+
217+
public static void ClearCaches()
218+
{
219+
if (publicClientApplication != null)
220+
{
221+
var accounts = publicClientApplication.GetAccountsAsync().GetAwaiter().GetResult().ToList();
222+
223+
// clear the cache
224+
while (accounts.Any())
225+
{
226+
publicClientApplication.RemoveAsync(accounts.First());
227+
accounts = publicClientApplication.GetAccountsAsync().GetAwaiter().GetResult().ToList();
228+
}
229+
}
230+
if (confidentialClientApplication != null)
231+
{
232+
var accounts = confidentialClientApplication.GetAccountsAsync().GetAwaiter().GetResult().ToList();
233+
234+
// clear the cache
235+
while (accounts.Any())
236+
{
237+
confidentialClientApplication.RemoveAsync(accounts.First());
238+
accounts = confidentialClientApplication.GetAccountsAsync().GetAwaiter().GetResult().ToList();
239+
}
240+
}
241+
}
216242
}
217243
}
218244

0 commit comments

Comments
 (0)