private Tuple<IAccessToken, string> GetToken(IAuthenticationFactory authFactory, AzureContext context)
        {
            if (context.Subscription == null)
                throw new ArgumentException(KeyVaultProperties.Resources.InvalidCurrentSubscription);
            if (context.Account == null)
                throw new ArgumentException(KeyVaultProperties.Resources.InvalidSubscriptionState);
            if (context.Account.Type != AzureAccount.AccountType.User)
                throw new ArgumentException(string.Format(KeyVaultProperties.Resources.UnsupportedAccountType, context.Account.Type));
            var tenant = context.Subscription.GetPropertyAsArray(AzureSubscription.Property.Tenants)
                  .Intersect(context.Account.GetPropertyAsArray(AzureAccount.Property.Tenants))
                  .FirstOrDefault();
            if (tenant == null)
                throw new ArgumentException(KeyVaultProperties.Resources.InvalidSubscriptionState);
          
            try
            {
                var accesstoken = authFactory.Authenticate(context.Account, context.Environment, tenant, null, ShowDialog.Auto,
                    ResourceIdEndpoint);

                return Tuple.Create(accesstoken, context.Environment.Endpoints[ResourceIdEndpoint]);
            }
            catch (Exception ex)
            {
                throw new ArgumentException(KeyVaultProperties.Resources.InvalidSubscriptionState, ex);
            }        
        }
        public KeyVaultDataServiceClient(IAuthenticationFactory authFactory, AzureContext context, HttpClient httpClient)
        {
            if (authFactory == null)
            {
                throw new ArgumentNullException("authFactory");
            }
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (context.Environment == null)
            {
                throw new ArgumentException(Resources.InvalidAzureEnvironment);
            }
            if (httpClient == null)
            {
                throw new ArgumentNullException("httpClient");
            }

            var credential = new DataServiceCredential(authFactory, context);
            this.keyVaultClient = new Client.KeyVaultClient(
                credential.OnAuthentication,
                SendRequestCallback,
                ReceiveResponseCallback,
                httpClient);


            this.vaultUriHelper = new VaultUriHelper(
                context.Environment.Endpoints[AzureEnvironment.Endpoint.AzureKeyVaultDnsSuffix]);
        }
        private Tuple<IAccessToken, string> GetToken(IAuthenticationFactory authFactory, AzureContext context, AzureEnvironment.Endpoint resourceIdEndpoint)
        {
            if (context.Account == null)
                throw new ArgumentException(KeyVaultProperties.Resources.ArmAccountNotFound);

            if (context.Account.Type != AzureAccount.AccountType.User &&
                context.Account.Type != AzureAccount.AccountType.ServicePrincipal )
                throw new ArgumentException(string.Format(KeyVaultProperties.Resources.UnsupportedAccountType, context.Account.Type));

            if (context.Subscription != null && context.Account != null)
                TenantId = context.Subscription.GetPropertyAsArray(AzureSubscription.Property.Tenants)
                       .Intersect(context.Account.GetPropertyAsArray(AzureAccount.Property.Tenants))
                       .FirstOrDefault();

            if (string.IsNullOrWhiteSpace(TenantId) && context.Tenant != null && context.Tenant.Id != Guid.Empty)
                TenantId = context.Tenant.Id.ToString();

            if (string.IsNullOrWhiteSpace(TenantId))
                throw new ArgumentException(KeyVaultProperties.Resources.NoTenantInContext);
          
            try
            {
                var accesstoken = authFactory.Authenticate(context.Account, context.Environment, TenantId, null, ShowDialog.Auto,
                    resourceIdEndpoint);

                return Tuple.Create(accesstoken, context.Environment.Endpoints[resourceIdEndpoint]);
            }
            catch (Exception ex)
            {
                throw new ArgumentException(KeyVaultProperties.Resources.InvalidSubscriptionState, ex);
            }        
        }
        public DataServiceCredential(IAuthenticationFactory authFactory, AzureContext context, AzureEnvironment.Endpoint resourceIdEndpoint)
        {
            if (authFactory == null)
                throw new ArgumentNullException("authFactory");
            if (context == null)
                throw new ArgumentNullException("context");

            var bundle = GetToken(authFactory, context, resourceIdEndpoint);
            this.token = bundle.Item1;
        }
        public Track2KeyVaultDataServiceClient(IAuthenticationFactory authFactory, IAzureContext context)
        {
            _authFactory = authFactory ?? throw new ArgumentNullException(nameof(authFactory));
            _context     = context ?? throw new ArgumentNullException(nameof(context));

            if (context.Environment == null)
            {
                throw new ArgumentException(KeyVaultProperties.Resources.InvalidAzureEnvironment);
            }
        }
        private static IGatewayClient CreateGatewaysClient(IAuthenticationFactory authenticator, IPowerBIProfile profile, IPowerBILogger logger, IPowerBISettings settings, HttpClientHandler httpClientHandler)
        {
            var token = authenticator.Authenticate(profile, logger, settings);

            if (Uri.TryCreate(profile.Environment.GlobalServiceEndpoint, UriKind.Absolute, out Uri baseUri))
            {
                return(new GatewayClient(baseUri, token, httpClientHandler));
            }

            throw new ArgumentNullException(nameof(IPowerBIEnvironment.GlobalServiceEndpoint));
        }
        public void RunPSTestWithToken(Func <AzureContext, string, string> testBuilder, params string[] scripts)
        {
            var callingClassType = TestUtilities.GetCallingClass(2);
            var mockName         = TestUtilities.GetCurrentMethodName(2);
            IAuthenticationFactory savedAuthFactory = AzureSession.AuthenticationFactory;

            try
            {
                RunPsTestWorkflow(
                    () =>
                {
                    savedAuthFactory       = AzureSession.AuthenticationFactory;
                    var command            = new GetAzureSubscriptionCommand();
                    command.CommandRuntime = new MockCommandRuntime();
                    command.InvokeBeginProcessing();
                    var profile = command.Profile;
                    var context = profile.Context;
                    var account = context.Account;
                    var tenant  = account.IsPropertySet(AzureAccount.Property.Tenants)
                            ? account.GetPropertyAsArray(AzureAccount.Property.Tenants).First()
                            : "Common";
                    var subscription = context.Subscription;
                    string token     = null;
                    if (account.IsPropertySet(AzureAccount.Property.AccessToken))
                    {
                        token = account.GetProperty(AzureAccount.Property.AccessToken);
                    }
                    else
                    {
                        var accessToken = AzureSession.AuthenticationFactory.Authenticate(account,
                                                                                          context.Environment,
                                                                                          tenant, null, ShowDialog.Never);
                        Assert.IsNotNull(accessToken);
                        Assert.IsNotNull(accessToken.AccessToken);
                        token = accessToken.AccessToken;
                    }

                    AzureSession.AuthenticationFactory = new AuthenticationFactory();
                    var testString      = testBuilder(context, token);
                    var returnedScripts = scripts.Concat(new String[] { testString });
                    return(returnedScripts.ToArray());
                },
                    // no custom initializer
                    null,
                    // no custom cleanup
                    null,
                    callingClassType,
                    mockName);
            }
            finally
            {
                AzureSession.AuthenticationFactory = savedAuthFactory;
            }
        }
 public DataServiceCredential(IAuthenticationFactory authFactory, AzureContext context, AzureEnvironment.Endpoint resourceIdEndpoint)
 {
     if (authFactory == null)
         throw new ArgumentNullException("authFactory");
     if (context == null)
         throw new ArgumentNullException("context");
     _authenticationFactory = authFactory;
     _context = context;
     _endpointName = resourceIdEndpoint;
     this.TenantId = GetTenantId(context);
 }
