Page 38 - MSDN Magazine, June 2017
P. 38
1. Open the Microsoft Account Developer Portal. This is available at apps.dev.microsoft.com. Here, you’ll see a list of apps associated with your Microsoft Account (if any).
2. Click Add an App. You’ll be asked to specify an app name, which must not include special characters. For the current exam- ple, you can enter MyBookshelf. Then, click Create Application.
3. Generate ID and client secret. When a new app is added,
the developer portal generates the Application Id, which is visi- ble in the application page, as shown in Figure 4. You also need a Client Secret, which you obtain by clicking Generate New Password. A popup will show the Client Secret, and this is actually the only time you’ll be able to see it clearly, so copy it into a safe location for later use.
4. Specify a redirect URI. This is required to tell the authentica- tion service what page it will need to show after the user has supplied the credentials. To accomplish this, click Add Platform, then Web. In the Redirect URIs box you must enter the proper redirect URI, which has the following form: https://mobile-{your-app-id}.
azurewebsites.net/.auth/login/ microsoftaccount/callback. Figure 5 demonstrates this step.
Save your changes, go back to Mobile Center and add the Client ID and Client Secret to the config- uration page for your app, as shown in Figure 6.
You can specify additional per- missions under Scope, but this is not the case here, so click Save. With a few steps, you’ve success- fully configured authentication for your app; similar steps apply to the other authentication pro- viders. Now it’s time to create a cross-platform app and write some code.
Creating and Setting Up
a Xamarin Sample Project
In Visual Studio 2017 select File | New | Project. Locate the Cross-Platform node under Visual C# and select the project template called Cross Platform App (Xamarin.Forms or Native). Call the project MyBookshelf and click OK. In the New Cross Platform App dialog, make sure you select the Blank App template, then Xamarin.Forms under UI Technology and Portable Class Library (PCL) under Code Sharing Strategy, and click OK. In order to work against Visual Studio Mobile Center services, including the Mobile Center SDK, you need to download and install the following NuGet packages:
Xamarin
Figure 5 Entering a Redirect URI
Figure 6 Configuring the Microsoft Account Authentication Service 34 msdn magazine