# Tuesday, 02 December 2014

Writer/Director Michael Cramer describes Teenage Ghost Punk as a "supernatural punk rock romantic comedy" - a string of adjectives and nouns that make it tough to categorize.

The movie debuted in October at the Spooky Movie International Horror Film Festival in Washington, DC. I saw it a month later at its Chicagoland premiere at the School of Rock in Oak Park, IL.

Teenage Ghost Punk tells the story of a family moving into a haunted house. Amanda is a popular high school cheerleader from Spring Lake, MI, whose newly-divorced mother moves the family to suburban Chicago, hoping for a fresh start. Amanda feels out of place in her new home and she is stressed because she misses her cheerleader friends and tall-but-rockhead boyfriend. Things get worse when she begins to hear bumps in the night and family items turn up missing. It turns out that the house is inhabited by the ghost of Brian - a teenager who was struck by lightning while playing guitar on the house's roof during a thunderstorm in the early 1980s. Brian is convinced this is still his house and that Amanda and family are intruding. Only Amanda can see and hear Brian and his ghostly pals. They talk and become close and Amanda decides to invite Brian to the school dance, where she hopes to introduce her friends to her new boyfriend. And then it gets weird.

WP_20141107_20_48_06_Pro
Cramer, along with some of the cast and crew answer audience
questions after the Chicagoland debut viewing November 7

In 2009, Michael Cramer released his first movie - Dear Mr. Fidrych - about a kid who idolized Detroit Tigers Pitcher Mark "The Bird" Fidrych, then grew up to address his midlife crisis by taking his son across country to meet his boyhood idol Fidrych.

I liked Dear Mr. Fidrych. It reminded me of my own childhood - and not just because Cramer and I grew up together in a Detroit suburb during the 1970's when The Bird had his burst of fame. However, Dear Mr. Fidrych was an independent film created on a shoestring budget and there was no hiding these facts.  Technical aspects of the movie were lacking - in particular the sound was inconsistent throughout the film and nearly all the actors were amateurs, with the leading roles going to the director and his immediate family. The story, the energy, and the charm of Dear Mr. Fidrych were enough to more than make up for any technical weaknesses.

Teenage Ghost Punk is far more polished. One could easily believe it was produced and created by a Hollywood studio. The sound is better, the cinematography is better and the acting is better. But the script retains the humor and the humanness of Dear Mr. Fidrych. Even Jack Cramer (son of the director), who plays the title character, has grown into a solid actor. He has an engaging smile that resonates on screen as he charms both Amanda and the audience. I can't think of any aspect of moviemaking that did not improve between Cramer's first movie and this one.

Teenage Ghost Punk is filled with memorable characters. A bumbling Ghostbusters-like team fails to defeat any ghosts but end up being right about their supernatural presence; the neighborhood ghosts spend their days recreating moments from their lives and spend their evenings playing cards; The over-the-top gay neighbors bicker and cuddle shamelessly; Amanda's little brother Adam includes 4-syllable words in nearly every sentences; and Madame Lidnar has little success at her own séances, but relates as well as anyone to the ghosts when she encounters them.

The silliness of the characters adds to the story, rather than distracting from it. The theme of TGP comes together very well at the end. Ultimately, the movie is about letting go of the past and moving on. Most of the characters - living and dead - are unable to do so until the end of the movie. They grew and matured as time passed.

And so did Michael Cramer and his crew.

Tuesday, 02 December 2014 10:45:00 (GMT Standard Time, UTC+00:00)
# Monday, 01 December 2014
Monday, 01 December 2014 11:24:00 (GMT Standard Time, UTC+00:00)
# Sunday, 30 November 2014

In my last article, I described how to use Visual Studio to create and deploy an Azure Mobile Service with server-side code written in a .NET language. I chose C# for that example. In this article, we will walk through the boilerplate C# code generated when you create a new Azure Mobile Services project.

Figure 1 shows the newly-created Azure Mobile Services project in Visual Studio’s Solution Explorer

Zumo9-Figure 01 - ZuMo Project
Figure 1

Let’s go through the key parts of the code.

Global.asax.cs

The Application_Start code runs at the very beginning of the application so any startup code goes here. In this case, we call the static method WebApiConfig.Register (Listing 1).

protected void Application_Start()
{
    WebApiConfig.Register();
}

Listing 1

WebApiConfig.cs

Let's take a look at the Register method in the WebApiConfig class.  WebApiConfig.cs is in App_Start folder.

