I have the following code:
var client = new WebSiteManagementClient(creds);
var data = client.WebSites.Get("eastuswebspace", "some-site", new WebSiteGetParameters());
I need to generate credentials, I am an admin with full access. Only one App accessing my data and need to generate a TokenCloudCredentials.
I tried registering an App but getting a "forbidden" error after successfully generating the token. Is there a simplest way of doing this (like Github, generate a token and it's done?).
Thanks.
I managed to make it work with the following snippet. It just needs the certificate. Check if that works for you.
You will need the Azure publishing settings file (thumbprint from that).
public const string base64EncodedCertificate = "frompublishsettingsfile";
public const string subscriptionId = "";
static SubscriptionCloudCredentials getCredentials()
{
return new CertificateCloudCredentials(subscriptionId, new X509Certificate2(Convert.FromBase64String(base64EncodedCertificate)));
}
static void Main(string[] args)
{
WebSiteManagementClient client = new WebSiteManagementClient(getCredentials());
To generate a Token Credentials, you need to create a certificate and upload it on Azure.
First, you can create a certificate using this command line :
makecert -sky exchange -r -n "CN=<CertificateName>" -pe -a sha1 -len 2048 -ss My "<CertificateName>.cer"
Then, it's necessary to upload it on Azure by following this process. Once it's uploaded, you can get the publishsettings file to obtain the certificate management thumbprint with this power shell command line :
Get-AzurePusblishSettingsFile
The following screen shot shows where to find the certificate management thumbprint in the publishprofile :
Then you can use the code proposed by Alex Belotserkovskiy to get authenticated with the Azure Management SDK.
Here is a complete blog post which shows all steps.