diff --git a/src/Authentication.Abstractions/AuthenticationInfo.cs b/src/Authentication.Abstractions/AuthenticationInfo.cs new file mode 100644 index 0000000000..77b78a0709 --- /dev/null +++ b/src/Authentication.Abstractions/AuthenticationInfo.cs @@ -0,0 +1,48 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using System.Collections.Concurrent; +using System; +using System.Collections.Generic; + +namespace Microsoft.Azure.Commands.Common.Authentication.Abstractions +{ + public class AuthenticationInfo : IAuthenticationInfo + { + /// + /// Class name of the TokenCredential, stands for the authentication method + /// + public string TokenCredentialName { get; set; } + + /// + /// Authority Uri to do the authentiation + /// + public string AuthorityUri { get; set; } + + /// + /// Authentication process succeed or not. + /// + public bool AuthenticationSuccess { get; set; } = false; + + /// + /// Additional properties for AuthenticationInfo + /// + public IDictionary ExtendedProperties { get; } = new ConcurrentDictionary(StringComparer.OrdinalIgnoreCase); + + /// + /// Key to show whether token cache is enabled or not. + /// + public const string TokenCacheEnabled = "TokenCacheEnabled"; + } +} diff --git a/src/Authentication.Abstractions/Interfaces/IAuthenticationFactory.cs b/src/Authentication.Abstractions/Interfaces/IAuthenticationFactory.cs index 3b3380e354..83818d7a56 100644 --- a/src/Authentication.Abstractions/Interfaces/IAuthenticationFactory.cs +++ b/src/Authentication.Abstractions/Interfaces/IAuthenticationFactory.cs @@ -94,5 +94,10 @@ IAccessToken Authenticate( /// The account to remove credentials for /// The TokenCache to remove credentials from void RemoveUser(IAzureAccount account, IAzureTokenCache tokenCache); + + /// + /// Get the information to be recorded in Telemetry + /// + IAuthenticationInfo GetDataForTelemetry(); } } diff --git a/src/Authentication.Abstractions/Interfaces/IAuthenticationInfo.cs b/src/Authentication.Abstractions/Interfaces/IAuthenticationInfo.cs new file mode 100644 index 0000000000..a5fc7acd7a --- /dev/null +++ b/src/Authentication.Abstractions/Interfaces/IAuthenticationInfo.cs @@ -0,0 +1,34 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +namespace Microsoft.Azure.Commands.Common.Authentication.Abstractions +{ + public interface IAuthenticationInfo : IExtensibleModel + { + /// + /// Class name of the TokenCredential, stands for the authentication method + /// + string TokenCredentialName { get; set; } + + /// + /// Authority Uri to do the authentiation + /// + string AuthorityUri { get; set; } + + /// + /// Authentication process succeed or not. + /// + bool AuthenticationSuccess { get; set; } + } +} diff --git a/src/Common/AzurePSCmdlet.cs b/src/Common/AzurePSCmdlet.cs index 55a827670a..4232f33275 100644 --- a/src/Common/AzurePSCmdlet.cs +++ b/src/Common/AzurePSCmdlet.cs @@ -430,6 +430,8 @@ protected override void EndProcessing() WriteWarningMessageForVersionUpgrade(); WriteSecretsWarningMessage(); + _qosEvent.AuthInfo = AzureSession.Instance.AuthenticationFactory.GetDataForTelemetry(); + if (MetricHelper.IsCalledByUser() && SurveyHelper.GetInstance().ShouldPromptAzSurvey() && (AzureSession.Instance.TryGetComponent(nameof(IConfigManager), out var configManager) diff --git a/src/Common/MetricHelper.cs b/src/Common/MetricHelper.cs index 5b85c5043d..76c1f0e496 100644 --- a/src/Common/MetricHelper.cs +++ b/src/Common/MetricHelper.cs @@ -292,6 +292,18 @@ public void SetPSHost(PSHost host) { } + private static void PopulateAuthenticationInfoFromQos(IAuthenticationInfo info, IDictionary eventProperties) + { + eventProperties[$"auth-info-{nameof(info.TokenCredentialName).ToLower()}"] = info.TokenCredentialName; + eventProperties[$"auth-info-{nameof(info.AuthorityUri).ToLower()}"] = info.AuthorityUri; + eventProperties[$"auth-info-{nameof(info.AuthenticationSuccess).ToLower()}"] = info.AuthenticationSuccess.ToString(); + + foreach (var property in info.ExtendedProperties) + { + eventProperties[$"auth-info-{property.Key.ToLower()}"] = property.Value; + } + } + private void PopulatePropertiesFromQos(AzurePSQoSEvent qos, IDictionary eventProperties, bool populateException = false) { if (qos == null) @@ -454,6 +466,7 @@ private void PopulatePropertiesFromQos(AzurePSQoSEvent qos, IDictionary