This project uses the Entity Framework to interact read and write data. The most important line of the Register method (Listing 2) is

Database.SetInitializer(new MobileServiceInitializer());

which initializes Entity Framework settings. The new MobileServiceInitializer is found in the same file and it has the ability to seed the sample TodoItem table with a couple records (Listing 3)

public static void Register()
{
    // Use this class to set configuration options for your mobile service
    ConfigOptions options = new ConfigOptions(); 
 
    // Use this class to set WebAPI configuration options
    HttpConfiguration config = ServiceConfig.Initialize(new ConfigBuilder(options)); 
 
    // To display errors in the browser during development, uncomment the following
    // line. Comment it out again when you deploy your service for production use.
    // config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always; 
 
    Database.SetInitializer(new MobileServiceInitializer());
} 
 


Listing 2

public class MobileServiceInitializer : DropCreateDatabaseIfModelChanges<MobileServiceContext>
{
    protected override void Seed(MobileServiceContext context)
    {
        List<TodoItem> todoItems = new List<TodoItem>
        {
            new TodoItem { Id = "1", Text = "First item", Complete = false },
            new TodoItem { Id = "2", Text = "Second item", Complete = false },
        }; 
 
        foreach (TodoItem todoItem in todoItems)
        {
            context.Set<TodoItem>().Add(todoItem);
        } 
 
        base.Seed(context);
    }
}

Listing 3

TodoItem.cs

Next, we'll look at the TodoItem class (Listing 4), which can be found in DataObjects folder. This is the data model and will. It has 2 explicit properties - Text: the text of a Task that we need to complete; and Complete: a flag indicated whether or not we have completed this task. This object will will map to columns in the TodoItem table.
We don't need to explicitly provide an ID property because the class inherits this property from the EntityData class.

public class TodoItem : EntityData
{
    public string Text { get; set; } 
 
    public bool Complete { get; set; }
}
 

Listing 4

MobileServiceContext.cs

This is a Context used to manage database updates and retrievals via Entity Framework. It knows where to connect to the database and what model to send to the database. The Controller class will instantiate this to interact with the database table.

TodoItemController.cs

TodoItemController is the main controller class that maps HTTP Verbs (POST, PATCH, GET, and DELETE) to specific actions. It inherits from the TableController class, which has an IDomainManager named DomainManager that is used to retrieve and update data using Entity Framework. All the controller methods need to do is to call TableController methods, such as Lookup, UpdateAsync, InsertAsync, and DeleteAsync.

For example, if a client sends a request to our mobile service’s HTTP endpoint with the POST verb, the routing engine will run the PostTodItem method in TodoItemController (Listing 5).

public async Task<IHttpActionResult> PostTodoItem(TodoItem item)
{
    TodoItem current = await InsertAsync(item);
    return CreatedAtRoute("Tables", new { id = current.Id }, current);
}

To add business logic to your service, you will add code to the Controller methods (GetAllTodoItems, GetTodoItem, PatchTodoItem, PostTodoItem, and DeleteTodoItem.)

In this article, we covered the code that is automatically generated in a C# Azure Mobile Service.

Sunday, 30 November 2014 14:19:16 (GMT Standard Time, UTC+00:00)
# Saturday, 29 November 2014

In a previous article, I described how to create an Azure Mobile Service built on top of node.js - with all the server-side code written in JavaScript. You can also create a Mobile Service with server-side code written in C# or Visual Basic. You will probably prefer this method if you are more  proficient in .NET than in JavaScript.

This article will walk you through the creation of an Azure Mobile Service, written in C#.

Launch Visual Studio 2013 and select File | New | Project from the menu. The New Project dialog displays, as shown in Figure 1.

Zumo8-Figure 01 - FileNew
Figure 1

Under the Templates list at the left of the dialog, expand either Visual Basic or C#; then, select the Cloud template category. Select "Azure Mobile Service" from the Cloud templates listed at the center of the dialog. Give the project a Name and Location and click the [OK] button.

The New ASP.NET Project dialog displays, as shown in Figure 2.

Zumo8-Figure 02 - NewProject Template
Figure 2

The Azure Mobile Service template should be selected and the "Web API" checkbox should be checked. Leave these selected and check and check the Host in the cloud checkbox; then, click the [OK] button.

Because you elected to host this service in the cloud, the Create Mobile Service dialog displays next, as shown in Figure 3.

Zumo8-Figure 03 - Create Mobile Service
Figure 3

