The Case of REST & Azure Resource Manager APIs

There are two kinds of people in this world. One who love ready made SDKs and then there are others who love to work on pure REST APIs. I’m from the 1st category. :)

The reason behind using SDKs is they include pure abstracted API calls. For example, if you use Active Directory Authentication Library (ADAL), it has AcquireTokenAsync method. This method, if you call, takes just couple of lines of code and makes your life much more easier.

However, behind the scenes, this method does a lot of stuff. For example, in case of Windows apps: calling WebAuthenticationBroker, launching Web UI, handling app navigation, etc. Similarly, it does same thing, in iOS and Android. But that entire code base is repetitive in every app which is going to use Active Directory for login. Now, one may ask, why so many calls are made just to authenticate and acquire token or as we progress through this blog post, why so many calls are required to perform basic operations. The answer lies in purity of REST APIs. And ADAL makes life easier here by providing one method doing all this for you while abstracting all the details.

When I was working on my blog post Monitor Azure Resource Usage and Predict Expenses, there was no SDK available for Azure Resource Manager (ARM) and the old API was not an ideal way to handle Resource Management APIs.

So, I had to write an app from scratch to get ARM working in my sample and here my friend Gaurav Mantri (@gmantri) helped me a lot. Gaurav founded Cloud Portam, which helps to manage resources in Azure like Storage, Search, etc… Thanks to him, I could understand the flow and I’m going to put it here on this blog post.

Step 1: Authenticate with Common

ARM allows you to manage resources within subscription and subscription is now part of your Active Directory. So, the first thing that you need to do is to authenticate with right Active Directory. This is simple if you’ve just one subscription and one Active Directory in your subscription, but if you’ve multiple subscriptions/active directories, you may want to iterate through them and get separate access tokens. To avoid this, first we hit the ‘common’ endpoint and then get the Tenants available.

Step 2: Get Tenants

As a user, your user account may be associated with multiple active directories. A tenant is nothing but an active directory to which you have access. Here, in this step we get all active directories first by calling below method. Later on we’ll try to fetch subscription (if available) from each directory.

Step 3: Get Subscriptions

Once we get tenants, each tenant may have subscription on which we may want perform some actions. To do so, we pass each tenant ID from GetTenants() to this method and acquire new token silently (without login prompt)

Step 4: Call ARM APIs

In order to perform management operations on an Azure Subscription, a user must be authenticated and authorized. Authentication part is handled by Azure Active Directory. There is a one to many relationship between an Azure AD and Azure Subscription. i.e. an Azure AD can be used as an authentication store for many Azure Subscriptions however authentication for an Azure Subscription can happen only with a single Azure AD. Once a user is authenticated with an Azure AD, next step is to find out a list of Azure Subscriptions the logged in user has access to. This is what we’re doing in this step. What a user can do in each of these subscriptions (i.e. the authorization part) can be accomplished by using Azure Resource Manager (ARM) API’s Role-based access control (RBAC).

Now you can replace your code in Step 4 to manage or monitor resources in your Azure subscription, but the flow will not change. The entire list of APIs covering resources and possible operations on them is available here

I hope this post will helps you to understand the model behind ARM API calls.

Namaste,
Mayur Tendulkar

Updating Mobile Development Environment

On 20th July, Microsoft released Visual Studio 2015. This release of Visual Studio includes improvements in terms of IDE features, Language features and even changes in underlying .NET framework. Along with this, Microsoft is also releasing Windows 10 on 29th July, which will add Universal Windows Platform (UWP) development capabilities to Visual Studio. In this blog post, I’m going to cover the features that are most important for us i.e. mobile developers. Having said that, if you want to build UWP apps on RTM, hold on till July 29th, as the SDK and tooling for UWP will be released on the same day. You can find that information here.

Install Selection

