-
Notifications
You must be signed in to change notification settings - Fork 101
Rackspace Identity Code Samples
Since all service endpoints use the identity service for authentication and authorization, we will start here.
//Required namespaces
using net.openstack.Providers.Rackspace;
using net.openstack.Core.Providers;
using net.openstack.Core.Exceptions.Response;
//Code snippet
try
{
IIdentityProvider identityProvider = new CloudIdentityProvider();
var userAccess = identityProvider.Authenticate(new RackspaceCloudIdentity
{
Username = "MyUserName",
Password = "MyPassword"
});
}
catch(ResponseException ex2)
{
// do something
}
try
{
IIdentityProvider identityProvider = new CloudIdentityProvider();
var userAccess = identityProvider.Authenticate(new RackspaceCloudIdentity
{
Username = "MyUserName",
APIKey = "MyAPIKey"
});
}
catch(ResponseException ex2)
{
// do something
}
By default, the US (default) cloud instance is used (This is the instance for all Cloud Regions EXCEPT LON. All future cloud instances will be in US (default) the cloud region). If you need to target the LON cloud instance, you only need to pass in the CloudInstance.UK
try
{
IIdentityProvider identityProvider = new CloudIdentityProvider();
var userAccess = identityProvider.Authenticate(new RackspaceCloudIdentity{
Username = "MyUserName",
Password = "MyPassword",
CloudInstance =CloudInstance.UK});
}
catch(ResponseException ex2)
{
// do something
}
retrieving details about a user is reserved for either admins, or the requesting user retrieving their own information. The examples below show a user retrieving their own if, but we will have an examples of what administrative accounts can do.
try
{
IIdentityProvider identityProvider = new CloudIdentityProvider();
var identity = new RackspaceCloudIdentity{ Username = "MyUserName", APIKey = "MyPassword" };
var userDetails = identityProvider.GetUserByName(identity, "MyUserName");
}
catch(ResponseException ex2)
{
// do something
}
try
{
IIdentityProvider identityProvider = new CloudIdentityProvider();
var identity = new RackspaceCloudIdentity{ Username = "MyUserName", APIKey = "MyPassword" };
var userDetails = identityProvider.GetUser(identity, "UserId");
}
catch(ResponseException ex2)
{
// do something
}
These methods are only available to user that exist in the identity:user-admin role. If the requesting user does not exist in this role, a exception will be thrown.
try
{
IIdentityProvider identityProvider = new CloudIdentityProvider();
var identity = new RackspaceCloudIdentity{ Username = "MyAdminUserName", APIKey = "MyAdminPassword" };
var userDetails = identityProvider.ListRoles(identity)
}
catch(ResponseException ex2)
{
// do something
}