public ApplicationsManager( Guid tenantId, TokenCredentials microsoftGraphTokenCredentials, CancellationToken cancellationToken ) { _tenantId = tenantId; _msGraphServiceClient = new MicrosoftGraphServiceClient( microsoftGraphTokenCredentials, cancellationToken ); }
protected async Task SetOwnerAsync( CancellationToken cancellationToken = default ) { // Initialization of MicrosoftGraphServiceClient var microsoftGraphTokenCredentials = _authenticationManager .GetMicrosoftGraphDelegatingTokenCredentials(); var msGraphServiceClient = new MicrosoftGraphServiceClient( microsoftGraphTokenCredentials, cancellationToken ); if (_authenticationManager.IsUserAuthenticationFlow()) { // If this is user authentication flow then authenticated user // will be used as owner of the deployment. var me = await msGraphServiceClient .GetMeAsync(cancellationToken); _owner = me; if (null != me.Mail) { InitializeDefaultTags(me.Mail); } else { var account = _authenticationManager.GetAccount(); InitializeDefaultTags(account?.Username); } } else { // If this is not user authentication flow then service principal // of the application will be used as owner of the deployment. var ownerSP = await msGraphServiceClient .GetServicePrincipalByAppIdAsync( _authConf.ClientId.ToString(), cancellationToken ); _owner = ownerSP; InitializeDefaultTags(ownerSP.DisplayName); } }
public void InitializeResourceManagementClients( CancellationToken cancellationToken = default ) { // Microsoft Graph var microsoftGraphTokenProvider = _authenticationManager .GenerateDelegatingTokenProvider( _authenticationManager.AcquireMicrosoftGraphTokenAsync ); _msGraphServiceClient = new MicrosoftGraphServiceClient( _tenantId, microsoftGraphTokenProvider, cancellationToken ); // Create generic RestClient for services _restClient = RestClient .Configure() .WithEnvironment(_azureEnvironment) .WithCredentials(_azureCredentials) //.WithLogLevel(HttpLoggingDelegatingHandler.Level.BodyAndHeaders) .Build(); var subscriptionId = _subscription.SubscriptionId; _resourceMgmtClient = new ResourceMgmtClient(subscriptionId, _restClient); _keyVaultManagementClient = new KeyVaultMgmtClient(subscriptionId, _restClient); _storageManagementClient = new StorageMgmtClient(subscriptionId, _restClient); _iotHubManagementClient = new IotHubMgmtClient(subscriptionId, _restClient); _cosmosDBManagementClient = new CosmosDBMgmtClient(subscriptionId, _restClient); _serviceBusManagementClient = new ServiceBusMgmtClient(subscriptionId, _restClient); _eventHubManagementClient = new EventHubMgmtClient(subscriptionId, _restClient); _operationalInsightsManagementClient = new OperationalInsightsMgmtClient(subscriptionId, _restClient); _applicationInsightsManagementClient = new ApplicationInsightsMgmtClient(subscriptionId, _restClient); _webSiteManagementClient = new WebSiteMgmtClient(subscriptionId, _restClient); _networkManagementClient = new NetworkMgmtClient(subscriptionId, _restClient); _authorizationManagementClient = new AuthorizationMgmtClient(subscriptionId, _restClient); _aksManagementClient = new AksMgmtClient(subscriptionId, _restClient); _signalRManagementClient = new SignalRMgmtClient(subscriptionId, _restClient); }