From be0f071c841d258061a73d8cb0e82a956922e1e4 Mon Sep 17 00:00:00 2001 From: Yabo Hu Date: Mon, 1 Feb 2021 15:51:20 +0800 Subject: [PATCH] upgrade common, implement getserviceclient credential, invoke listener to be cleared --- src/Accounts/Accounts/ChangeLog.md | 1 + .../Accounts/Context/ClearAzureRmContext.cs | 3 +- .../Authentication/ExternalAccessToken.cs | 6 ++-- .../Factories/AuthenticationFactory.cs | 5 +++ tools/Common.Netcore.Dependencies.targets | 32 +++++++++---------- .../MockCertificateAuthenticationFactory.cs | 5 +++ .../Mocks/MockTokenAuthenticationFactory.cs | 5 +++ 7 files changed, 37 insertions(+), 20 deletions(-) diff --git a/src/Accounts/Accounts/ChangeLog.md b/src/Accounts/Accounts/ChangeLog.md index cf24c834181b..7aaa526dcc78 100644 --- a/src/Accounts/Accounts/ChangeLog.md +++ b/src/Accounts/Accounts/ChangeLog.md @@ -18,6 +18,7 @@ - Additional information about change #1 --> ## Upcoming Release +* Invoked on clear context listener in Azure session to be cleared when `Clear-AzContext` was executed ## Version 2.2.4 * Shown correct client request id on debug message [#13745] diff --git a/src/Accounts/Accounts/Context/ClearAzureRmContext.cs b/src/Accounts/Accounts/Context/ClearAzureRmContext.cs index c2649392ed5c..dbd86538fecf 100644 --- a/src/Accounts/Accounts/Context/ClearAzureRmContext.cs +++ b/src/Accounts/Accounts/Context/ClearAzureRmContext.cs @@ -14,7 +14,6 @@ using System.IO; using System.Management.Automation; - using Microsoft.Azure.Commands.Common.Authentication; using Microsoft.Azure.Commands.Common.Authentication.Abstractions; using Microsoft.Azure.Commands.Common.Authentication.Models; @@ -86,6 +85,8 @@ void ClearContext(AzureRmProfile profile, RMProfileClient client) } } + AzureSession.Instance.RaiseContextClearedEvent(); + if (PassThru.IsPresent) { WriteObject(result); diff --git a/src/Accounts/Authentication/Authentication/ExternalAccessToken.cs b/src/Accounts/Authentication/Authentication/ExternalAccessToken.cs index 0f3d4a2a0e05..979708c6eb5b 100644 --- a/src/Accounts/Authentication/Authentication/ExternalAccessToken.cs +++ b/src/Accounts/Authentication/Authentication/ExternalAccessToken.cs @@ -32,10 +32,10 @@ public string UserId private readonly Func _refresh; - public ExternalAccessToken(string token, Func refresh = null) + public ExternalAccessToken(string accessToken, Func renew = null) { - this.AccessToken = token; - this._refresh = refresh; + this.AccessToken = accessToken; + this._refresh = renew; } public void AuthorizeRequest(Action authTokenSetter) diff --git a/src/Accounts/Authentication/Factories/AuthenticationFactory.cs b/src/Accounts/Authentication/Factories/AuthenticationFactory.cs index e774df4a738a..b7a959be731e 100644 --- a/src/Accounts/Authentication/Factories/AuthenticationFactory.cs +++ b/src/Accounts/Authentication/Factories/AuthenticationFactory.cs @@ -350,6 +350,11 @@ public ServiceClientCredentials GetServiceClientCredentials(IAzureContext contex } } + public ServiceClientCredentials GetServiceClientCredentials(string accessToken, Func renew = null) + { + return new RenewingTokenCredential(new ExternalAccessToken(accessToken, renew)); + } + /// /// Remove a user from token cache. /// diff --git a/tools/Common.Netcore.Dependencies.targets b/tools/Common.Netcore.Dependencies.targets index f5542e98e754..76a2c86e849c 100644 --- a/tools/Common.Netcore.Dependencies.targets +++ b/tools/Common.Netcore.Dependencies.targets @@ -3,21 +3,21 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + @@ -35,7 +35,7 @@ - $(NugetPackageRoot)\microsoft.azure.powershell.storage\1.3.30-preview\tools\ + $(NugetPackageRoot)\microsoft.azure.powershell.storage\1.3.31-preview\tools\ diff --git a/tools/ScenarioTest.ResourceManager/Mocks/MockCertificateAuthenticationFactory.cs b/tools/ScenarioTest.ResourceManager/Mocks/MockCertificateAuthenticationFactory.cs index a5c48f68ddf4..db57ca108dec 100644 --- a/tools/ScenarioTest.ResourceManager/Mocks/MockCertificateAuthenticationFactory.cs +++ b/tools/ScenarioTest.ResourceManager/Mocks/MockCertificateAuthenticationFactory.cs @@ -96,6 +96,11 @@ public Rest.ServiceClientCredentials GetServiceClientCredentials(IAzureContext c throw new System.NotImplementedException(); } + public Rest.ServiceClientCredentials GetServiceClientCredentials(string accessToken, Func renew = null) + { + throw new System.NotImplementedException(); + } + public void RemoveUser(IAzureAccount account, IAzureTokenCache tokenCache) { throw new NotImplementedException(); diff --git a/tools/ScenarioTest.ResourceManager/Mocks/MockTokenAuthenticationFactory.cs b/tools/ScenarioTest.ResourceManager/Mocks/MockTokenAuthenticationFactory.cs index ffbfd7e845e0..62f226986fc0 100644 --- a/tools/ScenarioTest.ResourceManager/Mocks/MockTokenAuthenticationFactory.cs +++ b/tools/ScenarioTest.ResourceManager/Mocks/MockTokenAuthenticationFactory.cs @@ -136,6 +136,11 @@ public ServiceClientCredentials GetServiceClientCredentials(IAzureContext contex return new Microsoft.Rest.TokenCredentials(Token.AccessToken); } + public Rest.ServiceClientCredentials GetServiceClientCredentials(string accessToken, Func renew = null) + { + throw new System.NotImplementedException(); + } + public void RemoveUser(IAzureAccount account, IAzureTokenCache tokenCache) { throw new NotImplementedException();