Select an Azure subscription to deploy the Mobile Service; enter a name for your Mobile Service (it must be unique);  select a Region; select a database; and enter login credentials for that database. Then click the [Create] button. This should create a project on your local machine and an empty Mobile Service in your Azure subscription.

The Mobile Service project is shown in Figure 4.

Zumo8-Figure 04 - ZuMo Project
Figure 4

To publish your Mobile Service, right-click the project in the Solution Explorer and select Publish from the context menu. The "Publish Web" wizard displays with the "Profile" page activated as shown in Figure 5.

Zumo8-Figure 05 - Publish Web
Figure 5

Under "Select a publish target", click "Microsoft Azure Mobile Service". The "Select Existing Mobile Service" dialog displays as shown in Figure 6.

Zumo8-Figure 06 - Publish Web-Profile
Figure 6

From the dropdown, select the Azure Mobile Service you created above and click the [Next] button.

The Profile page of the "Publish Web" wizard displays as shown in Figure 7.

Zumo8-Figure 07 - Publish Web-Connection
Figure 7

Verify the information on the Profile page is correct and click the [Next] button.

The "Settings" page of the "Publish Web" wizard displays as shown in Figure 8.

Zumo8-Figure 08 - Publish Web-Settings
Figure 8

Select "Release" from the Configuration dropdown and click the [Next] button.

The "Preview" page of the "Publish Web" wizard displays as shown in Figure 9.

Zumo8-Figure 09 - Publish Web-Publish
Figure 9

Click the [Publish] button to publish the Mobile Service to your Azure subscription.

Now, you should be able to log onto the portal and view your new mobile service (Figure 10). Its status may be listed as “Creating…” if you go to the portal too quickly; but, within a couple minutes, you will be able to manage the service from the Azure portal.

Zumo8-Figure 10 - Service in Portal
Figure 10

You can manage this service almost exactly the same way that you managed a JavaScript mobile service. The difference is that the .NET mobile service does not contain a DATA tab. Data configuration in a .NET service is done in the Visual Studio project.

In this article, we showed the steps to create and publish a new Azure Mobile Service with server-side code in a .NET language.

Saturday, 29 November 2014 14:20:36 (GMT Standard Time, UTC+00:00)
# Friday, 28 November 2014

Azure Mobile Services provides a simple way to expose server-side data to clients. In previous articles, we exposed data via a REST service and we created a client application that called that service to retrieve or update data.

But what if we want our service to push data down from the server to a client device without that device making a call each time? For example, you may want to tell send a message telling your app to change the text displayed on its tile, displaying the total number of orders entered in your e-commerce app; or you may want a "toast" popup notification to display on the app's device whenever someone scores in the Top 10 on a game you wrote.

We can use Push Notifications to do these things.

Each mobile vendor has its own service to manage Push Notifications and each service exposes an API to manage those notifications. Apple offers a Push Notification service to send data to registered iPhones and iPads; Google offers a Push Notification service to send data to registered Android phones and tablets; and Microsoft offers two Push Notification services - one to send data to registered Windows Pones and another to send data to registered Windows 8 or 8.1 devices.

Each of these services has an API and we can call each one explicitly for every device that will receive a notification. But this requires passing the address of each device, which is tedious and error-prone. Plus, it requires our server-side application to maintain a list of every device to which we want to push messages.

We can simplify the process by configuring Push Notifications through Azure Mobile Services. Azure Mobile Services Push Notifications automatically works with Azure Notification hubs to manage these messages.

In this article, we will focus on sending a Toast Notification to Windows 8.1 clients, but the process is similar for all Push Notifications.

The steps for setting up Push Notifications to a Windows 8.1 client using Azure Mobile Services are:

1. Create an Azure Mobile Service
2. Create a Windows 8.1 Client App and modify it as follows
    a. Associate app with store
    b. Get Package SID and Client ID from Live Services. Copy these to Mobile Service.
    c. Register notifications channel in OnLaunched (App.xaml.cs)
    d. Enable Toast notifications (Package.appxmanifest)
3. Update the Mobile Service service to send Push Notifications.

Let's walk through an example.

1. Create an Azure Mobile Service

For our example, we'll use the Azure Mobile Service we created in a previous article

2. Create a Windows 8.1 Client App and modify it as follows

For this example, we'll use the Windows 8.1 project in the Universal App generated for us in a previous article.

2a. Associate app with store

