Skip to content

Instantly share code, notes, and snippets.

@sandrinodimattia
Created November 7, 2013 01:20
Show Gist options
  • Save sandrinodimattia/7347313 to your computer and use it in GitHub Desktop.
Save sandrinodimattia/7347313 to your computer and use it in GitHub Desktop.
ServiceManagement Authentication
public static class CertificateCloudCredentialsFactory
{
public static CertificateCloudCredentials FromPublishSettingsFile(string path, string subscriptionName)
{
var profile = XDocument.Load(path);
var subscriptionId = profile.Descendants("Subscription")
.First(element => element.Attribute("Name").Value == subscriptionName)
.Attribute("Id").Value;
var certificate = new X509Certificate2(
Convert.FromBase64String(profile.Descendants("PublishProfile").Descendants("Subscription").Single().Attribute("ManagementCertificate").Value));
return new CertificateCloudCredentials(subscriptionId, certificate);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment