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


C# Models.AzureAccount类代码示例

本文整理汇总了C#中Microsoft.Azure.Common.Authentication.Models.AzureAccount的典型用法代码示例。如果您正苦于以下问题:C# AzureAccount类的具体用法?C# AzureAccount怎么用?C# AzureAccount使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


AzureAccount类属于Microsoft.Azure.Common.Authentication.Models命名空间,在下文中一共展示了AzureAccount类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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:dulems,项目名称:azure-powershell,代码行数:28,代码来源:MockTokenAuthenticationFactory.cs

示例2: 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

示例3: 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:docschmidt,项目名称:azure-powershell,代码行数:27,代码来源:CommonDataCmdletTests.cs

示例4: 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

示例5: 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

示例6: Authenticate

 public IAccessToken Authenticate(AzureAccount account, AzureEnvironment environment, string tenant, SecureString password, ShowDialog promptBehavior,
     AzureEnvironment.Endpoint resourceId = AzureEnvironment.Endpoint.ActiveDirectoryServiceEndpointResourceId)
 {
     var configuration = GetAdalConfiguration(environment, tenant, resourceId);
     TracingAdapter.Information(Resources.AdalAuthConfigurationTrace, configuration.AdDomain, configuration.AdEndpoint, 
         configuration.ClientId, configuration.ClientRedirectUri, configuration.ResourceClientUri, configuration.ValidateAuthority);
     var token = TokenProvider.GetAccessToken(configuration, promptBehavior, account.Id, password, account.Type);
     account.Id = token.UserId;
     return token;
 }
开发者ID:theadriangreen,项目名称:azure-sdk-for-net,代码行数:10,代码来源:AuthenticationFactory.cs

示例7: 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:rohmano,项目名称:azure-powershell,代码行数:10,代码来源:AdalTokenProvider.cs

示例8: Authenticate

        public IAccessToken Authenticate(AzureAccount account, AzureEnvironment environment, string tenant, SecureString password, ShowDialog promptBehavior,
            AzureEnvironment.Endpoint resourceId = AzureEnvironment.Endpoint.ActiveDirectoryServiceEndpointResourceId)
        {
            if (account.Id == null)
            {
                account.Id = "test";
            }

            return TokenProvider(account, environment, tenant);
        }
开发者ID:theadriangreen,项目名称:azure-sdk-for-net,代码行数:10,代码来源:MockTokenAuthenticationFactory.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:shuainie,项目名称:azure-powershell,代码行数:10,代码来源:AzureHDInsightCommandExtensions.cs

示例10: 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:docschmidt,项目名称:azure-powershell,代码行数:10,代码来源:MockCertificateAuthenticationFactory.cs

示例11: Login

        public AzureRMProfile Login(AzureAccount account, AzureEnvironment environment, string tenantId, string subscriptionId, 
            string subscriptionName, SecureString password)
        {
            AzureSubscription newSubscription = null;
            AzureTenant newTenant = null;
            ShowDialog promptBehavior = (password == null && account.Type != AzureAccount.AccountType.AccessToken) 
                ? ShowDialog.Always : ShowDialog.Never;

            // (tenant and subscription are present) OR
            // (tenant is present and subscription is not provided)
            if (!string.IsNullOrEmpty(tenantId))
            {
                var token = AcquireAccessToken(account, environment, tenantId, password, promptBehavior);
                TryGetTenantSubscription(token, account, environment, tenantId, subscriptionId, subscriptionName, out newSubscription, out newTenant);
            }
            // (tenant is not provided and subscription is present) OR
            // (tenant is not provided and subscription is not provided)
            else
            {
                foreach (var tenant in ListAccountTenants(account, environment, password, promptBehavior))
                {
                    AzureTenant tempTenant;
                    AzureSubscription tempSubscription;
                    var token = AcquireAccessToken(account, environment, tenant.Id.ToString(), password,
                        ShowDialog.Auto);
                    if (newTenant == null && TryGetTenantSubscription(token, account, environment, tenant.Id.ToString(), subscriptionId, subscriptionName, out tempSubscription, out tempTenant) &&
                        newTenant == null)
                    {
                        newTenant = tempTenant;
                        newSubscription = tempSubscription;
                    }
                }
            }

            if (newSubscription == null)
            {
                if (subscriptionId != null)
                {
                    throw new PSInvalidOperationException(String.Format(Properties.Resources.SubscriptionIdNotFound, account.Id, subscriptionId));
                }
                else if (subscriptionName != null)
                {
                    throw new PSInvalidOperationException(String.Format(Properties.Resources.SubscriptionNameNotFound, account.Id, subscriptionId));
                }
                else
                {
                    throw new PSInvalidOperationException(String.Format(Properties.Resources.NoSubscriptionFound, account.Id));
                }
            }

            _profile.Context = new AzureContext(newSubscription, account, environment, newTenant);
            _profile.Context.TokenCache = TokenCache.DefaultShared.Serialize();

            return _profile;
        }
