Permalink
Browse files

415: Added other unfinished iOS tutorials (4 total) to test staging

  • Loading branch information...
1 parent d869716 commit 27b092ab81a57212ff8e420276b7a7a2350eb268 @ggailey777 ggailey777 committed Oct 12, 2012
@@ -0,0 +1,105 @@
+<properties linkid="mobile-services-authorize-users-dotnet" urldisplayname="Mobile Services" headerexpose="" pagetitle="Authorize users with Mobile Services" metakeywords="Authorize users with Mobile Services, mobile devices, Windows Azure, mobile, Windows 8, WinRT app, authorization" footerexpose="" metadescription="Authorize users with Windows Azure Mobile Services in your Windows Store apps." umbraconavihide="0" disquscomments="1"></properties>
+
+<div class="umbMacroHolder" title="This is rendered content from macro" onresizestart="return false;" umbpageid="14810" ismacro="true" umb_chunkname="MobileArticleLeft" umb_chunkpath="devcenter/Menu" umb_macroalias="AzureChunkDisplayer" umb_hide="0" umb_modaltrigger="" umb_chunkurl="" umb_modalpopup="0"><!-- startUmbMacro --><span><strong>Azure Chunk Displayer</strong><br />No macro content available for WYSIWYG editing</span><!-- endUmbMacro --></div>
+
+<div class="dev-center-os-selector">
+ <a href="/en-us/develop/mobile/tutorials/authorize-users-in-scripts-dotnet/" title="Windows Store version">Windows Store app</a>
+ <a href="/en-us/develop/mobile/tutorials/authorize-users-in-scripts-ios/" title="iOS version" class="current">iOS app</a>
+ <span>Tutorial</span>
+</div>
+
+# Use scripts to authorize users in Mobile Services
+
+This topic shows you how to use server scripts to authorize authenticated users for accessing data in Windows Azure Mobile Services from an iOS app. In this tutorial you register scripts with Mobile Services to filter queries based on the userId of an authenticated user, ensuring that each user can see only their own data.
+
+This tutorial is based on the Mobile Services quickstart and builds on the previous tutorial [Get started with authentication]. Before you start this tutorial, you must first complete [Get started with authentication].
+
+## <a name="register-scripts"></a>Register scripts
+Because the quickstart app reads and inserts data, you need to register scripts for these operations against the TodoItem table.
+
+1. Log on to the [Windows Azure Management Portal], click **Mobile Services**, and then click your app.
+
+ ![][0]
+
+2. Click the **Data** tab, then click the **TodoItem** table.
+
+ ![][1]
+
+3. Click **Script**, then select the **Insert** operation.
+
+ ![][2]
+
+4. Replace the existing script with the following function, and then click **Save**.
+
+ function insert(item, user, request) {
+ item.userId = user.userId;
+ request.execute();
+ }
+
+ This script adds a userId value to the item, which is the user ID of the authenticated user, before it is inserted into the TodoItem table.
+
+ <div class="dev-callout"><b>Note</b>
+ <p>Dynamic schema must be enabled the first time that this insert script runs. With dynamic schema enabled, Mobile Services automatically adds the <strong>userId</strong> column to the <strong>TodoItem</strong> table on the first execution. Dynamic schema is enabled by default for a new mobile service, and it should be disabled before the app is published to the Windows Store.</p>
+ </div>
+
+
+5. Repeat steps 3 and 4 to replace the existing **Read** operation with the following function:
+
+ function read(query, user, request) {
+ query.where({ userId: user.userId });
+ request.execute();
+ }
+
+ This script filters the returned TodoItem objects so that each user only receives the items that they inserted.
+
+## Test the app
+
+1. In Xcode, open the project that you modified when you completed the tutorial [Get started with authentication].
+
+2. Press the **Run** button to build the project, start the app in the iPhone emulator, then log-on with your chosen identity provider.
+
+ Notice that this time, although there are items already in the TodoItem table from preview tutorials, no items are returned. This happens because previous items were inserted without the userId column and now have null values.
+
+3. In the app, enter text in **Insert a TodoItem** and then click **Save**.
+
+ ![][3]
+
+ This inserts both the text and the userId in the TodoItem table in the mobile service. Because the new item has the correct userId value, it is returned by the mobile service and displayed in the second column.
+
+5. Back in the **todoitem** table in the [Management Portal][Windows Azure Management Portal], click **Browse** and verify that each newly added item how has an associated userId value.
+
+6. (Optional) If you have additional login accounts, you can verify that users can only see their own data by closing the app and then running it again. When the login credentials dialog is displayed, enter a different login, and then verify that the items entered under the previous account are not displayed.
+
+## Next steps
+
+This concludes the tutorials that demonstrate the basics of working with authentication. Consider finding out more about the following Mobile Services topics:
+
+* [Get started with data]
+ <br/>Learn more about storing and querying data using Mobile Services.
+
+* [Get started with push notifications]
+ <br/>Learn how to send a very basic push notification to your app.
+
+* [Mobile Services server script reference]
+ <br/>Learn more about registering and using server scripts.
+
+<!-- Anchors. -->
+[Register server scripts]: #register-scripts
+[Next Steps]:#next-steps
+
+<!-- Images. -->
+[0]: ../Media/mobile-services-selection.png
+[1]: ../Media/mobile-portal-data-tables.png
+[2]: ../Media/mobile-insert-script-users.png
+[3]: ../Media/mobile-quickstart-startup-ios.png
+
+<!-- URLs. -->
+[Windows Push Notifications & Live Connect]: http://go.microsoft.com/fwlink/p/?LinkID=257677
+[Mobile Services server script reference]: http://go.microsoft.com/fwlink/p/?LinkId=262293
+[My Apps dashboard]: http://go.microsoft.com/fwlink/p/?LinkId=262039
+[Get started with Mobile Services]: /en-us/develop/mobile/tutorials/get-started/#create-new-service
+[Get started with data]: ./mobile-services-get-started-with-data-ios.md
+[Get started with authentication]: ./mobile-services-get-started-with-users-ios.md
+[Get started with push notifications]: ./mobile-services-get-started-with-push-ios.md
+[WindowsAzure.com]: http://www.windowsazure.com/
+[Windows Azure Management Portal]: https://manage.windowsazure.com/
@@ -56,7 +56,7 @@ Because the quickstart app reads and inserts data, you need to register scripts
1. In Visual Studio 2012 Express for Windows 8, open the project that you modified when you completed the tutorial [Get started with authentication].
-2. Press the F5 key to run the app and sign into Live Connect with your Microsoft Account.
+2. Press the F5 key to run the app, then log-on with your chosen identity provider.
Notice that this time, although there are items already in the TodoItem table from preview tutorials, no items are returned. This happens because previous items were inserted without the userId column and now have null values.
@@ -68,7 +68,7 @@ Because the quickstart app reads and inserts data, you need to register scripts
5. Back in the **todoitem** table in the [Management Portal][Windows Azure Management Portal], click **Browse** and verify that each newly added item how has an associated userId value.
-6. (Optional) If you have an additional Microsoft Account, you can verify that users can only see their own data by closing the app (Alt+F4) and then running it again. When the login credentials dialog is displayed, enter a different Microsoft account, and then verify that the items entered under the previous account are not displayed.
+6. (Optional) If you have additional login accounts, you can verify that users can only see their own data by closing the app (Alt+F4) and then running it again. When the login credentials dialog is displayed, enter a different login, and then verify that the items entered under the previous account are not displayed.
## Next steps
@@ -0,0 +1,167 @@
+<properties linkid="get-started-with-users-ios" urldisplayname="Mobile Services" headerexpose="" pagetitle="Get started with authentication in Mobile Services" metakeywords="Get started Windows Azure Mobile Services, mobile devices, Windows Azure, mobile, Windows 8, WinRT app" footerexpose="" metadescription="Get started with authentication in Mobile Services with your iOS apps" umbraconavihide="0" disquscomments="1"></properties>
+
+<div class="umbMacroHolder" title="This is rendered content from macro" onresizestart="return false;" umbpageid="14798" ismacro="true" umb_chunkname="MobileArticleLeft" umb_chunkpath="devcenter/Menu" umb_macroalias="AzureChunkDisplayer" umb_hide="0" umb_modaltrigger="" umb_chunkurl="" umb_modalpopup="0"><!-- startUmbMacro --><span><strong>Azure Chunk Displayer</strong><br />No macro content available for WYSIWYG editing</span><!-- endUmbMacro --></div>
+
+<div class="dev-center-os-selector">
+ <a href="/en-us/develop/mobile/tutorials/get-started-with-users-dotnet/" title="Windows Store version">Windows Store app</a>
+ <a href="/en-us/develop/mobile/tutorials/get-started-with-users-ios/" title="iOS version" class="current">iOS app</a>
+ <span>Tutorial</span>
+</div>
+
+# Get started with authentication in Mobile Services
+
+This topic shows you how to authenticate users in Windows Azure Mobile Services from your app. In this tutorial, you add authentication to the quickstart project using an identity provider that is supported by Mobile Services. After being successfully authenticated and authorized by Mobile Services, the user ID value is displayed.
+
+This tutorial walks you through these basic steps to enable authentication in your app:
+
+1. [Register your app for authentication and configure Mobile Services]
+2. [Restrict table permissions to authenticated users]
+3. [Add authentication to the app]
+
+This tutorial is based on the Mobile Services quickstart. You must also first complete the tutorial [Get started with Mobile Services].
+
+<div class="dev-callout"><b>Note</b>
+ <p>This tutorial demonstrates the basic method provided by Mobile Services to authenticate users by using a variety of identity providers. This method is easy to configure and supports multiple providers. However, this method also requires users to log-in every time your app starts. To instead use Live Connect to provide a single sign-on experience in your Windows Store app, see the topic <a href="/en-us/develop/mobile/tutorials/single-sign-on-win8-dotnet">Single sign-on for Windows Store apps by using Live Connect</a>.</p>
+</div>
+
+<a name="register"></a><h2><span class="short-header">Register your app</span>Register your app for authentication and configure Mobile Services</h2>
+
+To be able to authenticate users, you must register your app with an identity provider. You must then register the provider-generated client secret with Mobile Services.
+
+1. Log on to the [Windows Azure Management Portal], click **Mobile Services**, and then click your mobile service.
+
+ ![][4]
+
+2. Click the **Dashboard** tab and make a note of the **Site URL** value.
+
+ ![][5]
+
+ You may need to provide this value to the identity provider when you register your app.
+
+3. Choose a supported identity provider from the list below and follow the steps to register your app with that provider:
+
+ - <a href="/en-us/develop/mobile/howto/register-ms-account-auth" target="_blank">Microsoft Account</a>
+ - <a href="/en-us/develop/mobile/howto/register-facebook-auth" target="_blank">Facebook login</a>
+ - <a href="/en-us/develop/mobile/howto/register-twitter-auth" target="_blank">Twitter login</a>
+ - <a href="/en-us/develop/mobile/howto/register-google-auth" target="_blank">Google login</a>
+
+4. Back in the Management Portal, click the **Identity** tab, enter the app identifier and shared secret values obtained from your identity provider, and click **Save**.
+
+ ![][13]
+
+Both your mobile service and your app are now configured to work with your chosed authenication provider.
+
+<a name="permissions"></a><h2><span class="short-header">Restrict permissions</span>Restrict permissions to authenticated users</h2>
+
+1. In the Management Portal, click the **Data** tab, and then click the **TodoItem** table.
+
+ ![][14]
+
+2. Click the **Permissions** tab, set all permissions to **Only authenticated users**, and then click **Save**. This will ensure that all operations against the **TodoItem** table require an authenticated user. This also simplifies the scripts in the next tutorial because they will not have to allow for the possibility of anonymous users.
+
+ ![][15]
+
+3. In Xcode, open the project that you created when you completed the tutorial [Get started with Mobile Services].
+
+4. Press the **Run** button to build the project and start the app in the iPhone emulator; verify that an exception with a status code of 401 (Unauthorized) is raised.
+
+ This happens because the app is accessing Mobile Services as an unauthenticated user, but the _TodoItem_ table now requires authentication.
+
+Next, you will update the app to authenticate users with Live Connect before requesting resources from the mobile service.
+
+<a name="add-authentication"></a><h2><span class="short-header">Add authentication</span>Add authentication to the app</h2>
+
+5. Open the project file mainpage.xaml.cs and add the following using statement:
+
+ using Windows.UI.Popups;
+
+6. Add the following code snippet to the MainPage class:
+
+ private MobileServiceUser user;
+ private async System.Threading.Tasks.Task Authenticate()
+ {
+ while (user == null)
+ {
+
+ user = await App.MobileService
+ .Login(
+ MobileServiceAuthenticationProvider.Facebook);
+ if (user.UserId == null)
+ {
+
+ var message =
+ string.Format("You are now logged in - {0}", user.UserId);
+ var dialog = new MessageDialog(message);
+ dialog.Commands.Add(new UICommand("OK"));
+ await dialog.ShowAsync();
+ }
+ else
+ {
+ user = null;
+ var dialog =
+ new MessageDialog("You must log in.", "Login Required");
+ dialog.Commands.Add(new UICommand("OK"));
+ await dialog.ShowAsync();
+ }
+ }
+ }
+
+ This creates a member variable for storing the current user and a method to handle the authentication process. The user is authenticated by using a Facebook login.
+
+ <div class="dev-callout"><b>Note</b>
+ <p>If you are using an identity provider other than Facebook, change the value of MobileServiceAuthenticationProvider above to the value for your provider.</p>
+ </div>
+
+8. Replace the existing **OnNavigatedTo** event handler with the handler that calls the new **Authenticate** method:
+
+ protected override async void OnNavigatedTo(NavigationEventArgs e)
+ {
+ await Authenticate();
+ RefreshTodoItems();
+ }
+
+9. Press the **Run** button to build the project, start the app in the iPhone emulator, then log-on with your chosen identity provider.
+
+ When you are successfully logged-in, the app should run without errors, and you should be able to query Mobile Services and make updates to data.
+
+## <a name="next-steps"> </a>Next steps
+
+In the next tutorial, [Authorize users with scripts], you will take the user ID value provided by Mobile Services based on an authenticated user and use it to filter the data returned by Mobile Services.
+
+<!-- Anchors. -->
+[Register your app for authentication and configure Mobile Services]: #register
+[Restrict table permissions to authenticated users]: #permissions
+[Add authentication to the app]: #add-authentication
+[Next Steps]:#next-steps
+
+<!-- Images. -->
+[0]: ../Media/mobile-services-submit-win8-app.png
+[1]: ../Media/mobile-services-win8-app-name.png
+[2]: ../Media/mobile-services-store-association.png
+[3]: ../Media/mobile-services-select-app-name.png
+[4]: ../Media/mobile-services-selection.png
+[5]: ../Media/mobile-service-uri.png
+[6]: ../Media/mobile-live-connect-apps-list.png
+[7]: ../Media/mobile-live-connect-app-api-settings.png
+[8]: ../Media/mobile-services-win8-app-advanced.png
+[9]: ../Media/mobile-services-win8-app-connect-redirect.png
+[10]: ../Media/mobile-services-win8-app-connect-redirect-uri.png
+[11]: ../Media/mobile-services-win8-app-push-connect.png
+[12]: ../Media/mobile-services-win8-app-connect-auth.png
+[13]: ../Media/mobile-identity-tab.png
+[14]: ../Media/mobile-portal-data-tables.png
+[15]: ../Media/mobile-portal-change-table-perms.png
+[16]: ../Media/mobile-add-reference-live-dotnet.png
+
+<!-- URLs. -->
+[Submit an app page]: http://go.microsoft.com/fwlink/p/?LinkID=266582
+[My Applications]: http://go.microsoft.com/fwlink/p/?LinkId=262039
+[Live SDK for Windows]: http://go.microsoft.com/fwlink/p/?LinkId=262253
+[Single sign-on for Windows Store apps by using Live Connect]: ./mobile-services-single-sign-on-win8-dotnet.md
+[Get started with Mobile Services]: ./mobile-services-get-started-ios.md
+[Get started with data]: ./mobile-services-get-started-with-data-ios.md
+[Get started with authentication]: ./mobile-services-get-started-with-users-ios.md
+[Get started with push notifications]: ./mobile-services-get-started-with-push-ios.md
+[Authorize users with scripts]: ./mobile-services-authorize-users-ios.md
+[WindowsAzure.com]: http://www.windowsazure.com/
+[Windows Azure Management Portal]: https://manage.windowsazure.com/

0 comments on commit 27b092a

Please sign in to comment.