本文整理汇总了C#中Microsoft.Azure.Commands.Common.Authentication.Models.AzureAccount类的典型用法代码示例。如果您正苦于以下问题:C# AzureAccount类的具体用法?C# AzureAccount怎么用?C# AzureAccount使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AzureAccount类属于Microsoft.Azure.Commands.Common.Authentication.Models命名空间,在下文中一共展示了AzureAccount类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: CreateAzureSMProfile
public static AzureSMProfile CreateAzureSMProfile(string storageAccount)
{
var profile = new AzureSMProfile();
var client = new ProfileClient(profile);
var tenantId = Guid.NewGuid();
var subscriptionId = Guid.NewGuid();
var account = new AzureAccount
{
Id = "[email protected]",
Type = AzureAccount.AccountType.User
};
account.SetProperty(AzureAccount.Property.Tenants, tenantId.ToString());
account.SetProperty(AzureAccount.Property.Subscriptions, subscriptionId.ToString());
var subscription = new AzureSubscription()
{
Id = subscriptionId,
Name = "Test Subscription 1",
Environment = EnvironmentName.AzureCloud,
Account = account.Id,
};
subscription.SetProperty(AzureSubscription.Property.Tenants, tenantId.ToString());
subscription.SetProperty(AzureSubscription.Property.StorageAccount, storageAccount);
client.AddOrSetAccount(account);
client.AddOrSetSubscription(subscription);
client.SetSubscriptionAsDefault(subscriptionId, account.Id);
return profile;
}
开发者ID:rohmano,项目名称:azure-powershell,代码行数:27,代码来源:CommonDataCmdletTests.cs
示例2: Authenticate
public IAccessToken Authenticate(
AzureAccount account,
AzureEnvironment environment,
string tenant,
SecureString password,
ShowDialog promptBehavior,
IdentityModel.Clients.ActiveDirectory.TokenCache tokenCache,
AzureEnvironment.Endpoint resourceId = AzureEnvironment.Endpoint.ActiveDirectoryServiceEndpointResourceId)
{
if (account.Id == null)
{
account.Id = "test";
}
if (TokenProvider == null)
{
return new MockAccessToken()
{
AccessToken = account.Id,
LoginType = LoginType.OrgId,
UserId = account.Id
};
}
else
{
return TokenProvider(account, environment, tenant);
}
}
开发者ID:rohmano,项目名称:azure-powershell,代码行数:28,代码来源:MockTokenAuthenticationFactory.cs
示例3: Authenticate
public IAccessToken Authenticate(
AzureAccount account,
AzureEnvironment environment,
string tenant,
SecureString password,
ShowDialog promptBehavior,
TokenCache tokenCache,
AzureEnvironment.Endpoint resourceId = AzureEnvironment.Endpoint.ActiveDirectoryServiceEndpointResourceId)
{
var configuration = GetAdalConfiguration(environment, tenant, resourceId, tokenCache);
TracingAdapter.Information(Resources.AdalAuthConfigurationTrace, configuration.AdDomain, configuration.AdEndpoint,
configuration.ClientId, configuration.ClientRedirectUri, configuration.ResourceClientUri, configuration.ValidateAuthority);
IAccessToken token;
if (account.IsPropertySet(AzureAccount.Property.CertificateThumbprint))
{
var thumbprint = account.GetProperty(AzureAccount.Property.CertificateThumbprint);
token = TokenProvider.GetAccessTokenWithCertificate(configuration, account.Id, thumbprint, account.Type);
}
else
{
token = TokenProvider.GetAccessToken(configuration, promptBehavior, account.Id, password, account.Type);
}
account.Id = token.UserId;
return token;
}
开发者ID:rohmano,项目名称:azure-powershell,代码行数:28,代码来源:AuthenticationFactory.cs
示例4: AzureContext
public AzureContext(AzureSubscription subscription, AzureAccount account, AzureEnvironment environment, AzureTenant tenant)
{
Subscription = subscription;
Account = account;
Environment = environment;
Tenant = tenant;
}
开发者ID:rohmano,项目名称:azure-powershell,代码行数:7,代码来源:AzureContext.cs
示例5: SetupEnvironment
/// <summary>
/// This overrides the default subscription and default account. This allows the
/// test to get the tenant id in the test.
/// </summary>
public void SetupEnvironment()
{
base.SetupEnvironment(AzureModule.AzureResourceManager);
TestEnvironment csmEnvironment = new CSMTestEnvironmentFactory().GetTestEnvironment();
if (csmEnvironment.SubscriptionId != null)
{
//Overwrite the default subscription and default account
//with ones using user ID and tenant ID from auth context
var user = GetUser(csmEnvironment);
var tenantId = GetTenantId(csmEnvironment);
// Existing test will not have a user or tenant id set
if (tenantId != null && user != null)
{
var testSubscription = new AzureSubscription()
{
Id = new Guid(csmEnvironment.SubscriptionId),
Name = AzureRmProfileProvider.Instance.Profile.Context.Subscription.Name,
Environment = AzureRmProfileProvider.Instance.Profile.Context.Subscription.Environment,
Account = user,
Properties = new Dictionary<AzureSubscription.Property, string>
{
{
AzureSubscription.Property.Default, "True"
},
{
AzureSubscription.Property.StorageAccount,
Environment.GetEnvironmentVariable("AZURE_STORAGE_ACCOUNT")
},
{
AzureSubscription.Property.Tenants, tenantId
},
}
};
var testAccount = new AzureAccount()
{
Id = user,
Type = AzureAccount.AccountType.User,
Properties = new Dictionary<AzureAccount.Property, string>
{
{
AzureAccount.Property.Subscriptions, csmEnvironment.SubscriptionId
},
}
};
AzureRmProfileProvider.Instance.Profile.Context.Subscription.Name = testSubscription.Name;
AzureRmProfileProvider.Instance.Profile.Context.Subscription.Id = testSubscription.Id;
AzureRmProfileProvider.Instance.Profile.Context.Subscription.Account = testSubscription.Account;
var environment = AzureRmProfileProvider.Instance.Profile.Environments[AzureRmProfileProvider.Instance.Profile.Context.Subscription.Environment];
environment.Endpoints[AzureEnvironment.Endpoint.Graph] = csmEnvironment.Endpoints.GraphUri.AbsoluteUri;
environment.Endpoints[AzureEnvironment.Endpoint.StorageEndpointSuffix] = "core.windows.net";
AzureRmProfileProvider.Instance.Profile.Save();
}
}
}
开发者ID:Azure,项目名称:azure-powershell,代码行数:64,代码来源:SqlEvnSetupHelper.cs
示例6: GetAccessToken
public IAccessToken GetAccessToken(AdalConfiguration config, ShowDialog promptBehavior, string userId, SecureString password,
AzureAccount.AccountType credentialType)
{
if (credentialType == AzureAccount.AccountType.User)
{
throw new ArgumentException(string.Format(Resources.InvalidCredentialType, "User"), "credentialType");
}
return new ServicePrincipalAccessToken(config, AcquireTokenWithSecret(config, userId, password), this.RenewWithSecret, userId);
}
开发者ID:rohmano,项目名称:azure-powershell,代码行数:9,代码来源:ServicePrincipalTokenProvider.cs
示例7: GetAccessTokenWithCertificate
public IAccessToken GetAccessTokenWithCertificate(AdalConfiguration config, string clientId, string certificateThumbprint, AzureAccount.AccountType credentialType)
{
if (credentialType == AzureAccount.AccountType.User)
{
throw new ArgumentException(string.Format(Resources.InvalidCredentialType, "User"), "credentialType");
}
return new ServicePrincipalAccessToken(config, AcquireTokenWithCertificate(config, clientId, certificateThumbprint),
(adalConfig, appId) => this.RenewWithCertificate(adalConfig, appId, certificateThumbprint), clientId);
}
开发者ID:rohmano,项目名称:azure-powershell,代码行数:9,代码来源:ServicePrincipalTokenProvider.cs
示例8: Authenticate
public IAccessToken Authenticate(
AzureAccount account,
AzureEnvironment environment,
string tenant,
SecureString password,
ShowDialog promptBehavior,
AzureEnvironment.Endpoint resourceId = AzureEnvironment.Endpoint.ActiveDirectoryServiceEndpointResourceId)
{
return Authenticate(account, environment, tenant, password, promptBehavior, AzureSession.TokenCache, resourceId);
}
开发者ID:Azure,项目名称:azure-powershell,代码行数:10,代码来源:MockCertificateAuthenticationFactory.cs
示例9: GetSubscriptionCertificateCredentials
public static IHDInsightSubscriptionCredentials GetSubscriptionCertificateCredentials(this IAzureHDInsightCommonCommandBase command,
AzureSubscription currentSubscription, AzureAccount azureAccount, AzureEnvironment environment)
{
return new HDInsightCertificateCredential
{
SubscriptionId = currentSubscription.Id,
Certificate = AzureSession.DataStore.GetCertificate(currentSubscription.Account),
Endpoint = environment.GetEndpointAsUri(AzureEnvironment.Endpoint.ServiceManagement),
};
}
开发者ID:Azure,项目名称:azure-powershell,代码行数:10,代码来源:AzureHDInsightCommandExtensions.cs
示例10: ProfileSerializeDeserializeWorks
public void ProfileSerializeDeserializeWorks()
{
var dataStore = new MockDataStore();
AzureSession.DataStore = dataStore;
var profilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, AzureSession.ProfileFile);
var currentProfile = new AzureRMProfile(profilePath);
var tenantId = Guid.NewGuid().ToString();
var environment = new AzureEnvironment
{
Name = "testCloud",
Endpoints = { { AzureEnvironment.Endpoint.ActiveDirectory, "http://contoso.com" } }
};
var account = new AzureAccount
{
Id = "[email protected]",
Type = AzureAccount.AccountType.User,
Properties = { { AzureAccount.Property.Tenants, tenantId } }
};
var sub = new AzureSubscription
{
Account = account.Id,
Environment = environment.Name,
Id = new Guid(),
Name = "Contoso Test Subscription",
Properties = { { AzureSubscription.Property.Tenants, tenantId } }
};
var tenant = new AzureTenant
{
Id = new Guid(tenantId),
Domain = "contoso.com"
};
currentProfile.Context = new AzureContext(sub, account, environment, tenant);
currentProfile.Environments[environment.Name] = environment;
currentProfile.Context.TokenCache = new byte[] { 1, 2, 3, 4, 5, 6, 8, 9, 0 };
AzureRMProfile deserializedProfile;
// Round-trip the exception: Serialize and de-serialize with a BinaryFormatter
BinaryFormatter bf = new BinaryFormatter();
using (MemoryStream ms = new MemoryStream())
{
// "Save" object state
bf.Serialize(ms, currentProfile);
// Re-use the same stream for de-serialization
ms.Seek(0, 0);
// Replace the original exception with de-serialized one
deserializedProfile = (AzureRMProfile)bf.Deserialize(ms);
}
Assert.NotNull(deserializedProfile);
var jCurrentProfile = currentProfile.ToString();
var jDeserializedProfile = deserializedProfile.ToString();
Assert.Equal(jCurrentProfile, jDeserializedProfile);
}
开发者ID:rohmano,项目名称:azure-powershell,代码行数:55,代码来源:AzureRMProfileTests.cs
示例11: GetAccessTokenWithCertificate
public IAccessToken GetAccessTokenWithCertificate(
AdalConfiguration config,
string clientId,
string certificate,
AzureAccount.AccountType credentialType)
{
switch (credentialType)
{
case AzureAccount.AccountType.ServicePrincipal:
return servicePrincipalTokenProvider.GetAccessTokenWithCertificate(config, clientId, certificate, credentialType);
default:
throw new ArgumentException(string.Format(Resources.UnsupportedCredentialType, credentialType), "credentialType");
}
}
开发者ID:Azure,项目名称:azure-powershell,代码行数:14,代码来源:AdalTokenProvider.cs
示例12: ProfileSaveDoesNotSerializeContext
public void ProfileSaveDoesNotSerializeContext()
{
var dataStore = new MockDataStore();
var profilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, AzureSession.ProfileFile);
var profile = new AzureSMProfile(profilePath);
AzureSession.DataStore = dataStore;
var tenant = Guid.NewGuid().ToString();
var environment = new AzureEnvironment
{
Name = "testCloud",
Endpoints = { { AzureEnvironment.Endpoint.ActiveDirectory, "http://contoso.com" } }
};
var account = new AzureAccount
{
Id = "[email protected]",
Type = AzureAccount.AccountType.User,
Properties = { { AzureAccount.Property.Tenants, tenant } }
};
var sub = new AzureSubscription
{
Account = account.Id,
Environment = environment.Name,
Id = new Guid(),
Name = "Contoso Test Subscription",
Properties = { { AzureSubscription.Property.Tenants, tenant } }
};
profile.Environments[environment.Name] = environment;
profile.Accounts[account.Id] = account;
profile.Subscriptions[sub.Id] = sub;
profile.Save();
var profileFile = profile.ProfilePath;
string profileContents = dataStore.ReadFileAsText(profileFile);
var readProfile = JsonConvert.DeserializeObject<Dictionary<string, object>>(profileContents);
Assert.False(readProfile.ContainsKey("DefaultContext"));
AzureSMProfile parsedProfile = new AzureSMProfile();
var serializer = new JsonProfileSerializer();
Assert.True(serializer.Deserialize(profileContents, parsedProfile));
Assert.NotNull(parsedProfile);
Assert.NotNull(parsedProfile.Environments);
Assert.True(parsedProfile.Environments.ContainsKey(environment.Name));
Assert.NotNull(parsedProfile.Accounts);
Assert.True(parsedProfile.Accounts.ContainsKey(account.Id));
Assert.NotNull(parsedProfile.Subscriptions);
Assert.True(parsedProfile.Subscriptions.ContainsKey(sub.Id));
}
开发者ID:Azure,项目名称:azure-powershell,代码行数:48,代码来源:AzureSMProfileTests.cs
示例13: GetAccessToken
public IAccessToken GetAccessToken(
AdalConfiguration config,
ShowDialog promptBehavior,
string userId,
SecureString password,
AzureAccount.AccountType credentialType)
{
switch (credentialType)
{
case AzureAccount.AccountType.User:
return userTokenProvider.GetAccessToken(config, promptBehavior, userId, password, credentialType);
case AzureAccount.AccountType.ServicePrincipal:
return servicePrincipalTokenProvider.GetAccessToken(config, promptBehavior, userId, password, credentialType);
default:
throw new ArgumentException(Resources.UnknownCredentialType, "credentialType");
}
}
开发者ID:Azure,项目名称:azure-powershell,代码行数:17,代码来源:AdalTokenProvider.cs
示例14: Main
static void Main(string[] args)
{
try
{
if (args.Length == 0)
{
AzureAccount azureAccount = new AzureAccount();
azureAccount.Type = AzureAccount.AccountType.User;
var environment = AzureEnvironment.PublicEnvironments["AzureCloud"];
var auth = new Authenticator(AzureRmProfileProvider.Instance.Profile);
auth.Login(azureAccount, environment);
}
else if (args.Length == 2)
{
var subcriptionId = args[0];
var authToken = args[1];
Authenticator.ShowIoTHubsInSubscription(subcriptionId, authToken).Wait();
}
else
{
Console.WriteLine("Usage:");
Console.WriteLine("MSAAuthenticator.exe");
Console.WriteLine(" Pop up a credentials gatheting windows and list all IoT Hubs under all subscriptions associated with the user");
Console.WriteLine("MSAAuthenticator.exe <subscription_id> <access_token>");
Console.WriteLine(" Lists IoT Hubs abd devices given subscription_id and access_token");
}
}
catch (Exception ex)
{
var aggr = ex as System.AggregateException;
if (aggr != null)
{
foreach (var inner in aggr.InnerExceptions)
{
Console.WriteLine("Exception: {0}", inner.Message);
}
}
else
{
Console.WriteLine("Exception: {0}", ex.Message);
}
}
}
开发者ID:ms-iot,项目名称:security,代码行数:46,代码来源:Program.cs
示例15: ExecuteCmdlet
public override void ExecuteCmdlet()
{
AzureAccount azureAccount = new AzureAccount();
azureAccount.Type = ServicePrincipal.IsPresent
? AzureAccount.AccountType.ServicePrincipal
: AzureAccount.AccountType.User;
SecureString password = null;
if (Credential != null)
{
azureAccount.Id = Credential.UserName;
password = Credential.Password;
}
if (!string.IsNullOrEmpty(Tenant))
{
azureAccount.SetProperty(AzureAccount.Property.Tenants, new[] {Tenant});
}
var account = ProfileClient.AddAccountAndLoadSubscriptions(azureAccount, ProfileClient.GetEnvironmentOrDefault(Environment), password);
if (account != null)
{
WriteVerbose(string.Format(Resources.AddAccountAdded, azureAccount.Id));
if (ProfileClient.Profile.DefaultSubscription != null)
{
WriteVerbose(string.Format(Resources.AddAccountShowDefaultSubscription,
ProfileClient.Profile.DefaultSubscription.Name));
}
WriteVerbose(Resources.AddAccountViewSubscriptions);
WriteVerbose(Resources.AddAccountChangeSubscription);
string subscriptionsList = account.GetProperty(AzureAccount.Property.Subscriptions);
string tenantsList = account.GetProperty(AzureAccount.Property.Tenants);
if (subscriptionsList == null)
{
WriteWarning(string.Format(Resources.NoSubscriptionAddedMessage, azureAccount.Id));
}
WriteObject(account.ToPSAzureAccount());
}
}
开发者ID:Azure,项目名称:azure-powershell,代码行数:44,代码来源:AddAzureAccount.cs
示例16: SetupEnvironment
public void SetupEnvironment()
{
base.SetupEnvironment(AzureModule.AzureResourceManager);
TestEnvironment csmEnvironment = new CSMTestEnvironmentFactory().GetTestEnvironment();
if (csmEnvironment.SubscriptionId != null)
{
//Overwrite the default subscription and default account
//with ones using user ID and tenant ID from auth context
var user = GetUser(csmEnvironment);
var tenantId = GetTenantId(csmEnvironment);
var testSubscription = new AzureSubscription()
{
Id = new Guid(csmEnvironment.SubscriptionId),
Name = AzureRmProfileProvider.Instance.Profile.Context.Subscription.Name,
Environment = AzureRmProfileProvider.Instance.Profile.Context.Environment.Name,
Account = user,
Properties = new Dictionary<AzureSubscription.Property, string>
{
{AzureSubscription.Property.Default, "True"},
{
AzureSubscription.Property.StorageAccount,
Environment.GetEnvironmentVariable("AZURE_STORAGE_ACCOUNT")
},
{AzureSubscription.Property.Tenants, tenantId},
}
};
var testAccount = new AzureAccount()
{
Id = user,
Type = AzureAccount.AccountType.User,
Properties = new Dictionary<AzureAccount.Property, string>
{
{AzureAccount.Property.Subscriptions, csmEnvironment.SubscriptionId},
}
};
AzureRmProfileProvider.Instance.Profile.Context = new AzureContext(testSubscription, testAccount, AzureRmProfileProvider.Instance.Profile.Context.Environment, new AzureTenant { Id = new Guid(tenantId) });
}
}
开发者ID:Azure,项目名称:azure-powershell,代码行数:43,代码来源:KeyVaultEnvSetupHelper.cs
示例17: SimpleAccessToken
/// <summary>
/// Create a new access token from the given account and tenant id
/// </summary>
/// <param name="account">The account, containing user id, access token information</param>
/// <param name="tenantId">The tenant id for the given access token</param>
/// <param name="tokenType">The token type for the given token.</param>
public SimpleAccessToken(AzureAccount account, string tenantId, string tokenType = _defaultTokenType)
{
if (account == null)
{
throw new ArgumentNullException("account");
}
if (string.IsNullOrWhiteSpace(account.Id))
{
throw new ArgumentOutOfRangeException("account", Resources.AccessTokenRequiresAccount);
}
if (account.Type != AzureAccount.AccountType.AccessToken ||
!account.IsPropertySet(AzureAccount.Property.AccessToken))
{
throw new ArgumentException(Resources.TypeNotAccessToken);
}
this.UserId = account.Id;
this._tokenType = tokenType;
this.AccessToken = account.GetProperty(AzureAccount.Property.AccessToken);
this.TenantId = tenantId;
}
开发者ID:rohmano,项目名称:azure-powershell,代码行数:26,代码来源:SimpleAccessToken.cs
示例18: GetAccessTokenCredentials
public static IHDInsightSubscriptionCredentials GetAccessTokenCredentials(this IAzureHDInsightCommonCommandBase command,
AzureSubscription currentSubscription, AzureAccount azureAccount, AzureEnvironment environment)
{
ProfileClient profileClient = new ProfileClient(new AzureSMProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile)));
AzureContext azureContext = new AzureContext(currentSubscription, azureAccount, environment);
var cloudCredentials = AzureSession.AuthenticationFactory.GetSubscriptionCloudCredentials(azureContext) as AccessTokenCredential;
if (cloudCredentials != null)
{
var field= typeof(AccessTokenCredential).GetField("token", BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance);
var accessToken = field.GetValue(cloudCredentials) as IAccessToken;
if (accessToken != null)
{
return new HDInsightAccessTokenCredential()
{
SubscriptionId = currentSubscription.Id,
AccessToken = accessToken.AccessToken
};
}
}
return null;
}
开发者ID:Azure,项目名称:azure-powershell,代码行数:22,代码来源:AzureHDInsightCommandExtensions.cs
示例19: GetAccessTokenWithCertificate
public IAccessToken GetAccessTokenWithCertificate(AdalConfiguration config, string principalId, string certificateThumbprint, AzureAccount.AccountType credentialType)
{
return this.accessToken;
}
开发者ID:Azure,项目名称:azure-powershell,代码行数:4,代码来源:FakeAccessTokenProvider.cs
示例20: GetAccessToken
public IAccessToken GetAccessToken(AdalConfiguration config, ShowDialog promptBehavior, string userId, SecureString password,
AzureAccount.AccountType credentialType)
{
return this.accessToken;
}
开发者ID:Azure,项目名称:azure-powershell,代码行数:5,代码来源:FakeAccessTokenProvider.cs
注:本文中的Microsoft.Azure.Commands.Common.Authentication.Models.AzureAccount类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论