public virtual CredentialViewModel DescribeCredential(Credential credential) { var kind = GetCredentialKind(credential.Type); Authenticator authenticator = null; if (kind == CredentialKind.External) { if (string.IsNullOrEmpty(credential.TenantId)) { string providerName = credential.Type.Split('.')[1]; Authenticators.TryGetValue(providerName, out authenticator); } else { authenticator = Authenticators .Values .FirstOrDefault(provider => provider.Name.Equals(AzureActiveDirectoryV2Authenticator.DefaultAuthenticationType, StringComparison.OrdinalIgnoreCase)); } } var credentialViewModel = new CredentialViewModel { Key = credential.Key, Type = credential.Type, TypeCaption = FormatCredentialType(credential.Type), Identity = credential.Identity, Created = credential.Created, Expires = credential.Expires, Kind = kind, AuthUI = authenticator?.GetUI(), // Set the description as the value for legacy API keys Description = credential.Description, Value = kind == CredentialKind.Token && credential.Description == null ? credential.Value : null, Scopes = credential.Scopes.Select(s => new ScopeViewModel( s.Owner?.Username ?? credential.User.Username, s.Subject, NuGetScopes.Describe(s.AllowedAction))) .ToList(), ExpirationDuration = credential.ExpirationTicks != null ? new TimeSpan?(new TimeSpan(credential.ExpirationTicks.Value)) : null }; credentialViewModel.HasExpired = credential.HasExpired || (credentialViewModel.IsNonScopedApiKey && !credential.HasBeenUsedInLastDays(_config.ExpirationInDaysForApiKeyV1)); credentialViewModel.Description = credentialViewModel.IsNonScopedApiKey ? Strings.NonScopedApiKeyDescription : credentialViewModel.Description; return(credentialViewModel); }
public virtual CredentialViewModel DescribeCredential(Credential credential) { var kind = GetCredentialKind(credential.Type); Authenticator authenticator = null; if (kind == CredentialKind.External) { if (string.IsNullOrEmpty(credential.TenantId)) { string providerName = credential.Type.Split('.')[1]; Authenticators.TryGetValue(providerName, out authenticator); } else { authenticator = Authenticators .Values .FirstOrDefault(provider => provider.Name.Equals(AzureActiveDirectoryV2Authenticator.DefaultAuthenticationType, StringComparison.OrdinalIgnoreCase)); } } var credentialViewModel = new CredentialViewModel { Key = credential.Key, Type = credential.Type, TypeCaption = FormatCredentialType(credential.Type), Identity = credential.Identity, Created = credential.Created, Expires = credential.Expires, Kind = kind, AuthUI = authenticator?.GetUI(), Description = credential.Description, Scopes = credential.Scopes.Select(s => new ScopeViewModel( s.Owner?.Username ?? credential.User.Username, s.Subject, NuGetScopes.Describe(s.AllowedAction))) .ToList(), ExpirationDuration = credential.ExpirationTicks != null ? new TimeSpan?(new TimeSpan(credential.ExpirationTicks.Value)) : null, RevocationSource = credential.RevocationSourceKey != null?Enum.GetName(typeof(CredentialRevocationSource), credential.RevocationSourceKey) : null, }; credentialViewModel.HasExpired = IsCredentialExpiredOrNonScopedApiKeyNotUsedInLastDays(credential); credentialViewModel.Description = credentialViewModel.IsNonScopedApiKey ? ServicesStrings.NonScopedApiKeyDescription : credentialViewModel.Description; return(credentialViewModel); }
public virtual CredentialViewModel DescribeCredential(Credential credential) { var kind = GetCredentialKind(credential.Type); Authenticator auther = null; if (kind == CredentialKind.External) { string providerName = credential.Type.Split('.')[1]; Authenticators.TryGetValue(providerName, out auther); } var credentialViewModel = new CredentialViewModel { Key = credential.Key, Type = credential.Type, TypeCaption = FormatCredentialType(credential.Type), Identity = credential.Identity, Created = credential.Created, Expires = credential.Expires, Kind = kind, AuthUI = auther?.GetUI(), // Set the description as the value for legacy API keys Description = credential.Description, Value = kind == CredentialKind.Token && credential.Description == null ? credential.Value : null, Scopes = credential.Scopes.Select(s => new ScopeViewModel(s.Subject, NuGetScopes.Describe(s.AllowedAction))).ToList(), ExpirationDuration = credential.ExpirationTicks != null ? new TimeSpan?(new TimeSpan(credential.ExpirationTicks.Value)) : null }; credentialViewModel.HasExpired = credential.HasExpired || (credentialViewModel.IsNonScopedV1ApiKey && !credential.HasBeenUsedInLastDays(_config.ExpirationInDaysForApiKeyV1)); credentialViewModel.Description = credentialViewModel.IsNonScopedV1ApiKey ? Strings.NonScopedApiKeyDescription : credentialViewModel.Description; return(credentialViewModel); }