当前位置: 首页>>代码示例>>C#>>正文


C# WindowsAzureSubscription.SetAccessToken方法代码示例

本文整理汇总了C#中WindowsAzureSubscription.SetAccessToken方法的典型用法代码示例。如果您正苦于以下问题:C# WindowsAzureSubscription.SetAccessToken方法的具体用法?C# WindowsAzureSubscription.SetAccessToken怎么用?C# WindowsAzureSubscription.SetAccessToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WindowsAzureSubscription的用法示例。


在下文中一共展示了WindowsAzureSubscription.SetAccessToken方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SetupAzureEnvironmentFromEnvironmentVariables

        private void SetupAzureEnvironmentFromEnvironmentVariables(AzureModule mode)
        {
            TestEnvironment rdfeEnvironment = new RDFETestEnvironmentFactory().GetTestEnvironment();
            TestEnvironment csmEnvironment = new CSMTestEnvironmentFactory().GetTestEnvironment();
            TestEnvironment currentEnvironment = (mode == AzureModule.AzureResourceManager
                ? csmEnvironment
                : rdfeEnvironment);

            string jwtToken;

            if (mode == AzureModule.AzureResourceManager)
            {
                jwtToken = csmEnvironment.Credentials != null ?
                ((TokenCloudCredentials)csmEnvironment.Credentials).Token : null;
            }
            else if (mode == AzureModule.AzureServiceManagement)
            {
                jwtToken = rdfeEnvironment.Credentials != null ?
                ((TokenCloudCredentials)rdfeEnvironment.Credentials).Token : null;
            }
            else
            {
                throw new ArgumentException("Invalid module mode.");
            }

            SetEndpointsToDefaults(rdfeEnvironment, csmEnvironment);

            WindowsAzureProfile.Instance.TokenProvider = new FakeAccessTokenProvider(jwtToken, csmEnvironment.UserName);

            WindowsAzureProfile.Instance.CurrentEnvironment = WindowsAzureProfile.Instance.Environments[testEnvironmentName];

            WindowsAzureProfile.Instance.CurrentEnvironment.ActiveDirectoryEndpoint =
                currentEnvironment.ActiveDirectoryEndpoint.AbsoluteUri;
            WindowsAzureProfile.Instance.CurrentEnvironment.GalleryEndpoint =
                currentEnvironment.GalleryUri.AbsoluteUri;
            WindowsAzureProfile.Instance.CurrentEnvironment.ResourceManagerEndpoint =
                csmEnvironment.BaseUri.AbsoluteUri;
            WindowsAzureProfile.Instance.CurrentEnvironment.ServiceEndpoint =
                rdfeEnvironment.BaseUri.AbsoluteUri;

            if (currentEnvironment.UserName == null)
            {
                currentEnvironment.UserName = "[email protected]";
            }

            testSubscription = new WindowsAzureSubscription(false, false)
            {
                SubscriptionId = currentEnvironment.SubscriptionId,
                ActiveDirectoryEndpoint =
                    WindowsAzureProfile.Instance.CurrentEnvironment.ActiveDirectoryEndpoint,
                ActiveDirectoryUserId = currentEnvironment.UserName,
                SubscriptionName = currentEnvironment.SubscriptionId,
                ServiceEndpoint = new Uri(WindowsAzureProfile.Instance.CurrentEnvironment.ServiceEndpoint),
                ResourceManagerEndpoint = new Uri(WindowsAzureProfile.Instance.CurrentEnvironment.ResourceManagerEndpoint),
                TokenProvider = WindowsAzureProfile.Instance.TokenProvider,
                GalleryEndpoint = new Uri(WindowsAzureProfile.Instance.CurrentEnvironment.GalleryEndpoint),
                SqlDatabaseDnsSuffix = WindowsAzureProfile.Instance.CurrentEnvironment.SqlDatabaseDnsSuffix,
                CurrentStorageAccountName = Environment.GetEnvironmentVariable("AZURE_STORAGE_ACCOUNT"),
                IsDefault = true
            };

            testEnvironment = currentEnvironment;
            if (HttpMockServer.GetCurrentMode() == HttpRecorderMode.Playback)
            {
                testSubscription.SetAccessToken(new FakeAccessToken
                {
                    AccessToken = "123",
                    UserId = testEnvironment.UserName
                });
            }
            else
            {
                testSubscription.SetAccessToken(WindowsAzureProfile.Instance.TokenProvider.GetNewToken(WindowsAzureProfile.Instance.CurrentEnvironment));
            }

            WindowsAzureProfile.Instance.AddSubscription(testSubscription);
            WindowsAzureProfile.Instance.Save();
        }
开发者ID:kangyangthu,项目名称:azure-sdk-tools,代码行数:78,代码来源:EnvironmentSetupHelper.cs

