Is there a way to create a Resource Group with the Azure Management C# API?
Basically this REST API call:
https://msdn.microsoft.com/en-us/library/azure/dn790525.aspx
I found a way to create an Affinity Group by using client.AffinityGroups.Create, but that's the closest thing I've found.
I found the API call was hidden in a library which is only in preview mode at the moment. It's found in the following NuGet package, enable include prerelease in Visual Studio to find it in the NuGet client.
https://www.nuget.org/packages/Microsoft.Azure.Management.Resources/
Then to create a resource group I can use
var credentials = new TokenCloudCredentials("", "");
var client = new Microsoft.Azure.Management.Resources.ResourceManagementClient(credentials);
var result = c.ResourceGroups.CreateOrUpdateAsync("MyResourceGroup", new Microsoft.Azure.Management.Resources.Models.ResourceGroup("West US"), new System.Threading.CancellationToken()).Result;
There is another stack overflow post explaining how to do the authentication:
How to get Tags of Azure ResourceManagementClient object
The following blog post explains how to set up TokenCloudCredentials, required for the authentication part, in more detail, but only for command line apps:
http://www.bradygaster.com/post/using-windows-azure-active-directory-to-authenticate-the-management-libraries
If you want to use something other than a command line app the following can work for authentication:
http://www.dushyantgill.com/blog/2015/05/23/developers-guide-to-auth-with-azure-resource-manager-api/
Go to https://resources.azure.com - the ARMExplorer shows both the REST and the PowerShell commands to create a resource group. All the APIs are REST based. In C#, send a WebClient request.
Related
I am trying to implement SCIM with Web Api 2 (c#) and I've found the nuget package and some documentation from Microsoft and their sample code.
My understanding from the SCIM documentation is that they just need an API with the specified user/Group methods and schemas, but in the sample code they have used a monitor and provider.
public Startup()
{
IMonitor monitor = new DefaultMonitor();
IProvider provider = new SampleProvider();
this.starter = new WebApplicationStarter(provider, monitor);
}
Their code doesn't compile even after following the instructions and getting nuget packages most probably because of the old resources on the packages that they have used, but also I don't see what is the nececity of using the package other than adding some interfaces for my controllers.
I've also found this:
SCIM (System for Cross-domain Identity Management) library for C#
But it is also a shame that the blog post that they are pointing to from MS is gone :.
So what I am asking is:
- Am I going the correct direction? Should I use the nuget?
And if yes, anything special on Web api?
Any suggestion is also very appreciated.
I am trying to follow this PowerBI embedded example and am getting an error:
'PowerBIToken' does not contain a definition for 'CreateProvisionToken'
This MSDN article describes the CreateProvisionToken() method.
I installed latest Microsoft.PowerBI.Core and Microsoft.PowerBI.Api using NuGet package manager
included Microsoft.PowerBI.Security and Microsoft.PowerBI.Api.V1 in my project.
I also tried changing CreateProvisionToken() part to the following:
var credentials = new TokenCredentials(accessKey, "AppKey");
var client = new PowerBIClient(credentials);
var devToken = PowerBIToken. CreateDevToken(reportID, workspaceID);
using (client)
{
var embedToken = PowerBIToken.CreateReportEmbedToken(
collectionName,
workspaceID,
reportID);
var embedTokenString = embedToken.Generate(accessKey);
}
Which generates a token which "looks about right", but using this token in the example html in the end of the article results in an error This content is not available when rendering the report.
What am I missing?
The latest version of Power BI embedded simplifies the authentication mechanism by only support one embedded token, no other tokens anymore from Power BI blog:
https://powerbi.microsoft.com/en-us/blog/what-s-new-and-what-s-next-for-power-bi-embedded-july-2016/
We have simplified the way developers authenticate their calls to Power BI. From today on, app tokens will only be used to authenticate embedding requests and other client side requests that may be added in the future. All calls to our REST APIs will be authenticated using our API keys directly. This eliminates the need to generate app tokens each time you want to call the REST API.
You need follow up the example from Microsoft:
https://github.com/Azure-Samples/power-bi-embedded-integrate-report-into-web-app/blob/master/EmbedSample/Controllers/DashboardController.cs
Hi I'm currently refreshing my knowledge in C# programming.
I wanted to translate the manual way of creating a Web App in Microsoft Azure (Classic) into the C# language.
(Manual way - New > Compute > Web App > Custom Create > ...etc.. )
Whenever I search through google about this topic all it gives me is to literally create a "WebApp" in Visual Studio. (File > New > ...etc...) However, what I am looking for is how to create an Azure Web App programatically via C# - how to interact with the Management UI of the Classic Azure Portal to create a web app.
Anyone familiar to do this? Thanks in advance for the help! :)
To create an azure website easily using C#, you can use "Windows Azure Management Libraries". This SDK is a wrapper arround "Azure Service Management" API.
Here is a introduction from Braddy Gaster an a blog post, to get credentials from an Azure Tenant an work with ASM Api.
Then you will be able to create a website with something like this :
using (var AwsManagement = new Microsoft.WindowsAzure.Management.WebSites.WebSiteManagementClient(azureCredentials))
{
WebSiteCreateParameters parameters = new WebSiteCreateParameters()
{
Name = "myAws",
// this Service Plan must be created before
ServerFarm = "myServiceplan",
};
await AwsManagement.WebSites.CreateAsync("myWebSpace", parameters, CancellationToken.None);
}
I was able to work on the available code Microsoft posted in GitHub:
https://github.com/Azure/azure-sdk-for-net
I re-coded some and just acquired the functions that I only need for my program to work. :)
You can create a web site by using a POST request that includes the name of the web site and other information in the request body. You can check the code example for ASM here.
I have setup up a .NET console application that will do the following:
Access the Google Contacts API for my personal Google Account
Perform basic CRUD (create, read, update, delete) operations to these contacts
I believe executing the CRUD operations will be straight forward using the following documentation:
https://developers.google.com/google-apps/contacts/v3/#about_authorization_protocols
However, my problems are occurring when trying to authenticate my connection using OAuth2.0.
I am using the Google.GData.Contacts .NET NUGET Package using the code from the following example:
https://code.google.com/p/google-gdata/source/browse/trunk/clients/cs/samples/oauth2_sample/oauth2demo.cs?r=1159
OAuth2Parameters parameters = new OAuth2Parameters() {
ClientId = clientId,
ClientSecret = clientSecret,
RedirectUri = redirectUri,
Scope = scopes
};
string url = OAuthUtil.CreateOAuth2AuthorizationUrl(parameters);
Console.WriteLine("Authorize URI: " + url);
parameters.AccessCode = Console.ReadLine();
OAuthUtil.GetAccessToken(parameters);
As this code was last updated in 2012, I'm worried it might no longer be relevant for my task.
Major Questions:
I'm not sure exactly what the parameters.AccessCode value is. Where does this value come from?
Based upon my use case am I using the correct OAuth2.0 approach? You can can setup authentication for a Service Account, Web Application, or Native Application. The above code implies Native Application
Is there a better way to handle my task?
The access code should be used only for WebServer Applications.
I'm not sure if your console app will run in an environment where a browser can be launched or not.
If yes (your app is running in a environment where a URL can be launched), use the documentation for Installed Applications.
If browser is not present, you can use the documentation for Applications on limited-input devices.
If the library you're targeting to use (NUGET, whatever) has no support for this flow, don't worry: it's easy to write custom code. You can use any library able to do HTTP/HTTPS requests, like or Windows.Web.Http.HttpClient (Windows 8 and later).
Additionally, you can use contact import services like CloudSponge, which offers a .Net API and support for other contact sources (in case you want expand your address book support in the future).
AccessCode comes from the URL created in that Line above. See here:
string url = OAuthUtil.CreateOAuth2AuthorizationUrl(parameters);
url contains a URL now for your browser. Fill it in Chrome/Firefox/etc and confirm the google request to get the AccessCode. It will look like this "4/bAQT1qf66vpkmfU8xDkoVZmedvVoYDH6KovzcHcA5pc" but will change every time you call the URL.
Console.WriteLine("Authorize URI: " + url);
now you can see the url but you might not be able to copy it from your console. But if you get it into your browser, it will result in a google dialog to get your AccessCode.
i want to develop Desktop based application in wpf (c#). which will need option to login their facebook account too. so i have registered my app in fb developer site and download C# sdk with reference some stack overflow link. which always give connection failed
// code which i have used
string APIKey = ConfigurationManager.AppSettings["API_Key"];
string APISecret = ConfigurationManager.AppSettings["API_Secret"];
Facebook.Session.ConnectSession connectsession = new Facebook.Session.ConnectSession(APIKey, APISecret);
if (connectsession.IsConnected())
{
Facebook.Rest.Api api = new Facebook.Rest.Api(connectsession);
var friends = api.Friends.GetLists();
foreach (var friend in friends)
{
System.Console.WriteLine(friend.name);
}
}
some site telling that C# sdk is deprecated.
http://developers.facebook.com/blog/post/624/
Facebook Graph C# SDK Ver 6.0: Unable to create event on App's Page
please help me to start facebook api integration in my desktop based app using wpf. some body asked to use graph api but i have doubt whether this will supprot for c# . am struk to start my step on facebook integration.
Graph Api is fully supported in C# because it is based on rest and you can call rest service through C# code, obviously url calling is different from method calling, In graph api you can call url and parse its response. I would recommend to go with graph api, Facebook has not provided the C# SDK, its a open source library maintained by open source community, however graph api help is directly provided by Facebook.
Check here and here to know how to call graph api through C#