You will need a Windows Store account to complete this step. You can register at http://dev.windows.com/. It cost $19 to register for both the Windows Store and the Windows Phone Store and there is no annual renewal fee.
Register your app with the store by opening the Visual Studio Solution; right-clicking on the Windows 8.1 project; and selecting Store | Associate App with the Store from the context menu.
The "Associate App with the Windows Store" dialog (Figure 1) displays. Click the [Next] button.

Zumo7-Figure 01 - Associate App 
Figure 1

If prompted, sign into the Windows Store (Figure 2)

Zumo7-Figure 02 - Sign In 
Figure 2

You may be prompted for your email address (Figure 3). If so, enter it and click [Next]; then check your email account for a Security Code that was sent from the Microsoft Account Team.

Zumo7-Figure 03 - Sign In 
Figure 3

Copy this code and paste it into Sign-In Wizard (Figure 4) and click the [Submit] button.

Zumo7-Figure 04 - Sign In 
Figure 4

The "Select an app name" dialog (Figure 5) displays.

Zumo7-Figure 05 - Select App Name 
Figure 5

Enter a name for your app and click the [Reserve] button; then, click the [Next] button to display the final step in the wizard (Figure 6). Click the [Associate] button.

Zumo7-Figure 06 - Associate App
Figure 6

2b. Get Package SID and Client ID from Live Services. Copy these to Mobile Service.

Connect to the store portal (http://dev.windows.com for Windows Store apps and http://dev.windowsphone.com for Windows Phone apps) and click Dashboard. You should see your app listed with "In Progress" below its listing. Figure 7 shows the listing for an app in the Windows Store dashboard

Zumo7-Figure 07 - DevCenter Dashboard 
Figure 7

Click the [Edit] link below your app to display the Submissions Details page (Figure 8).

Zumo7-Figure 08 - App Details
Figure 8

So far, you have only completed Step 1 (Reserve App Name) of the app submission process. Click step 2 (Services) to display the app's Services page (Figure 9)

Zumo7-Figure 09 - App Services 
Figure 9

Click the Live Services site link in the second paragraph to navigate to the Live Services page (Figure 10). You may be prompted to sign in again.

Zumo7-Figure 10 - Live Services
Figure 10

Note the Package SID and Client ID on the Live Services page. Copy each of these in turn and paste them into the appropriate fields of the "Windows Store" section of the "Push" page in the Azure Mobile Services page of the Azure portal. This is demonstrated in Figure 11.

 Zumo7-Figure 11 - Azure Push
Figure 11

Click the [Save] icon to save these values to your Mobile Service. 

Your service is now capable of sending notifications to Windows store client apps.

2c. Register notifications channel in OnLaunched (App.xaml.cs)

Return to your .NET client application and open App.xaml.cs from the Shared project. Add the following 2 lines (Listing 1) to the top of this file:

   1: using Windows.Networking.PushNotifications;
   2: using Windows.UI.Popups;

Listing 1

Add the InitNotificationsAsync method to the bottom of the class (Listing 2)

   1: private async void InitNotificationsAsync()
   2: {
   3:     // Request a push notification channel.
   4:     var channel = await PushNotificationChannelManager
   5:         .CreatePushNotificationChannelForApplicationAsync();
   6:  
   7:     // Register for notifications using the new channel
   8:     System.Exception exception = null;
   9:     try
  10:     {
  11:         await MobileService.GetPush().RegisterNativeAsync(channel.Uri);
  12:     }
  13:     catch (System.Exception ex)
  14:     {
  15:         exception = ex;
  16:     }
  17:     if (exception != null)
  18:     {
  19:         var dialog = new MessageDialog(exception.Message, "Registering Channel URI");
  20:         dialog.Commands.Add(new UICommand("OK"));
  21:         await dialog.ShowAsync();
  22:     }
  23: }

Listing 2

Your client application is now listening for push notifications.

2d. Enable Toast notifications (Package.appxmanifest)

In this example, the service will send a Toast notification, which will tell the client to popup a "Toast" message. A Toast message appears at the top-right of the Windows 8 screen and may contain 1 or more lines of text and an image.

To enable your application to accept Toast notifications, open the Package.appxmanifest file and select the "Application" tab. Under the Notifications section, select the "Toast capable" dropdown and set it to "Yes". (Figure 11)

Zumo7-Figure 12 - Enable Toast
Figure 12

Your client application is now listening for push notifications and capable of creating a Toast popup when it receives a notification.

3. Update the Mobile Service service to send Push Notifications.

The final step is to actually send Push Notifications from your Mobile Service. In this example, we will use the node.js mobile service we created in this article (link) and we'll send a Toast Notification to all Windows Store clients whenever a user enters a new ToDoItem.

In the Azure portal, open your Mobile Service and navigate to the todoitem table's SCRIPT page (Figure 12). 

Zumo7-Figure 13 - Insert Script
Figure 11

Select INSERT from the dropdown and replace the script with the code in Listing 3.

   1: request.execute({
   2:     success: function() {
   3:         // If the insert succeeds, send a notification.
   4:         push.wns.send(null, payload, 'wns/toast', {
   5:             success: function(pushResponse) {
   6:                 console.log("Sent push:", pushResponse);
   7:                 request.respond();
   8:                 },              
   9:                 error: function (pushResponse) {
  10:                     console.log("Error Sending push:", pushResponse);
  11:                     request.respond(500, { error: pushResponse });
  12:                     }
  13:                 });
  14:             }
  15:         });
  16:  
  17: }

