Top Banner
Mobile Services Authentication and Push Notifications Radu Vunvulea [email protected] http://vunvulearadu.blogspot.com
14

Mobile services on windows azure (part3)

May 25, 2015

Download

Technology

Radu Vunvulea
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Mobile services on windows azure (part3)

Mobile ServicesAuthentication and Push Notifications

Radu [email protected]

http://vunvulearadu.blogspot.com

Page 2: Mobile services on windows azure (part3)

{“name” : “Radu Vunvulea,“company” : “iQuest”,“userType” : “enthusiastic”“technologies” : [ “.NET”, “JS”, “Azure”, “Web”, “Mobile”, “SL” ],“w8experience” : [ “2 LoB App”, “1 Travel App”],“blog” : “vunvulearadu.blogspot.com”,“email” : ”[email protected]”,“socialMedia” :

{“twitter” : “@RaduVunvulea”,

“fb” : “radu.vunvulea”}

}

Who am I?

Page 3: Mobile services on windows azure (part3)

• Authentication

Windows Azure Mobile Services

Page 4: Mobile services on windows azure (part3)

Identify providers supported

Page 5: Mobile services on windows azure (part3)

• Define custom scripts that check if the given user id has rights to access his data

App.MobileService.GetTable<MyEntity>()• Before this we need to create a table with the same name• Update: table.UpdateAsync(entity)• Delete: table.DeleteAsync(entity)• Insert: table.InsertAsync(entity)• Fetch with data:

• Where• Take• Skip• OrderBy• Select• ThenBy• ToListAsync

How to work with data

Page 6: Mobile services on windows azure (part3)

• Each application need to be register to the identify provider• Windows Live:

• http://go.microsoft.com/fwlink/p/?LinkId=262039&clcid=0x409

• Facebook• http://go.microsoft.com/fwlink/p/?

LinkId=268286&clcid=0x409• Google

• http://go.microsoft.com/fwlink/p/?LinkId=268303&clcid=0x409

• Twitter• http://go.microsoft.com/fwlink/p/?

LinkId=268300&clcid=0x409

• Every identify provider require to specify the URL of our mobile service

Register your application

Page 7: Mobile services on windows azure (part3)

• After configuring the identity provider the “Identity” data need to be configured on our Mobile Service page

• We can have more than one identify provider active

• All the provider give us similar output:• Key/Id• Secret token

• After setting the key and secret token your service is ready to use authentication

Configure mobile service identity

Page 8: Mobile services on windows azure (part3)

• Change table permissions of each CRUD operation that you need to be accessible by authenticate user only to “Only Authenticate Users”

• After this step all the table content on the given CRUD operation will be accessible only to authenticated users

• The error that is returned when a user will try to access a specific service and is not authenticated will be • 401 – Unauthorized

Adding authentication to data

Page 9: Mobile services on windows azure (part3)

• There is a build in control that resolve the authentication problem

• The only think that we need to do is to specify the identify provider

App.MobileService.LoginAsync(MobileServiceAuthenticationProvider.Facebook)

• After this step each time when user will access a table from mobile service the user.userId field will contain the user id

• Remarks:All users that are login will be able to access any kind of data from our table. In this way we didn’t restrict access to specific rows from it.

Authentication on the client

Page 10: Mobile services on windows azure (part3)

• We don’t have an our of the box mechanism

• On the INSERT action script we can add a column when we store the user id

function insert(item, user, request) { item.userId = user.userId; request.execute();}

• On the action where we want to control access we need to check the userId

function read(query, user, request) { query.where({ userId: user.userId }); request.execute();}

Restrict access to table rows

Page 11: Mobile services on windows azure (part3)

• Register your application• Associate your application from VS with your app from

Store• Save your Client Secret key and Package Security

Identifier from My Apps tab• Add Client Secret key and Package Security Identified to

your Mobile Service (under Push tab)• Use “PushNotificationChannelManager” to register to

push notifications

• Data can be pushed even from CRUD script of Mobile Services tables:push.wns.sendToastText04(item.channel, { title: item.text }

Push notifications

Page 12: Mobile services on windows azure (part3)

Demo

Page 13: Mobile services on windows azure (part3)
Page 14: Mobile services on windows azure (part3)

THE END

Radu [email protected]

http://vunvulearadu.blogspot.com