Beispiel #9
0
        public SecurityDomainClient(IAuthenticationFactory authenticationFactory, IAzureContext defaultContext, Action <string> debugWriter)
        {
            _credentials = new DataServiceCredential(authenticationFactory, defaultContext, ExtendedEndpoint.ManagedHsmServiceEndpointResourceId);

            _uriHelper = new VaultUriHelper(
                defaultContext.Environment.GetEndpoint(AzureEnvironment.Endpoint.AzureKeyVaultDnsSuffix),
                defaultContext.Environment.GetEndpoint(ExtendedEndpoint.ManagedHsmServiceEndpointSuffix));

            HttpClient.DefaultRequestHeaders.TransferEncodingChunked = false;

            _writeDebug = debugWriter;
        }
Beispiel #10
0
 public UserModel(
     [NotNull] IUserDal dal,
     [NotNull] IUserFactory userFactory,
     [NotNull] IAuthenticationFactory authenticationFactory,
     [NotNull] IRandomHexIdentifiers randomHexIdentifiers,
     [NotNull] IGoogleIdTokenVerifier googleIdTokenVerifier)
 {
     this.dal = dal;
     this.userFactory = userFactory;
     this.authenticationFactory = authenticationFactory;
     this.randomHexIdentifiers = randomHexIdentifiers;
     this.googleIdTokenVerifier = googleIdTokenVerifier;
 }
        private static IPowerBIClient CreateClient(IAuthenticationFactory authenticator, IPowerBIProfile profile, IPowerBILogger logger, IPowerBISettings settings, HttpClientHandler httpClientHandler)
        {
            var token = authenticator.Authenticate(profile, logger, settings);

            if (Uri.TryCreate(profile.Environment.GlobalServiceEndpoint, UriKind.Absolute, out Uri baseUri))
            {
                return(new PowerBIClient(baseUri, new TokenCredentials(token.AccessToken), httpClientHandler));
            }
            else
            {
                return(new PowerBIClient(new TokenCredentials(token.AccessToken), httpClientHandler));
            }
        }
 public DataServiceCredential(IAuthenticationFactory authFactory, IAzureContext context, string resourceIdEndpoint)
 {
     if (authFactory == null)
     {
         throw new ArgumentNullException("authFactory");
     }
     if (context == null)
     {
         throw new ArgumentNullException("context");
     }
     _authenticationFactory = authFactory;
     _context      = context;
     _endpointName = resourceIdEndpoint;
     this.TenantId = GetTenantId(context);
 }
 public DataServiceCredential(IAuthenticationFactory authFactory, AzureContext context)
 {
     if (authFactory == null)
     { 
         throw new ArgumentNullException("authFactory");
     }
     if (context == null)
     {
         throw new ArgumentNullException("context");
     }
     
     var bundle = GetToken(authFactory, context);
     this.token = bundle.Item1;
     this.resourceId = bundle.Item2;
 }
        public DataServiceCredential(IAuthenticationFactory authFactory, AzureContext context, AzureEnvironment.Endpoint resourceIdEndpoint)
        {
            if (authFactory == null)
            {
                throw new ArgumentNullException("authFactory");
            }
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            var bundle = GetToken(authFactory, context, resourceIdEndpoint);

            this.token = bundle.Item1;
        }
        public KeyVaultDataServiceClient(IAuthenticationFactory authFactory, AzureContext context)
        {
            if (authFactory == null)
                throw new ArgumentNullException("authFactory");
            if (context == null)
                throw new ArgumentNullException("context");
            if (context.Environment == null)
                throw new ArgumentException(KeyVaultProperties.Resources.InvalidAzureEnvironment);

            var credential = new DataServiceCredential(authFactory, context, AzureEnvironment.Endpoint.AzureKeyVaultServiceEndpointResourceId);
            this.keyVaultClient = new KeyVaultClient(credential.OnAuthentication);


            this.vaultUriHelper = new VaultUriHelper(
                context.Environment.Endpoints[AzureEnvironment.Endpoint.AzureKeyVaultDnsSuffix]);
        }
        private Tuple <IAccessToken, string> GetToken(IAuthenticationFactory authFactory, AzureContext context, AzureEnvironment.Endpoint resourceIdEndpoint)
        {
            if (context.Account == null)
            {
                throw new ArgumentException(KeyVaultProperties.Resources.ArmAccountNotFound);
            }

            if (context.Account.Type != AzureAccount.AccountType.User &&
                context.Account.Type != AzureAccount.AccountType.ServicePrincipal)
            {
                throw new ArgumentException(string.Format(KeyVaultProperties.Resources.UnsupportedAccountType, context.Account.Type));
            }

            if (context.Subscription != null && context.Account != null)
            {
                TenantId = context.Subscription.GetPropertyAsArray(AzureSubscription.Property.Tenants)
                           .Intersect(context.Account.GetPropertyAsArray(AzureAccount.Property.Tenants))
                           .FirstOrDefault();
            }

            if (string.IsNullOrWhiteSpace(TenantId) && context.Tenant != null && context.Tenant.Id != Guid.Empty)
            {
                TenantId = context.Tenant.Id.ToString();
            }

            if (string.IsNullOrWhiteSpace(TenantId))
            {
                throw new ArgumentException(KeyVaultProperties.Resources.NoTenantInContext);
            }

            try
            {
                var accesstoken = authFactory.Authenticate(context.Account, context.Environment, TenantId, null, ShowDialog.Auto,
                                                           resourceIdEndpoint);

                return(Tuple.Create(accesstoken, context.Environment.Endpoints[resourceIdEndpoint]));
            }
            catch (Exception ex)
            {
                throw new ArgumentException(KeyVaultProperties.Resources.InvalidSubscriptionState, ex);
            }
        }
        public KeyVaultDataServiceClient(IAuthenticationFactory authFactory, AzureContext context)
        {
            if (authFactory == null)
            {
                throw new ArgumentNullException("authFactory");
            }
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (context.Environment == null)
            {
                throw new ArgumentException(KeyVaultProperties.Resources.InvalidAzureEnvironment);
            }

            var credential = new DataServiceCredential(authFactory, context, AzureEnvironment.Endpoint.AzureKeyVaultServiceEndpointResourceId);

            this.keyVaultClient = new KeyVaultClient(credential.OnAuthentication);


            this.vaultUriHelper = new VaultUriHelper(
                context.Environment.Endpoints[AzureEnvironment.Endpoint.AzureKeyVaultDnsSuffix]);
        }
        private Tuple <IAccessToken, string> GetToken(IAuthenticationFactory authFactory, AzureContext context)
        {
            if (context.Subscription == null)
            {
                throw new ArgumentException(Resources.InvalidCurrentSubscription);
            }
            if (context.Account == null)
            {
                throw new ArgumentException(Resources.InvalidSubscriptionState);
            }
            if (context.Account.Type != AzureAccount.AccountType.User)
            {
                throw new ArgumentException(string.Format(Resources.UnsupportedAccountType, context.Account.Type));
            }

            var tenant = context.Subscription.GetPropertyAsArray(AzureSubscription.Property.Tenants)
                         .Intersect(context.Account.GetPropertyAsArray(AzureAccount.Property.Tenants))
                         .FirstOrDefault();

            if (tenant == null)
            {
                throw new ArgumentException(Resources.InvalidSubscriptionState);
            }

            try
            {
                var accesstoken = authFactory.Authenticate(context.Account, context.Environment, tenant, null, ShowDialog.Auto,
                                                           ResourceIdEndpoint);

                return(Tuple.Create(accesstoken, context.Environment.Endpoints[ResourceIdEndpoint]));
            }
            catch (Exception ex)
            {
                throw new ArgumentException(Resources.InvalidSubscriptionState, ex);
            }
        }
        private static Tuple<IAccessToken, string> GetTokenInternal(string tenantId, IAuthenticationFactory authFactory, AzureContext context, AzureEnvironment.Endpoint resourceIdEndpoint)
        {
            if (string.IsNullOrWhiteSpace(tenantId))
                throw new ArgumentException(KeyVaultProperties.Resources.NoTenantInContext);

            try
            {
                var tokenCache = AzureSession.TokenCache;
                if (context.TokenCache != null && context.TokenCache.Length > 0)
                {
                    tokenCache = new TokenCache(context.TokenCache);
                }

                var accesstoken = authFactory.Authenticate(context.Account, context.Environment, tenantId, null, ShowDialog.Never,
                    tokenCache, resourceIdEndpoint);

                if (context.TokenCache != null && context.TokenCache.Length > 0)
                {
                    context.TokenCache = tokenCache.Serialize();
                }

                return Tuple.Create(accesstoken, context.Environment.Endpoints[resourceIdEndpoint]);
            }
            catch (Exception ex)
            {
                throw new ArgumentException(KeyVaultProperties.Resources.InvalidSubscriptionState, ex);
            }
        }