示例2: SetupAzureEnvironmentFromEnvironmentVariables

        private void SetupAzureEnvironmentFromEnvironmentVariables()
        {
            ServiceManagementTestEnvironmentFactory serviceManagementTestEnvironmentFactory = new ServiceManagementTestEnvironmentFactory();
            TestEnvironment rdfeEnvironment = serviceManagementTestEnvironmentFactory.GetTestEnvironment();
            ResourceManagerTestEnvironmentFactory resourceManagerTestEnvironmentFactory = new ResourceManagerTestEnvironmentFactory();
            TestEnvironment csmEnvironment = resourceManagerTestEnvironmentFactory.GetTestEnvironment();
            string jwtToken = csmEnvironment.Credentials != null ? 
                ((TokenCloudCredentials)csmEnvironment.Credentials).Token : null;

            WindowsAzureProfile.Instance.TokenProvider = new FakeAccessTokenProvider(jwtToken, csmEnvironment.UserName);
            
            WindowsAzureProfile.Instance.CurrentEnvironment = WindowsAzureProfile.Instance.Environments[testEnvironmentName];

            WindowsAzureProfile.Instance.CurrentEnvironment.ActiveDirectoryEndpoint =
                csmEnvironment.ActiveDirectoryEndpoint.AbsoluteUri;
            WindowsAzureProfile.Instance.CurrentEnvironment.GalleryEndpoint =
                csmEnvironment.GalleryUri.AbsoluteUri;
            WindowsAzureProfile.Instance.CurrentEnvironment.ResourceManagerEndpoint =
                csmEnvironment.BaseUri.AbsoluteUri;
            WindowsAzureProfile.Instance.CurrentEnvironment.ServiceEndpoint =
                rdfeEnvironment.BaseUri.AbsoluteUri;

            var newSubscription = new WindowsAzureSubscription(false, false)
            {
                SubscriptionId = csmEnvironment.SubscriptionId,
                ActiveDirectoryEndpoint =
                    WindowsAzureProfile.Instance.CurrentEnvironment.ActiveDirectoryEndpoint,
                ActiveDirectoryUserId = csmEnvironment.UserName,
                SubscriptionName = csmEnvironment.SubscriptionId,
                ServiceEndpoint = new Uri(WindowsAzureProfile.Instance.CurrentEnvironment.ServiceEndpoint),
                ResourceManagerEndpoint = new Uri(WindowsAzureProfile.Instance.CurrentEnvironment.ResourceManagerEndpoint),
                TokenProvider = WindowsAzureProfile.Instance.TokenProvider,
                GalleryEndpoint = new Uri(WindowsAzureProfile.Instance.CurrentEnvironment.GalleryEndpoint),
                SqlDatabaseDnsSuffix = WindowsAzureProfile.Instance.CurrentEnvironment.SqlDatabaseDnsSuffix,
                CurrentStorageAccountName = csmEnvironment.StorageAccount,
                IsDefault = true
            };
            if (HttpMockServer.Mode == HttpRecorderMode.Playback)
            {
                newSubscription.SetAccessToken(new FakeAccessToken
                    {
                        AccessToken = "123",
                        UserId = csmEnvironment.UserName
                    });
            }
            else
            {
                newSubscription.SetAccessToken(WindowsAzureProfile.Instance.TokenProvider.GetNewToken(WindowsAzureProfile.Instance.CurrentEnvironment));
            }

            WindowsAzureProfile.Instance.AddSubscription(newSubscription);
            WindowsAzureProfile.Instance.Save();
        }
开发者ID:jianghaolu,项目名称:azure-sdk-tools,代码行数:53,代码来源:WindowsAzurePowerShellTokenTest.cs

示例3: AddAccount

        public IEnumerable<WindowsAzureSubscription> AddAccount(ITokenProvider tokenProvider)
        {
            if (ActiveDirectoryEndpoint == null || ActiveDirectoryServiceEndpointResourceId == null)
            {
                throw new Exception(string.Format(Resources.EnvironmentDoesNotSupportActiveDirectory, Name));
            }

            IAccessToken mainToken = tokenProvider.GetNewToken(this);
            var credentials = new TokenCloudCredentials(mainToken.AccessToken);

            using (var subscriptionClient = new SubscriptionClient(credentials, new Uri(ServiceEndpoint)))
            {
                var result = subscriptionClient.Subscriptions.List();
                // Filter out subscriptions with no tenant, backfill's not done on them
                foreach (var subscription in result.Subscriptions.Where(s => !string.IsNullOrEmpty(s.ActiveDirectoryTenantId)))
                {
                    var azureSubscription = new WindowsAzureSubscription
                    {
                        ActiveDirectoryEndpoint = ActiveDirectoryEndpoint,
                        ActiveDirectoryTenantId = subscription.ActiveDirectoryTenantId,
                        ActiveDirectoryUserId = mainToken.UserId,
                        ActiveDirectoryServiceEndpointResourceId = ActiveDirectoryServiceEndpointResourceId,
                        SubscriptionId = subscription.SubscriptionId,
                        SubscriptionName = subscription.SubscriptionName,
                        ServiceEndpoint = !string.IsNullOrEmpty(ServiceEndpoint) ? new Uri(ServiceEndpoint) : null,
                        ResourceManagerEndpoint = !string.IsNullOrEmpty(ResourceManagerEndpoint) ? new Uri(ResourceManagerEndpoint) : null,
                        TokenProvider = tokenProvider,
                        GalleryEndpoint = !string.IsNullOrEmpty(GalleryEndpoint) ? new Uri(GalleryEndpoint) : null
                    };

                    if (mainToken.LoginType == LoginType.LiveId)
                    {
                        azureSubscription.SetAccessToken(tokenProvider.GetNewToken(azureSubscription, mainToken.UserId));
                    }
                    else
                    {
                        azureSubscription.SetAccessToken(mainToken);
                    }
                    yield return azureSubscription;
                }
            }
        }
开发者ID:EmmaZhu,项目名称:azure-sdk-tools,代码行数:42,代码来源:WindowsAzureEnvironment.cs


注:本文中的WindowsAzureSubscription.SetAccessToken方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。