.NET Zone is brought to you in partnership with:

Sasha Goldshtein is a Senior Consultant for Sela Group, an Israeli company specializing in training, consulting and outsourcing to local and international customers.Sasha's work is divided across these three primary disciplines. He consults for clients on architecture, development, debugging and performance issues; he actively develops code using the latest bits of technology from Microsoft; and he conducts training classes on a variety of topics, from Windows Internals to .NET Performance. You can read more about Sasha's work and his latest ventures at his blog: http://blogs.microsoft.co.il/blogs/sasha. Sasha writes from Herzliya, Israel. Sasha is a DZone MVB and is not an employee of DZone and has posted 204 posts at DZone. You can read more from them at their website. View Full User Profile

Windows Azure Mobile Services Unofficial Android SDK: Authentication Support

01.16.2013
| 2381 views |
  • submit to reddit

I totally forgot to blog about it, but my unofficial SDK has had authentication support for a few days now. This has been pretty easy to implement, actually, thanks to OAuth and the Mobile Services backend.

If you haven’t gotten started with WAMS authentication yet, you really should try it out. It’s easy as pie, really, and you can set yourself up with 3-4 authentication providers in a matter of several minutes. I’ll leave the rest to this great tutorial on authentication with WAMS.

So, if you’ve got the latest version from GitHub, you can now do this to authenticate:

mobileService.login(
    MobileServiceAuthenticationProvider.TWITTER,
    new MobileServiceLoginCallback() {
      public void errorOccurred(MobileException exception) {
        //Invoked if an error occurred
      }
      public void completedSuccessfully(MobileUser user) {
        //Invoked on success -- user.getUserId()
        //provides the user id
      }
      public void cancelled() {
        //Invoked if the user cancelled the process
      }
});

As a bonus, the client-side SDK will persist the authentication token returned by WAMS after the login flow completes. (If you care about the details, the token is persisted in a preferences file, and is not encrypted; this is something that needs to be taken care of in the future.) On subsequent runs of your app, you won’t have to display the login flow again to the user. Use the MobileService.isLoggedIn method to determine whether the user is currently logged in, and the MobileService.logout method to log out.

I am posting short links and updates on Twitter as well as on this blog. You can follow me: @goldshtn


Published at DZone with permission of Sasha Goldshtein, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)