Azure Mobile Services is deprecated, please migrate to Azure App Service.
This article builds on top of the previous tutorial where an Android Todo app was created with Azure Mobile Services. However most steps can be adapted for any Mobile Services Android app.
Copy _Mobile Service URL* from Azure Mobile Service Dashboard
Paste the Azure _Mobile Service URL* into Twitter app’s Website and Callback URL fields and save. Then in Settings tab tick the ‘Allow this application to be used Sign in with Twitter’ checkbox.
In Twitter app’s API Keys tab copy the API key & API secret.
And paste them into Identity > Twitter settings.
In Android Studio ToDoActivity cut the code block under the new Mobile Service client.
And paste into a new method _createTable()*.
private void authenticate() {
mClient.login(MobileServiceAuthenticationProvider.Twitter, new UserAuthenticationCallback() {
@Override
public void onCompleted(MobileServiceUser mobileServiceUser, Exception e, ServiceFilterResponse serviceFilterResponse) {
if (e==null)
{
createAndShowDialog(String.format("You are signed in as %s"), mobileServiceUser.getUserId() );
}
else
{
createAndShowDialog(e.getMessage(),"Error");
}
}
});
}
Then build and run
function insert(item, user, request) {
item.userId = user.userId;
request.execute();
}
Now change Script > Read so app shows only the authenticated user’s items.
function read(query, user, request) {
query.where({ userId: user.userId });
request.execute();
}
Impressive - with just a couple of lines of code the app is updated to enable user authentication and handle identity requests.
Azure Mobile Services also allows you to send Push Notifications which is covered in the next tutorial.