本文整理汇总了C#中net.openstack.Providers.Rackspace.CloudIdentityProvider.Authenticate方法的典型用法代码示例。如果您正苦于以下问题:C# CloudIdentityProvider.Authenticate方法的具体用法?C# CloudIdentityProvider.Authenticate怎么用?C# CloudIdentityProvider.Authenticate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.openstack.Providers.Rackspace.CloudIdentityProvider
的用法示例。
在下文中一共展示了CloudIdentityProvider.Authenticate方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Should_Authenticate_Test_Admin_Identity
public void Should_Authenticate_Test_Admin_Identity()
{
IIdentityProvider serviceProvider = new CloudIdentityProvider(_testAdminIdentity);
var userAccess = serviceProvider.Authenticate();
Assert.IsNotNull(userAccess);
}
示例2: TestValidateToken
public void TestValidateToken()
{
IIdentityProvider provider = new CloudIdentityProvider(Bootstrapper.Settings.TestIdentity);
UserAccess userAccess = provider.Authenticate();
Assert.IsNotNull(userAccess);
Assert.IsNotNull(userAccess.Token);
Assert.IsNotNull(userAccess.Token.Id);
try
{
UserAccess validated = provider.ValidateToken(userAccess.Token.Id);
Assert.IsNotNull(validated);
Assert.IsNotNull(validated.Token);
Assert.AreEqual(userAccess.Token.Id, validated.Token.Id);
Assert.IsNotNull(validated.User);
Assert.AreEqual(userAccess.User.Id, validated.User.Id);
Assert.AreEqual(userAccess.User.Name, validated.User.Name);
Assert.AreEqual(userAccess.User.DefaultRegion, validated.User.DefaultRegion);
}
catch (UserNotAuthorizedException ex)
{
if (ex.Response.StatusCode != HttpStatusCode.Forbidden)
throw;
Assert.Inconclusive("The service does not allow this user to access the Validate Token API.");
}
}
示例3: Main
public static void Main(string[] args)
{
if (args.Length < 2 || args.Length > 3)
{
Console.WriteLine("Usage: {0} username api_key [region (US|UK)]", Environment.CommandLine);
Environment.Exit(1);
}
RackspaceImpersonationIdentity auth = new RackspaceImpersonationIdentity();
auth.Username = args[0];
auth.APIKey = args[1];
if (args.Length == 3)
{
if (args[2] != "UK" && args[2] != "US")
{
Console.WriteLine("region must be either US or UK", Environment.CommandLine);
Environment.Exit(1);
}
switch (args[2])
{
case "UK": { auth.CloudInstance = CloudInstance.UK; }; break;
case "US": { auth.CloudInstance = CloudInstance.Default; }; break;
}
}
else
{
auth.CloudInstance = CloudInstance.Default;
}
try
{
IIdentityProvider identityProvider = new CloudIdentityProvider();
var userAccess = identityProvider.Authenticate(auth);
}
catch (ResponseException ex2)
{
Console.WriteLine("Authentication failed with the following message: {0}", ex2.Message);
Environment.Exit(1);
}
var cloudServers = new CloudServersProvider(auth);
var servers = cloudServers.ListServers();
foreach (Server serv in servers)
{
var date = System.DateTime.Now;
var success = serv.CreateSnapshot(serv.Name + "_" + date.Year + "-" + date.Month + "-" + date.Day);
if (success)
{
Console.WriteLine("Image for server {0} has been created successfully.", serv.Name);
}
else
{
Console.WriteLine("Image for server {0} could not be created.", serv.Name);
}
}
}
示例4: CreateIdentity
private CloudIdentity CreateIdentity(string username, string apikey) {
var result = new CloudIdentity() {
Username = username,
APIKey = apikey
};
var provider = new CloudIdentityProvider();
var ua = provider.Authenticate(result);
return result;
}
示例5: Should_Not_Hit_Cache_When_Authenticating_The_First_Time
public void Should_Not_Hit_Cache_When_Authenticating_The_First_Time()
{
var cacheMock = new Mock<ICache<UserAccess>>();
var restServiceMock = new Mock<IRestService>();
restServiceMock.Setup(m => m.Execute<AuthenticationResponse>(It.IsAny<string>(), It.IsAny<HttpMethod>(), It.IsAny<string>(), It.IsAny<Dictionary<string, string>>(), It.IsAny<Dictionary<string, string>>(), It.IsAny<RequestSettings>())).Returns(new Response<AuthenticationResponse>(200, "OK", new AuthenticationResponse(), new List<HttpHeader>(), null));
restServiceMock.Setup(m => m.Execute<AuthenticationResponse>(It.IsAny<Uri>(), It.IsAny<HttpMethod>(), It.IsAny<string>(), It.IsAny<Dictionary<string, string>>(), It.IsAny<Dictionary<string, string>>(), It.IsAny<RequestSettings>())).Returns(new Response<AuthenticationResponse>(200, "OK", new AuthenticationResponse(), new List<HttpHeader>(), null));
var identityProvider = new CloudIdentityProvider(restServiceMock.Object, cacheMock.Object);
identityProvider.Authenticate(new RackspaceCloudIdentity());
cacheMock.Verify(m => m.Get(It.IsAny<string>(), It.IsAny<Func<UserAccess>>(), true), Times.Once());
}
示例6: Should_Always_Request_Fresh_Data_From_Cache_When_Authenticating
public void Should_Always_Request_Fresh_Data_From_Cache_When_Authenticating()
{
var cacheMock = new Mock<ICache<UserAccess>>();
var restServiceMock = new Mock<IRestService>();
restServiceMock.Setup(m => m.Execute<AuthenticationResponse>(It.IsAny<string>(), It.IsAny<HttpMethod>(), It.IsAny<string>(), It.IsAny<Dictionary<string, string>>(), It.IsAny<Dictionary<string, string>>(), It.IsAny<RequestSettings>())).Returns(new Response<AuthenticationResponse>(200, "OK", new AuthenticationResponse(), new List<HttpHeader>(), null));
restServiceMock.Setup(m => m.Execute<AuthenticationResponse>(It.IsAny<Uri>(), It.IsAny<HttpMethod>(), It.IsAny<string>(), It.IsAny<Dictionary<string, string>>(), It.IsAny<Dictionary<string, string>>(), It.IsAny<RequestSettings>())).Returns(new Response<AuthenticationResponse>(200, "OK", new AuthenticationResponse(), new List<HttpHeader>(), null));
var identityProvider = new CloudIdentityProvider(restServiceMock.Object, cacheMock.Object);
for (int i = 0; i < 100; i++)
{
identityProvider.Authenticate(new RackspaceCloudIdentity());
}
cacheMock.Verify(m => m.Get(It.IsAny<string>(), It.IsAny<Func<UserAccess>>(), true), Times.Exactly(100));
}
示例7: Run
public async Task Run(string username, string apiKey, string region)
{
// Configure authentication
var identity = new CloudIdentity
{
Username = username,
APIKey = apiKey
};
var identityService = new CloudIdentityProvider(identity);
var result = identityService.Authenticate();
var serverService = new CloudServersProvider(identity, region, null, null);
var rackConnectService = new RackConnectService(identityService, region);
// Create a cloud server on your hybrid network
Console.WriteLine($"Looking up your RackConnect network in {region}...");
var networks = await rackConnectService.ListNetworksAsync();
var network = networks.FirstOrDefault();
if (network == null)
throw new Exception($"You do not have a Hybrid Cloud / RackConnect network configured in the {region} which is required to run this sample.");
Console.WriteLine("Creating sample cloud server... ");
// Ubuntu 14.04 LTS (Trusty Tahr) (PVHVM)
const string ubuntuImageId = "09de0a66-3156-48b4-90a5-1cf25a905207";
// 512MB Standard Instance
const string standardFlavorId = "2";
var requestedServer = serverService.CreateServer("sample", ubuntuImageId, standardFlavorId,
networks: new string[] {network.Id});
serverService.WaitForServerActive(requestedServer.Id);
Console.WriteLine("Allocating a public IP address...");
var ip = await rackConnectService.CreatePublicIPAsync(
new PublicIPCreateDefinition {ShouldRetain = true});
await ip.WaitUntilActiveAsync();
Console.WriteLine($"Acquired {ip.PublicIPv4Address}!");
Console.WriteLine("Assigning the public IP to the sample cloud server...");
await ip.AssignAsync(requestedServer.Id);
await ip.WaitUntilActiveAsync();
Console.WriteLine("Deleting sample cloud server...");
serverService.DeleteServer(requestedServer.Id);
Console.WriteLine("Deallocating the public IP address...");
await ip.DeleteAsync();
}
示例8: TestAuthenticate
public void TestAuthenticate()
{
IIdentityProvider provider = new CloudIdentityProvider(Bootstrapper.Settings.TestIdentity);
UserAccess userAccess = provider.Authenticate();
Assert.IsNotNull(userAccess);
Assert.IsNotNull(userAccess.Token);
Assert.IsNotNull(userAccess.Token.Id);
Assert.IsNotNull(userAccess.Token.Expires);
Assert.IsFalse(userAccess.Token.IsExpired);
Assert.IsNotNull(userAccess.User);
Assert.IsNotNull(userAccess.User.Id);
Assert.IsNotNull(userAccess.User.Name);
Assert.IsNotNull(userAccess.ServiceCatalog);
Console.WriteLine(JsonConvert.SerializeObject(userAccess, Formatting.Indented));
}
示例9: Should_Throw_Error_When_Authenticating_With_Invalid_Password
public void Should_Throw_Error_When_Authenticating_With_Invalid_Password()
{
var identity = new RackspaceCloudIdentity()
{
Username = _testIdentity.Username,
Password = "bad password"
};
IIdentityProvider serviceProvider = new CloudIdentityProvider(identity);
try
{
var userAccess = serviceProvider.Authenticate();
throw new Exception("This code path is invalid, exception was expected.");
}
catch (net.openstack.Core.Exceptions.Response.ResponseException)
{
Assert.IsTrue(true);
}
}
示例10: Login
static bool Login()
{
auth = new RackspaceCloudIdentity();
auth.Username = Username;
auth.Password = Password;
auth.APIKey = APIKey;
auth.CloudInstance = AccountRegion == "LON" ? CloudInstance.UK : CloudInstance.Default;
try
{
CloudIdentityProvider identityProvider = new CloudIdentityProvider();
var userAccess = identityProvider.Authenticate(auth);
}
catch (Exception ex)
{
PrintException(ex);
return false;
}
return true;
}
示例11: Authenticate
//Method to Authenticate the credentials and obtain token
public void Authenticate()
{
try
{
//Creating an instance of CloudIdentityProvider providing the CloudIdentity object and urls in the constructor
provider = new CloudIdentityProvider(identity, "https://identity.api.rackspacecloud.com/v1.0", "https://lon.identity.api.rackspacecloud.com/v1.0");
//Calling the authenticate method which returns an UserAccess object containing token and user details
UserAccess access = provider.Authenticate(identity);
token = access.Token;
userdetails = access.User;
//Set the TokenId property
TokenId = token.Id;
//Verify with other programmers to make this method void
cloudFiles = new CloudFilesProvider(identity);
//return token.Id;
}
catch (UserAuthenticationException ex)
{
Console.WriteLine(ex.Message);
throw ex;
}
catch (UserAuthorizationException ex)
{
Console.WriteLine(ex.Message);
throw ex;
}
catch (UserNotAuthorizedException ex)
{
Console.WriteLine(ex.Message);
throw ex;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
throw ex;
}
}
示例12: Should_Authenticate_NewUser
public void Should_Authenticate_NewUser()
{
Assert.IsNotNull(_testUser);
IIdentityProvider provider = new CloudIdentityProvider();
var userAccess =
provider.Authenticate(new RackspaceCloudIdentity
{Username = _testUser.Username, Password = _newTestUserPassword});
Assert.IsNotNull(userAccess);
}
示例13: Main
public static void Main(string[] args)
{
Boolean containerExists = false;
if (args.Length < 4 || args.Length > 5)
{
Console.WriteLine("Usage: {0} username api_key target_container path_to_file [region (US|UK)]", Environment.CommandLine);
Environment.Exit(1);
}
RackspaceCloudIdentity auth = new RackspaceCloudIdentity();
IEnumerable<Container> containerList = null;
auth.Username = args[0];
auth.APIKey = args[1];
targetContainer = args[2];
filePath = args[3];
if (args.Length == 5)
{
if (args[4] != "UK" && args[4] != "US")
{
Console.WriteLine("region must be either US or UK", Environment.CommandLine);
Environment.Exit(1);
}
switch (args[4])
{
case "UK": {auth.CloudInstance = CloudInstance.UK;};break;
case "US": { auth.CloudInstance = CloudInstance.Default;}; break;
}
}
try
{
IIdentityProvider identityProvider = new CloudIdentityProvider();
var userAccess = identityProvider.Authenticate(auth);
}
catch (ResponseException ex2)
{
Console.WriteLine("Authentication failed with the following message: {0}",ex2.Message);
Environment.Exit(1);
}
try
{
var cloudFilesProvider = new CloudFilesProvider(auth);
containerList = cloudFilesProvider.ListContainers();
foreach (Container container in containerList)
{
if (container.Name == targetContainer)
{
containerExists = true;
break;
}
}
if (!containerExists)
{
Console.WriteLine("Container \"{0}\" does not exist on the provided CloudFiles account.", targetContainer);
Environment.Exit(1);
}
if (!File.Exists(filePath))
{
Console.WriteLine("The file specified ({0}) does not exist", filePath);
Environment.Exit(1);
}
cloudFilesProvider.CreateObjectFromFile(targetContainer, @filePath, Path.GetFileName(filePath));
}
catch (Exception ex2)
{
Console.WriteLine(ex2.Message);
Environment.Exit(1);
}
Console.WriteLine("*SUCCESS* File: \"{0}\" uploaded to \"{1}\"", filePath, targetContainer);
}
示例14: TestListEndpoints
public void TestListEndpoints()
{
IIdentityProvider provider = new CloudIdentityProvider(Bootstrapper.Settings.TestIdentity);
UserAccess userAccess = provider.Authenticate();
Assert.IsNotNull(userAccess);
Assert.IsNotNull(userAccess.Token);
Assert.IsNotNull(userAccess.Token.Id);
try
{
IEnumerable<ExtendedEndpoint> endpoints = provider.ListEndpoints(userAccess.Token.Id);
Console.WriteLine(JsonConvert.SerializeObject(userAccess, Formatting.Indented));
}
catch (UserNotAuthorizedException ex)
{
if (ex.Response.StatusCode != HttpStatusCode.Forbidden)
throw;
Assert.Inconclusive("The service does not allow this user to access the List Endpoints API.");
}
}