开发者ID:rbramwell,项目名称:azure-powershell,代码行数:55,代码来源:RMProfileClient.cs

示例12: 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:rohmano,项目名称:azure-powershell,代码行数:13,代码来源:AdalTokenProvider.cs

示例13: ProfileSaveDoesNotSerializeContext

        public void ProfileSaveDoesNotSerializeContext()
        {
            var dataStore = new MockDataStore();
            var currentProfile = new AzureProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile));
            AzureSession.DataStore = dataStore;
            var client = new ProfileClient(currentProfile);
            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 } }
            };

            client.AddOrSetEnvironment(environment);
            client.AddOrSetAccount(account);
            client.AddOrSetSubscription(sub);

            currentProfile.Save();

            var profileFile = currentProfile.ProfilePath;
            string profileContents = dataStore.ReadFileAsText(profileFile);
            var readProfile = JsonConvert.DeserializeObject<Dictionary<string, object>>(profileContents);
            Assert.False(readProfile.ContainsKey("Context"));
            AzureProfile parsedProfile = new AzureProfile();
            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:theadriangreen,项目名称:azure-sdk-for-net,代码行数:48,代码来源:ProfileTests.cs

示例14: 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 = ProfileClient.Profile.DefaultSubscription.Name,
                    Environment = ProfileClient.Profile.DefaultSubscription.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},
                    }
                };

                ProfileClient.Profile.Accounts.Remove(ProfileClient.Profile.DefaultSubscription.Account);
                ProfileClient.Profile.Subscriptions[testSubscription.Id] = testSubscription;
                ProfileClient.Profile.Accounts[testAccount.Id] = testAccount;                
                ProfileClient.SetSubscriptionAsDefault(testSubscription.Name, testSubscription.Account);
                
                ProfileClient.Profile.Save();
            }
        }
开发者ID:nityasharma,项目名称:azure-powershell,代码行数:48,代码来源:KeyVaultEnvSetupHelper.cs

示例15: GetAzureProfile

        // Gets the customer's Azure account and subscription information
        private static AzureProfile GetAzureProfile()
        {
            AzureProfile profile = new AzureProfile();
            ProfileClient profileClient = new ProfileClient(profile);
            AzureAccount azureAccount = new AzureAccount() {Type = AzureAccount.AccountType.User};

            // Prompts the user for their credentials and retrieves their account/subscription info
            profileClient.AddAccountAndLoadSubscriptions(azureAccount, profile.Environments[EnvironmentName.AzureCloud], null);

            // By default, the first subscription is chosen
            if (profileClient.Profile.Subscriptions.Count > 1)
            {
                SelectSubscription(profileClient.Profile);
            }

            return profileClient.Profile;
        }
开发者ID:neerajay,项目名称:azure-batch-samples,代码行数:18,代码来源:Program.cs


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