Beispiel #20
0
 public MockClientFactory(IAuthenticationFactory authenticationFactory)
 {
     this.authenticationFactory = authenticationFactory;
 }
Beispiel #21
0
 /// <summary>
 /// Set the  authentication factory to use
 /// </summary>
 /// <param name="authenticationFactory"></param>
 public static void SetCurrent(IAuthenticationFactory authenticationFactory)
 {
     _currentAuthenticationFactory = authenticationFactory;
 }
 public PowerBIApiClient(IAuthenticationFactory authenticator, IPowerBIProfile profile, IPowerBILogger logger, IPowerBISettings settings, HttpClientHandler httpClientHandler)
 {
     this.Client = CreateClient(authenticator, profile, logger, settings, httpClientHandler);
     InitializeClients();
 }
 public PowerBICmdletInitFactory(IPowerBILoggerFactory logger, IDataStorage storage, IAuthenticationFactory authenticator, IPowerBISettings settings)
 => (this.LoggerFactory, this.Storage, this.Authenticator, this.Settings) = (logger, storage, authenticator, settings);
 public PowerBIClientCmdletInitFactory(IPowerBILoggerFactory logger, IDataStorage storage, IAuthenticationFactory authenticator, IPowerBISettings settings, IPowerBIClientFactory client) : base(logger, storage, authenticator, settings) => this.Client = client;
 public PowerBIApiClient(IAuthenticationFactory authenticator, IPowerBIProfile profile, IPowerBILogger logger, IPowerBISettings settings)
 {
     this.Client   = CreateClient(authenticator, profile, logger, settings);
     this.Gateways = CreateGatewaysClient(authenticator, profile, logger, settings);
     InitializeClients();
 }
 // Constructors
 public FlowerHornController(IAuthenticationFactory authenticationFactory) : base(authenticationFactory)
 {
 }
 public SettingsController(IAuthenticationFactory authenticationFactory)
     : base(authenticationFactory)
 {
 }
