4

When using an ASP.Net MVC4 site, it's very easy to add OAuth authentication with SimpleMembership.

OAuthWebSecurity.RegisterTwitterClient(consumerKey,consumerSecret);

When using Azure Mobile Services on a client device, it's very easy to add OAuth authentication.

await App.MobileService.LoginAsync(MobileServiceAuthenticationProvider.Twitter);

The problem is that these are two different data stores. I need to users to be able to register and/or login from either the app or the site. What is the best/easiest way to provide integrated OAuth authentication from devices and an ASP.Net site? Are there samples available?

Rob Gibbens
  • 1,122
  • 1
  • 8
  • 24

2 Answers2

3

I was only able to achieve this with Twitter and Facebook logins when Azure Mobile Services and MVC SimpleMembership were in play. Please see this thread which admittedly has a lot to look through, but it does explain my findings in pretty good detail.

http://social.msdn.microsoft.com/Forums/en-US/azuremobile/thread/d54d28c6-6941-4af5-b116-dc8c51820498

Sorry I couldn't give you any code, because my stated goal was to not write any authentication/security code for this integration.

Nate

Nate Jackson
  • 549
  • 4
  • 15
0

I just finished posting a sample that uses ASP.NET MVC4 simple membership to authenticate to an Azure Mobile Service (via Facebook, in my example) at http://blogs.msdn.com/b/carlosfigueira/archive/2013/06/25/exposing-authenticated-data-from-azure-mobile-services-via-an-asp-net-mvc-application.aspx. The post contains a lot of details, but the idea is that if you can get the provider access token (from Facebook or Google, for example), you can format it and send to the backing mobile service. In the snippet below, the facebook token was stored in the session state, and is retrieved by a method that ensures that the user is logged in.

        if (MobileService.CurrentUser == null)
        {
            var accessToken = Session["facebooktoken"] as string;
            var token = new JObject();
            token.Add("access_token", accessToken);
            return MobileService.LoginAsync(MobileServiceAuthenticationProvider.Facebook, token).ContinueWith<bool>(t =>
            {
                if (t.Exception != null)
                {
                    return true;
                }
                else
                {
                    System.Diagnostics.Trace.WriteLine("Error logging in: " + t.Exception);
                    return false;
                }
            });
        }
carlosfigueira
  • 85,035
  • 14
  • 131
  • 171