Mobile services on windows azure (part3)
-
Upload
radu-vunvulea -
Category
Technology
-
view
414 -
download
2
Transcript of Mobile services on windows azure (part3)
Mobile ServicesAuthentication and Push Notifications
Radu [email protected]
http://vunvulearadu.blogspot.com
{“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?
• 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
• 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
• 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
• 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
• 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
• 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
• 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