Listing 3

Test It Out

Your app is now ready to accept Push Notifications and your Mobile Service is configured to send them each time a new "ToDoItem" is inserted.

To see it in action, launch the application and insert a new ToDo item. Within a few seconds, you should see a "Toast" popup in the top right of your screen, indicating that you entered this item. If other users were also using this same app, they would see the same message.

In this article, we discussed Azure Mobile Services Push Notifications and walked through an example of adding them to a JavaScript Push Notification service and a Windows 8.1 application.

Friday, 28 November 2014 11:07:00 (GMT Standard Time, UTC+00:00)
# Thursday, 27 November 2014

I had always heard good things about the St. Louis Days of .NET http://stldodn.com/2014, but this year was the first chance I had to attend. It did not disappoint. I didn't hear the final count, but the hallways at the Ameristar Casino Conference Center in St. Charles, MO were packed for this event.

A commitment in Houston caused me to miss the half-day workshops held on Thursday; but I arrived in St. Charles late Friday and I had a chance to mingle with many of the speakers after dinner. I liked the fact that the event drew from areas where I had a lot of contacts (Illinois, Indiana, Michigan) but also from parts of the country where I don't travel as often (e.g., Missouri, Kansas, Nebraska). Any chance I have to expand my network of smart people is a good thing.

Most speakers were from all across the Central Region but a few travelled from as far away as Philadelphia and Ottawa.

Microsoft was well-represented at the St. Louis Day of .NET. From DX (the division where I work), Bill Fink, Jennifer Marsman, Donovan Brown, Kevin Remde, Randy Pagels, and I all spoke at the conference. Jeff Fatic and Matt Winkler of Microsoft also delivered presentations.

I attended sessions on JavaScript, Azure, and Design and I learned something in every session. I also had a long conversation about Azure Notification Hubs with Azhar Salahuddin and Charlie Chapman. I have used Notification Hubs indirectly through Azure Mobile Services, but they showed me how they work under the hood and how to work directly with notification hubs

I also spent some time with Angela Dugan of Polaris Solutions picking her brain about how organizations can become more agile and with Charlie Chapman and Gus Emery talking about universal apps.

I learned a lot at the St. Louis Days of .NET and I also got a chance to get to know the communities in the western Midwest a little bit better.

The organizers were already planning to reprise St. Louis Days of .NET in 2015. I recommend you check it out.

Thursday, 27 November 2014 04:18:00 (GMT Standard Time, UTC+00:00)
# Monday, 24 November 2014
Monday, 24 November 2014 10:25:41 (GMT Standard Time, UTC+00:00)
# Monday, 17 November 2014
Monday, 17 November 2014 13:05:00 (GMT Standard Time, UTC+00:00)
# Monday, 10 November 2014
Monday, 10 November 2014 19:57:00 (GMT Standard Time, UTC+00:00)
# Sunday, 09 November 2014

In a previous article, I showed how to create a sample .NET client application to connect to your Azure Mobile Service. In this article, I will show you how to add authentication to this sample application.

Azure Mobile Services supports a number of different methods of authentication. A couple of them you would expect from a Microsoft platform - User can be authenticated against Active Directory or they can be directed to log in with a Microsoft account (formerly known as a "Live" account.) You would expect Mobile Services to support these authentication methods because they are created and/or maintained by Microsoft. However, Mobile Services is designed to accept authentication tokens that adhere to the OAuth standard and it is built to support Facebook, Twitter, and Google authentication - all of which conform to oAuth.

In order to use an Authentication Provider, you must enable support for that provider. You can enable support for one provider and instruct all clients to use that provider; or you can enable support for multiple oAuth providers and clients will be able to offer a choice to users, allowing them to log in with their favourite service.