You can think Visual Studio 2015 as the most complete mobile development IDE. You can build any kind of mobile applications which can run on Android, iOS and Windows devices. To setup your environment for mobile development, while installing itself, make sure you select your required tools. For example, here I’ve selected Xamarin tools to build native mobile applications. In this case, Visual Studio will install the necessary SDKs and libraries e.g. Android SDKs & NDKs with different API levels, Java SDK, etc…

VS 2015 Install

If you’re already a Xamarin developer, you may want to install Xamarin Studio, which needs to be installed separately by downloading Xamarin Installer from the site. With open sourcing of .NET and Roslyn, even Xamarin Studio is using some of its benefits. You can read more about it from Miguel’s blog.

Xamarin Integration & Project Template

Previously (VS 2013 or prior), you had to install Xamarin to get Xamarin specific project templates. With VS2015, if you select above option during install, you’ll have Xamarin project templates in File > New Project Dialog.

VS 2015 Project TemplatesNote: The difference between Blank App (Native Portable) & Blank App (Xamarin.Forms Portable) is literal. That means, later one has Xamarin.Forms NuGet and integration in all projects. First one, just creates 4 separate projects without Xamarin.Forms dependencies.

When you create a Xamarin project, Visual Studio will ask you to sign into your Xamarin account to use different features according to license.

VS 2015 Xamarin

Developer (aka God) Mode

As I mentioned above, if you want to build UWP apps on RTM, you’ll need to wait till 29th July. And to enable Windows Store apps development and debugging on your machine, you’ll need to enable a ‘Developer Mode’. When you create a new project you’ll get following dialog which can take you to next dialog, where you need to select ‘Developer Mode’ and you should be able to test your apps. Do the same thing in your Windows 10 mobile device, if you want to debug apps directly on mobile.

VS 2015 - Developer Mode

VS 2015 - Developer Mode Enabled

Accessing Tools

This is not new as such to Visual Studio 2015, but I want to add it here for your reference. You can find all the tools and setting related to Xamarin and mobility under Tools menu. So, if you want to download new API Level (for example Android M Preview) or monitor your Android app’s performance on device using Android Device Monitor, you know where to look for. We’ll cover tools and features exclusive for Windows 10 in next post.

VS 2015 ToolsBy the way, if you ever face any issues with Xamarin and need to contact support, Xamarin logs can help you to share more information about your issues with Support guys. Even, you can go through them and find issues/reasons. You can find them easily under Help > Xamarin

If you want to check where exactly platform SDKs are installed, you can find in Tools > Options and at two different selections

VS 2015 - SDK Location - 1

VS 2015 - SDK Location - 2

More Resources

Now, if you want to know more about Visual Studio 2015 and .NET Framework, Microsoft Channel 9 has Connect On-Demand series on it. Some of the most important videos are here

What’s new in C# 6
New Coding Experiences for C# and Visual Basic
What’s New for .NET 2015
Developing iOS and Android Apps in C# with Visual Studio
Xamarin.Forms: Leaveraging XAML to Build iOS, Android, and Windows Apps
Wearables in C#: Highlighting Apple Watch, Android Wear, and Microsoft Band
GitHub Extensions for Visual Studio

I’ll update tendulkar-uvāca series with new tools and technologies once they are released i.e. after 29th July. Till then, download the Visual Studio 2015 and enjoy the new IDE & tooling.

By the way, have I told you: You get Visual Studio 2015 Community Edition free for specific use cases and along with it, you get Xamarin Starter for free. If you’re a student, you can get more benefit through Microsoft DreamSpark program.

Namaste
Mayur Tendulkar

 

tendulkar-uvāca : Episode 2

In previous episode of tendulkar-uvāca, we’ve seen how we can setup our development environment using Visual Studio and Xamarin.
In this episode, we’re going to see how we can use emulators to test and debug our applications.

iOS simulators will get installed with XCode is installed.
For Android emulator, install Xamarin Android Player from here
Windows Phone emulators can be installed while installing Visual Studio 2013 Update 3.

Do let me know your feedback and suggestions.

Namaste
Mayur Tendulkar