Beispiel #28
0
 // Constructors
 public BaseController(IAuthenticationFactory authenticationFactory)
 {
     this.authenticationFactory = authenticationFactory;
 }
Beispiel #29
0
 public IPowerBIApiClient CreateClient(IAuthenticationFactory authenticator, IPowerBIProfile profile, IPowerBILogger logger, IPowerBISettings settings)
 {
     return(new PowerBIApiClient(authenticator, profile, logger, settings, new PowerBIHttpClientHandler(logger)));
 }
Beispiel #30
0
 public GitHubService(IAuthenticationFactory authenticationFactory, IGitHubApi api)
 {
     _authenticationFactory = authenticationFactory;
     _api = api;
 }
Beispiel #31
0
 public EnquiryController(IAuthenticationFactory authenticationFactory)
     : base(authenticationFactory)
 {
 }
 // Constructors
 public SearchController(IAuthenticationFactory authenticationFactory)
     : base(authenticationFactory)
 {
 }
        private static Tuple <IAccessToken, string> GetTokenInternal(string tenantId, IAuthenticationFactory authFactory, IAzureContext context, string resourceIdEndpoint)
        {
            if (string.IsNullOrWhiteSpace(tenantId))
            {
                throw new ArgumentException(KeyVaultProperties.Resources.NoTenantInContext);
            }

            try
            {
                var tokenCache = AzureSession.Instance.TokenCache;
                if (context.TokenCache != null && context.TokenCache.CacheData != null && context.TokenCache.CacheData.Length > 0)
                {
                    tokenCache = context.TokenCache;
                }

                var accesstoken = authFactory.Authenticate(context.Account, context.Environment, tenantId, null, ShowDialog.Never,
                                                           null, tokenCache, resourceIdEndpoint);

                if (context.TokenCache != null && context.TokenCache.CacheData != null && context.TokenCache.CacheData.Length > 0)
                {
                    context.TokenCache = tokenCache;
                }

                return(Tuple.Create(accesstoken, context.Environment.GetEndpoint(resourceIdEndpoint)));
            }
            catch (Exception ex)
            {
                throw new ArgumentException(KeyVaultProperties.Resources.InvalidSubscriptionState, ex);
            }
        }
