Skip to content
This repository was archived by the owner on Oct 10, 2023. It is now read-only.

Commit e6218bc

Browse files
authored
Merge pull request #8 from titusgicheru/master
Registration Instructions and Client Identity Update
2 parents 583d82c + 598c3eb commit e6218bc

File tree

14 files changed

+2842
-3834
lines changed

14 files changed

+2842
-3834
lines changed

README.md

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,30 @@ If you want to run the iOS project in this sample, you'll need the following:
5151

5252
You can use the [Visual Studio Emulator for Android](https://www.visualstudio.com/features/msft-android-emulator-vs.aspx) if you want to run the Android project.
5353

54-
## Register and configure the app
55-
56-
The first thing you need to do is to register your app in the [Application Registration Portal](https://apps.dev.microsoft.com).
57-
58-
1. Sign in to the [Application Registration Portal](https://apps.dev.microsoft.com).
59-
1. Choose **Add an app**.
60-
1. Enter a name for the app and choose **Create**.
61-
1. Choose **Add Platform**, then choose **Native Application**.
62-
1. Choose **Save**.
54+
## Register the application
55+
56+
1. Navigate to the [the Azure portal - App registrations](https://go.microsoft.com/fwlink/?linkid=2083908) to register your app. Login using a **Work or School Account**.
57+
58+
2. Select **New registration**. On the **Register an application** page, set the values as follows.
59+
60+
* Set **Name** to **Xamarin Native PropertyManager**.
61+
* Set **Supported account types** to **Accounts in any organizational directory**.
62+
* Leave **Redirect URI** empty.
63+
* Choose **Register**.
64+
65+
3. On the **Xamarin Native PropertyManager** page, copy and save the values for the **Application (client) ID** and the **Directory (tenant) ID**. You will need them in step 7.
66+
67+
4. Select **Certificates & secrets** under **Manage**. Select the **New client secret** button. Enter a value in **Description**, select any option for **Expires** and choose **Add**.
68+
69+
5. Copy the client secret value before leaving the page. You will need it in the next step.
70+
71+
6. Open the sample solution in Visual Studio and then open the **Constants.cs** file. Change the **Tenant** string to the **Directory (tenant) ID** value you copied earlier. Similarly, change the **ClientIdForAppAuthn** string to the **Application (client) ID** value and change the **ClientSecret** string to the client secret value.
72+
73+
7. Return to the Azure Active Directory management center. Select **API permissions** and then select **Add a permission**. On the panel that appears, choose **Microsoft Graph** and then choose **Application permissions**.
74+
75+
8. Use the **Select permissions** search box to search for the following permissions: User.Read, Group.ReadWrite.All, Sites.Read.All, Files.ReadWrite.All, Tasks.ReadWrite, Directory.Read.All. Select the check box for each permission as it appears (note that the permissions will not remain visible in the list as you select each one). Select the **Add permissions** button at the bottom of the panel.
76+
77+
9. Choose the **Grant admin consent for [tenant name]** button. Select **Yes** for the confirmation that appears.
6378

6479
## Build and debug
6580

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto">
3-
<uses-sdk android:minSdkVersion="25" android:targetSdkVersion="25" />
3+
<uses-sdk android:minSdkVersion="25" android:targetSdkVersion="28" />
44
<uses-permission android:name="android.permission.INTERNET" />
55
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
66
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
77
<application android:label="Property Manager">
8-
<activity android:name="microsoft.identity.client.BrowserTabActivity">
9-
<intent-filter>
10-
<action android:name="android.intent.action.VIEW" />
11-
<category android:name="android.intent.category.DEFAULT" />
12-
<category android:name="android.intent.category.BROWSABLE" />
13-
<data android:scheme="msal[CLIENT_ID]" android:host="auth" />
14-
</intent-filter>
15-
</activity>
16-
</application>
8+
<activity android:name="microsoft.identity.client.BrowserTabActivity">
9+
<intent-filter>
10+
<action android:name="android.intent.action.VIEW" />
11+
<category android:name="android.intent.category.DEFAULT" />
12+
<category android:name="android.intent.category.BROWSABLE" />
13+
<data android:scheme="msal[CLIENT_ID]" android:host="auth" />
14+
</intent-filter>
15+
</activity>
16+
</application>
1717
</manifest>

XamarinNativePropertyManager.Droid/Resources/Resource.designer.cs

Lines changed: 2663 additions & 3744 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

XamarinNativePropertyManager.Droid/Services/AuthenticationService.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
using System;
7+
using System.Collections.Generic;
78
using System.Linq;
89
using System.Threading.Tasks;
910
using Android.App;
@@ -73,8 +74,11 @@ public async Task<AuthenticationResult> AcquireTokenSilentAsync()
7374
// Try to get a unique user id.
7475
var uuid = GetCurrentUUID();
7576

77+
IEnumerable<IAccount> accounts = await pca.GetAccountsAsync();
78+
var firstAccount = accounts.FirstOrDefault();
79+
7680
// Authenticate the user.
77-
var authenticationResult = await pca.AcquireTokenSilentAsync(Constants.Scopes, pca.Users.FirstOrDefault());
81+
var authenticationResult = await pca.AcquireTokenSilentAsync(Constants.Scopes, firstAccount);
7882
return authenticationResult;
7983
}
8084
}

XamarinNativePropertyManager.Droid/Views/DetailsView.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,5 @@ protected override void OnActivityResult(int requestCode, Result resultCode, Int
5555
AuthenticationContinuationHelper.SetAuthenticationContinuationEventArgs(
5656
requestCode, resultCode, data);
5757
}
58-
}
59-
}
58+
}
59+
}

0 commit comments

Comments
 (0)