本文整理汇总了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();
}
示例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();
}
示例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;
}
}
}