Setting up each of these oAuth providers is pretty similar, so the best way to show you how is to walk through an example. I'll enable Twitter authentication but the process is not much different for other providers.

Creating An App on Twitter

In order to allow users to log into your app via Twitter, you need to create an app in Twitter. You can do so by navigating to http://dev.twitter.com and signing in with your Twitter credentials (you may need to create a Twitter account first. If so, you may be the last person on Earth to do so.) At the bottom of the page is a "Tools" section. Click the "Manage Your Apps" link in this section, as shown in Figure 1.

Zumo6-Figure 01 - DevTwitter
Figure 1

On the "Twitter Apps" page, click the [Create New App] button (Figure 2).

Zumo6-Figure 02 - Create New App button
Figure 2

The "Create an application" page (Figure 3) displays. The first 3 fields are required.

Zumo6-Figure 03 - Create An Application 
Figure 3

At the "Name" field, enter a name for your application. I usually use the same name I gave my Azure Mobile Service.

At the "Description" field, enter a brief description of your app.

At the "Website" field, enter your Mobile Service URL. You can find this URL in the Azure portal on the DASHBOARD tab of your Mobile Service (Figure 4)

Zumo6-Figure 04 - Mobile Service URL

Figure 4

Scroll down the "Create an Application" page (Figure 5), read the Developer agreement completely (in this case, you are likely the first person ever to do this), check the "Yes I agree" checkbox, and click the [Create your Twitter application] button to create the app.

Zumo6-Figure 05 - Developer Agreement

Figure 5

A page displays for your newly-created app with a tab menu across the top as shown in Figure 6.

Zumo6-Figure 06 - Twitter App tabs 
Figure 6

Click the "Keys and Access Tokens" tab to display the Application Settings as shown in Figure 7.

Zumo6-Figure 07 - Twitter Keys  
Figure 7

You will need the Consumer Key (API Key) and the Consumer Secret (API Secret) so keep this web page open and open a new browser or browser tab and navigate to the Azure Portal.

In the Azure Portal, select your mobile service and click the IDENTITY menu option as shown in Figure 8.

Zumo6-Figure 08 - Mobile Services IDENTITY menu 
Figure 8

On the IDENTITY page, scroll down to the "twitter settings" section. From the Twitter "Application Settings" page, copy the API Key and the API Secret and paste these values into the corresponding fields on the Azure Mobile Services IDENTITY page, as shown in Figure 9.

 Zumo6-Figure 09 - Twitter Settings
jFigure 9

Click the SAVE icon (Figure 10) at the bottom of the page to save these changes.

Zumo6-Figure 10 - Save

Figure 10

Your Mobile Service now supports Twitter authentication.

Force clients to login before accessing your service by setting permissions on the service actions. This is done at the Mobile Service table's PERMISSIONS page. (To access the PERMISSIONS page, select your Mobile Service in the Azure Portal; click the DATA tab; select the table you want to secure; and click the PERMISSIONS tab.)

Change the permission of each action to "Only Authenticated Users" by selecting "Only Authenticated Users" from the dropdown next to each action, as shown in Figure 11. Click the SAVE icon to commit these changes.

Zumo6-Figure 11 - Table Permssions
Figure 11

Now any client app that calls your service has no choice but to force users to log in with Twitter in order to use your app.

CLIENT APP

Open the client app that we created in an earlier article and open MainPage.cs in the Shared project.

Add the following code to the class.

   1: MobileServiceUser user = null;
   2: private async System.Threading.Tasks.Task AuthenticateAsync()
   3: {
   4:     while (user == null)
   5:     {
   6:             user = await App.MobileService
   7:                 .LoginAsync(MobileServiceAuthenticationProvider.Twitter);
   8:     }
   9:  

Listing 1

Then call this method by adding the following line at the top of the OnNavigatedTo method

   1: await AuthenticateAsync(); 

Listing 2

When the user navigates to the MainPage, she will be redirected to the Twitter login page where she must successfully login before proceeding. The MobileService will remember the user and pass this information in a token with each request to the REST service. If you configure another authentication provider, such as Google or Microsoft, you can direct the user to that provider's login page by changing the MobileServiceAuthenticationProvider enum, which is passed as a parameter to the MobileService.LoginAsync method.

In this article, we saw how to configure single sign-on for our Azure Mobile Service.

Sunday, 09 November 2014 10:00:00 (GMT Standard Time, UTC+00:00)