Beispiel #34
0
 public Track2VaultClient(IAuthenticationFactory authFactory, IAzureContext context)
 {
     _credential     = new Track2TokenCredential(new DataServiceCredential(authFactory, context, AzureEnvironment.Endpoint.AzureKeyVaultServiceEndpointResourceId));
     _vaultUriHelper = new VaultUriHelper(context.Environment.GetEndpoint(AzureEnvironment.Endpoint.AzureKeyVaultDnsSuffix));
 }
 public ReportController(IAuthenticationFactory authenticationFactory)
     : base(authenticationFactory)
 {
 }
 public Track2HsmClient(IAuthenticationFactory authFactory, IAzureContext context)
 {
     _credential = new Track2TokenCredential(new DataServiceCredential(authFactory, context, AzureEnvironment.ExtendedEndpoint.ManagedHsmServiceEndpointResourceId));
     _uriHelper  = new VaultUriHelper(context.Environment.GetEndpoint(AzureEnvironment.ExtendedEndpoint.ManagedHsmServiceEndpointSuffix));
 }
 /// <summary>
 /// Constructor for <see cref="ApiProxyController"/>
 /// </summary>
 /// <param name="httpClient">The <see cref="HttpClient"/> used to make requests to downstream API's.</param>
 /// <param name="proxyConfig">The <see cref="ApiProxyConfig"/> containing configured API's.</param>
 /// <param name="authFactory">The <see cref="IAuthenticationFactory"/>.</param>
 /// <param name="log">The <see cref="ILogger{ApiProxyController}"/></param>
 public ApiProxyController(HttpClient httpClient, IOptions <ApiProxyConfig> proxyConfig, IAuthenticationFactory authFactory, ILogger <ApiProxyController> log = null)
 {
     this.httpClient  = httpClient;
     this.authFactory = authFactory;
     this.log         = log;
     this.proxyConfig = proxyConfig.Value;
 }
Beispiel #38
0
 // Constructors
 public ActionsController(IAuthenticationFactory authenticationFactory)
     : base(authenticationFactory)
 {
 }
Beispiel #39
0
 public UserFactory([NotNull] IAuthenticationFactory authenticationFactory)
 {
     this.authenticationFactory = authenticationFactory;
 }
 public DetailsController(IAuthenticationFactory authenticationFactory)
     : base(authenticationFactory)
 {
 }
Beispiel #41
0
 /// <summary>
 /// Set the  authentication factory to use
 /// </summary>
 /// <param name="authenticationFactory"></param>
 public static void SetCurrent(IAuthenticationFactory authenticationFactory)
 {
     _currentAuthenticationFactory = authenticationFactory;
 }