5. How to work with data
• 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
6. Register your application
• 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
7. Configure mobile service identity
• 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
8. Adding authentication to data
• 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
9. Authentication on the client
• 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.
10. Restrict access to table rows
• 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();
}
11. Push notifications
• 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
}